shelly1_01 = Virtual Dining Room Light Toggle

This commit is contained in:
Brian Hanifin
2019-09-13 09:27:47 -07:00
parent 24aeb167a2
commit c15b93d0ca
2 changed files with 101 additions and 1 deletions
+2 -1
View File
@@ -3,4 +3,5 @@
# Specific file ignores
/secrets.yaml
.DS_Store
.DS_Store
._*
+99
View File
@@ -0,0 +1,99 @@
# Sonoff Basic Power Module
#
substitutions:
devicename: shelly1_01
upper_devicename: Shelly1 01
hass_light: light.dining_room
hass_status: hass/status
mqtt_prefix: esphome
esphome:
name: ${devicename}
platform: ESP8266
board: esp01_1m
board_flash_mode: dout
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pass
# Enable Home Assistant API
api:
# Enable MQTT to watch for Home Assistant to come back online.
mqtt:
broker: 10.0.0.56
discovery: false
topic_prefix: ${mqtt_prefix}
birth_message:
topic: ${mqtt_prefix}/status/${devicename}
payload: online
will_message:
topic: ${mqtt_prefix}/status/${devicename}
payload: offline
ota:
safe_mode: True
logger:
script:
- id: dining_room_light_toggle
then:
if:
condition:
api.connected:
then:
# 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: GPIO5
inverted: True
name: ${upper_devicename} Button
id: button
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_press:
- script.execute: dining_room_light_toggle
on_release:
- script.execute: dining_room_light_toggle
switch:
# Relay is for internal use only. Do not expose to Home Assistant.
- platform: gpio
id: relay
pin: GPIO4
restore_mode: ALWAYS_ON
internal: true
text_sensor:
- platform: mqtt_subscribe
id: mqtt_hass_status
topic: ${hass_status}
on_value:
if:
condition:
text_sensor.state:
id: mqtt_hass_status
state: online
then:
if:
condition:
switch.is_off: relay
then:
- homeassistant.service:
service: light.turn_off
data:
entity_id: ${hass_light}
- switch.turn_on: relay