Sorry for late reply didn’t get notifcation
This is pasted directly there are some entities that need to be cleared from there
substitutions:
devicename: shelly1_toilet
upper_devicename: Shelly1 Toilet
ip_address: 10.10.4.51
sensor_prefix: esp
esphome:
name: shelly1_toilet
platform: ESP8266
board: esp01_1m
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: on
use_address: ${ip_address}
manual_ip:
static_ip: ${ip_address}
gateway: 10.10.4.1
subnet: 255.255.255.0
web_server:
port: 80
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
safe_mode: True
switch:
- platform: gpio
pin: 4
name: "Toilet"
id: relay1
restore_mode: RESTORE_DEFAULT_ON
- platform: restart
name: ${upper_devicename} Restart
binary_sensor:
- platform: gpio
pin:
number: 5
name: ${upper_devicename} SW
on_multi_click:
- timing:
- ON for at most 0.3s
- OFF for at most 0.3s
- ON for at least 0.2s
then:
- logger.log: "Double Clicked"
- switch.toggle: relay1
- timing:
- OFF for at most 0.3s
- ON for at most 0.3s
- OFF for at least 0.2s
then:
- logger.log: "Double Clicked"
- switch.toggle: relay1
- timing:
- ON for at least 0.4s
then:
- script.execute: sw1_action
- timing:
- OFF for at least 0.4s
then:
- script.execute: sw1_action
- platform: status
name: ${sensor_prefix} ${upper_devicename} Status
id: network_available
on_state:
then:
- if:
condition:
lambda: 'return id(network_available).state;'
then:
- logger.log: "API connection available"
else:
- logger.log: "API connection NOT available"
sensor:
- platform: uptime
name: ${upper_devicename} Uptime
- platform: wifi_signal
name: ${upper_devicename} Signal
update_interval: 300s
text_sensor:
- platform: homeassistant
id: yeelight_available
entity_id: binary_sensor.yeelight_toilet_available
- platform: homeassistant
id: light_toilet
entity_id: light.toilet
script:
- id: sw1_action
then:
- logger.log: "SW1 single click"
- if:
condition:
and:
- lambda: 'return id(yeelight_available).state == "on";'
- api.connected:
- wifi.connected:
then:
- logger.log: "WiFi, hass API and yeelight is available"
- if:
condition:
switch.is_on: relay1
then:
- logger.log: "Relay state is ON"
- if:
condition:
- lambda: 'return id(light_toilet).state == "on";'
then:
- logger.log: "Turning off light"
- homeassistant.service:
service: light.turn_off
data:
entity_id: light.toilet
- if:
condition:
- lambda: 'return id(light_toilet).state == "off";'
then:
- logger.log: "Turning on light"
- homeassistant.service:
service: scene.turn_on
data_template:
entity_id: >-
{% set full_light_time_start = now().strftime('%Y-%m-%d') + ' ' + '06:00:00.0000+10:00' %}
{% set full_light_time_end = now().strftime('%Y-%m-%d') + ' ' + '21:00:00.0000+10:00' %}
{% if as_timestamp(now()) >= as_timestamp(full_light_time_start) and as_timestamp(now()) <= as_timestamp(full_light_time_end) %}
scene.toilet_light_full
{% else %}
scene.toilet_light_soft
{% endif %}
else:
- logger.log: "Control relay is OFF, turning back on"
- switch.turn_on: relay1
else:
- logger.log: "No hass connection. Toggle relay state"
- switch.toggle: relay1