mirror of
https://github.com/brianhanifin/esphome-config.git
synced 2026-07-28 04:05:55 +00:00
66 lines
1.7 KiB
YAML
66 lines
1.7 KiB
YAML
# Shelly 1 Power Module
|
|
# Location: Dining Room Light Switch
|
|
#
|
|
substitutions:
|
|
project: Shelly1 01
|
|
id: shelly1_01
|
|
|
|
hass_light: light.dining_room
|
|
<<: !include common/substitutions/gpio/shelly1.yaml
|
|
|
|
<<: !include common/esphome/esp8266.yaml
|
|
<<: !include common/wifi.yaml
|
|
<<: !include common/api.yaml
|
|
<<: !include common/ota.yaml
|
|
<<: !include common/logger.yaml
|
|
|
|
script:
|
|
- id: hass_light_toggle
|
|
then:
|
|
if:
|
|
condition:
|
|
api.connected:
|
|
then:
|
|
- if:
|
|
condition:
|
|
switch.is_off: relay
|
|
then:
|
|
# Turn the relay back on and turn on the light.
|
|
- switch.turn_on: relay
|
|
|
|
- homeassistant.service:
|
|
service: light.turn_on
|
|
data:
|
|
entity_id: $hass_light
|
|
else:
|
|
# Have Home Assistant toggle the light.
|
|
- homeassistant.service:
|
|
service: light.toggle
|
|
data:
|
|
entity_id: $hass_light
|
|
else:
|
|
# When HA is unavailable, toggle the relay.
|
|
- switch.toggle: relay
|
|
|
|
binary_sensor:
|
|
- platform: gpio
|
|
pin:
|
|
number: $button_gpio
|
|
inverted: True
|
|
name: $project Button
|
|
id: button
|
|
filters:
|
|
- delayed_on: 10ms
|
|
- delayed_off: 10ms
|
|
on_press:
|
|
- script.execute: hass_light_toggle
|
|
on_release:
|
|
- script.execute: hass_light_toggle
|
|
|
|
switch:
|
|
# Relay is for internal use only. Do not expose to Home Assistant.
|
|
- platform: gpio
|
|
id: relay
|
|
pin: $relay_gpio
|
|
restore_mode: ALWAYS_ON
|