184 lines
5.0 KiB
YAML
184 lines
5.0 KiB
YAML
# ESPHome Firmware for
|
|
# Sonoff Switchman M5 2-Gang US
|
|
# Copyright (c) 2024 Mario Di Vece
|
|
# License: [MIT](https://opensource.org/license/mit/)
|
|
# Decription:
|
|
# Aims to provide a feature-rich, production-ready firmware for this elegant device
|
|
# - Provides Diagnostic data plus, status LED indicator when not connected to Home Assistant API
|
|
# - Relays may be configured individually on the UI to work in decoupled mode.
|
|
# LEDs are physically connected to the relays, and they can't be individually controlled :(
|
|
# - Exposes gestures via events:
|
|
# esphome.on_gesture { button: (A|B), gesture: (click|double_click|button_hold) }
|
|
# - Off-state (Background Brightness) of the LEDs is configurable via the UI
|
|
#
|
|
# For the below example to work, you need to keep the following entries in your secrets.yaml file:
|
|
# - wifi_ssid: "<secret>"
|
|
# - wifi_password: "<secret>"
|
|
# - ota_password: "<secret>"
|
|
# - api_key: "<32-byte-base-64-secret>"
|
|
#
|
|
# Example file (lab-office-wasw-003.yaml)
|
|
#
|
|
# substitutions:
|
|
# device_site: "lab"
|
|
# device_location_code: "office"
|
|
# device_location_name: "Office"
|
|
# device_type_code: "wasw"
|
|
# device_type_name: "Wall Switch"
|
|
# device_number: "003"
|
|
# device_ip: "192.168.1.31"
|
|
#
|
|
# packages:
|
|
# base_package:
|
|
# url: https://github.com/mariodivece/esphometemplates/
|
|
# ref: main
|
|
# file: sonoff-m5-2g-us.yaml
|
|
# refresh: 0d
|
|
#
|
|
|
|
substitutions:
|
|
# User-required substitutions
|
|
device_site: "home"
|
|
device_location_code: "bedroom01"
|
|
device_location_name: "Bedroom 1"
|
|
device_type_code: "wasw"
|
|
device_type_name: "Wall Switch"
|
|
device_number: "044"
|
|
device_ip: "0.0.0.0"
|
|
|
|
# Project Substitutions (not intended for user substitution)
|
|
device_model: "Switchman M5 (2-Gang)"
|
|
device_make: "Sonoff"
|
|
package_version: "2024.2.13"
|
|
package_url: "github://mariodivece/esphometemplates/sonoff-m5-2g-us.yaml@main"
|
|
|
|
# Relay Configurations
|
|
relay_a_gpio: GPIO23
|
|
relay_b_gpio: GPIO19
|
|
|
|
# Button Configurations
|
|
button_a_gpio: GPIO04
|
|
button_b_gpio: GPIO15
|
|
|
|
# Indicator LED
|
|
led_indicator_gpio: GPIO22
|
|
|
|
# Allow importing this package
|
|
dashboard_import:
|
|
package_import_url: ${package_url}
|
|
import_full_config: false
|
|
|
|
# Import packages
|
|
packages:
|
|
standard_package:
|
|
url: https://github.com/mariodivece/esphometemplates/
|
|
ref: main
|
|
refresh: 0d
|
|
files:
|
|
- standard/project.yaml
|
|
- standard/diagnostics.yaml
|
|
- standard/wifi.yaml
|
|
- standard/internaltemp.yaml
|
|
sonoffm5_package:
|
|
url: https://github.com/mariodivece/esphometemplates/
|
|
ref: main
|
|
refresh: 0d
|
|
files:
|
|
- sonoff-m5/board.yaml
|
|
- sonoff-m5/timings.yaml
|
|
- sonoff-m5/status-led.yaml
|
|
- sonoff-m5/backlight.yaml
|
|
- sonoff-m5/indicator-led.yaml
|
|
- sonoff-m5/mode-button-a.yaml
|
|
- sonoff-m5/mode-button-b.yaml
|
|
- sonoff-m5/relay-a.yaml
|
|
- sonoff-m5/relay-b.yaml
|
|
- sonoff-m5/button-a.yaml
|
|
- sonoff-m5/button-b.yaml
|
|
|
|
switch:
|
|
|
|
# Modify behavior of imported Relay B
|
|
- id: !extend relay_b
|
|
on_turn_on:
|
|
- switch.turn_on: led_indicator
|
|
on_turn_off:
|
|
- switch.turn_off: led_indicator
|
|
|
|
binary_sensor:
|
|
|
|
# Button A
|
|
- id: !extend button_a
|
|
on_press:
|
|
# Latching
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_a).active_index() == 0;'
|
|
then:
|
|
- switch.toggle: relay_a
|
|
# Momentary
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_a).active_index() == 1;'
|
|
then:
|
|
- switch.turn_on: relay_a
|
|
# Pulse
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_a).active_index() == 2;'
|
|
then:
|
|
- switch.turn_on: relay_a
|
|
- delay: ${timing_pulse}
|
|
- switch.turn_off: relay_a
|
|
on_release:
|
|
# Momentary
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_a).active_index() == 1;'
|
|
then:
|
|
- switch.turn_off: relay_a
|
|
|
|
# Button B
|
|
- id: !extend button_b
|
|
on_press:
|
|
# Latching
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_b).active_index() == 0;'
|
|
then:
|
|
- switch.toggle: relay_b
|
|
# Momentary
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_b).active_index() == 1;'
|
|
then:
|
|
- switch.turn_on: relay_b
|
|
# Pulse
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_b).active_index() == 2;'
|
|
then:
|
|
- switch.turn_on: relay_b
|
|
- delay: ${timing_pulse}
|
|
- switch.turn_off: relay_b
|
|
# Decoupled
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_b).active_index() == 3;'
|
|
then:
|
|
- switch.turn_on: led_indicator
|
|
|
|
on_release:
|
|
# Momentary
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_b).active_index() == 1;'
|
|
then:
|
|
- switch.turn_off: relay_b
|
|
# Decoupled
|
|
- if:
|
|
condition:
|
|
- lambda: 'return id(mode_b).active_index() == 3;'
|
|
then:
|
|
- switch.turn_off: led_indicator
|