diff --git a/devices/sonoff-s31-reset-relay-toggle.yaml b/devices/sonoff-s31-reset-relay-toggle.yaml new file mode 100644 index 0000000..0058c30 --- /dev/null +++ b/devices/sonoff-s31-reset-relay-toggle.yaml @@ -0,0 +1,159 @@ +esphome: + name: ${devicename} + friendly_name: ${friendly_name} + +esp8266: + board: esp12e + # https://esphome.io/components/esp8266.html + # https://github.com/esphome/issues/issues/3263 + # Stops relay from cycling when restarting or flashing + early_pin_init: false + +logger: + baud_rate: 0 # (UART logging interferes with cse7766) + logs: + sensor: DEBUG # (Overide any global setting, to VERBOSE will spamming the cse7766 sensors) + +uart: + rx_pin: RX + baud_rate: 4800 + parity: EVEN + +globals: + # Global boolean containing value if confirm is selected. + - id: confirm_restart + type: bool + restore_value: no + initial_value: 'false' + +binary_sensor: + - platform: gpio + pin: + number: GPIO0 + mode: INPUT_PULLUP + inverted: True + internal: true + id: the_button + on_press: + - switch.toggle: relay + + - platform: status + name: Status + +sensor: + # Wifi Signal + - <<: !include ../common/sensors/wifi-signal.yaml + + # Uptime + - <<: !include ../common/sensors/uptime.yaml + + # Energy monitoring + - platform: cse7766 + current: # amperes + name: "Current" + accuracy_decimals: 2 # Default + unit_of_measurement: "A" # Default + device_class: "current" # Default + state_class: "measurement" # Default + filters: + - throttle_average: 15s + voltage: + name: "Voltage" + accuracy_decimals: 2 # Default + unit_of_measurement: "V" # Default + device_class: "voltage" # Default + state_class: "measurement" # Default + filters: + - throttle_average: 15s + power: # (active) power value of the sensor in watts + name: "Power" + id: my_power + accuracy_decimals: 2 # Default + unit_of_measurement: "W" # Default + device_class: "power" # Default + state_class: "measurement" # Default + filters: + - throttle_average: 15s + energy: # total (active) energy value of the sensor in Wh + name: "Energy" + accuracy_decimals: 3 # Default + unit_of_measurement: "kWh" # Default + device_class: energy # Default + state_class: total_increasing # Default + filters: + - throttle: 15s + apparent_power: # apparent power value of the sensor in VA - (only available with version 2024.3.0 or greater) + name: "Apparent Power" + accuracy_decimals: 1 # Default + unit_of_measurement: "VA" # Default + device_class: apparent_power # Default + state_class: measurement # Default + filters: + - throttle_average: 15s + power_factor: # efficiency - (only available with version 2024.3.0 or greater) + name: "Power Factor" + accuracy_decimals: 2 + unit_of_measurement: "" # Default (unitless) + device_class: power_factor # Default + state_class: measurement # Default + filters: + - throttle_average: 15s + + - platform: total_daily_energy # (Optional, not specific to cse7766) + name: "Daily Energy" + power_id: my_power + accuracy_decimals: 2 + unit_of_measurement: "Wh" # Default + device_class: energy # Default + state_class: total_increasing # Default + +switch: + - platform: gpio + name: "Relay" + pin: GPIO12 + id: relay + # AWLAYS_OFF should probably be used if we're not using early_pin_init: false + # restore_mode: ALWAYS_OFF # Powering the relay may cause damage or instability when the programmer is supplying Vcc. + # It is assumed this switch is used for a piece of critical infrastructure. + # As such, we want it to remain ON turing reboots. + # Lastly- the only functionality exposed for interacting with this relay, is to quickly power cycle it. + restore_mode: ALWAYS_ON + # Hide from home assistant / mqtt. + internal: false + + # Expose a "confirm restart" switch. + - platform: template + name: Confirm Restart + id: confirm_restart_sw + icon: mdi:alert + lambda: |- + return id(confirm_restart); + turn_on_action: + - lambda: |- + id(confirm_restart) = true; + turn_off_action: + - lambda: |- + id(confirm_restart) = false; + +button: + # Restart Button + - <<: !include ../common/buttons/restart.yaml + + - platform: template + name: Power Cycle + icon: mdi:restart-alert + on_press: + - if: + condition: + lambda: 'return id(confirm_restart);' + then: + - switch.turn_off: relay + - delay: 0.5s + - switch.turn_on: relay + # Turn off confirm switch after cycling relay + - switch.turn_off: confirm_restart_sw + +status_led: + pin: + number: GPIO13 + inverted: yes