diff --git a/.gitignore b/.gitignore index 885c2f7..17ca068 100755 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ # Specific file ignores /secrets.yaml -.DS_Store \ No newline at end of file +.DS_Store +._* diff --git a/shelly01.yaml b/shelly01.yaml new file mode 100644 index 0000000..e1924a9 --- /dev/null +++ b/shelly01.yaml @@ -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 \ No newline at end of file