mirror of
https://github.com/brianhanifin/esphome-config.git
synced 2026-09-22 18:29:39 +00:00
74 lines
1.6 KiB
YAML
74 lines
1.6 KiB
YAML
# Shelly 1 Power Module
|
|
#
|
|
substitutions:
|
|
devicename: shelly1_01
|
|
upper_devicename: Shelly1 01
|
|
hass_light: light.dining_room
|
|
|
|
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:
|
|
|
|
ota:
|
|
safe_mode: True
|
|
|
|
logger:
|
|
|
|
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: GPIO5
|
|
inverted: True
|
|
name: ${upper_devicename} 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: GPIO4
|
|
restore_mode: ALWAYS_ON |