Automated Bathroom Mirror

Another ESPHome powered Sonoff Basic implemented.

Heat pad added to bathroom Mirror. Light/heat control changed from hardwired pull switch to Sonoff basic. Pull cord as input. Relay as output. Auto off after 60mins. Some challenges on de-bouncing the incredibly awful pull cord switch but “multi-click” got me there. Thats full Control, with custom firmware working exactly how I want it, updateable over WiFi…for a £5 sonoff basic and a few hours tinkering time.

Just have to stop and appreciate how remarkable that is ! Thanks so much to the people that contribute to all the software components but especially @OttoWinter and ESPHome !

YAML…here. Took a while to get the multi_click format and details right. The key is the “invalid_cooldown” being disabled (0s)
Template Sensor needed to track the Switch to give “on_state” option to trigger the 60minute delayed power off.

    # Enable logging
    logger:  
    level: INFO

    # Enable Home Assistant API
    api:

    ota:

    time:
    - platform: homeassistant

    substitutions:
    switch_id: "esp_sf03"

    sensor:
    - platform: wifi_signal
        name: "${switch_id} WiFi Signal Sensor"
        update_interval: 60s

    switch:
    # Restart Switch in HA
    - platform: restart
        name: "${switch_id} Restart"
    # Relay output
    - platform: gpio
        pin: 12
        id: ${switch_id}_out_relay1
        name: "${switch_id} Relay 1"

    status_led:
    # Use Sonoff LED as Status LED
    pin:
        number: 13
        inverted: True
    # Green LED Output

    binary_sensor:
    # Std Sonoff Push Button - Not very relevant, it's inside the Mirror
    - platform: gpio
        id: ${switch_id}_in_switch1
        internal: true
        pin: 0
        name: " Touch Switch 1"
        filters:
        - invert:
        on_click:
        min_length: 50ms
        max_length: 350ms
        then:
            - switch.toggle: ${switch_id}_out_relay1

    # Pull Switch - Soldered to GPIO2/Grnd
    - platform: gpio
        id: ${switch_id}_in_switch2
        internal: true
        pin:
        number: 2
        mode: INPUT_PULLUP
        name: " Touch Switch 2"
        on_multi_click:
        - timing:
            - ON for at least 200ms
            then:
            - logger.log: "Debounced ON"
            - switch.toggle: ${switch_id}_out_relay1
            invalid_cooldown: 0s
        - timing:
            - OFF for at least 200ms
            then:
            - logger.log: "Debounced OFF"
            - switch.toggle: ${switch_id}_out_relay1
            invalid_cooldown: 0s
    
    # Template to track Relay and give "on_state"
    - platform: template
        name: "${switch_id} Template 1"
        id: ${switch_id}_template1
        internal: true
        lambda: |-
        if (id(${switch_id}_out_relay1).state) {
            return true;
        } else {
            return false;
        }
        on_state:
        - if:
            condition:
                - binary_sensor.is_on: ${switch_id}_template1
            then:
                - delay: 60min
                - switch.turn_off: ${switch_id}_out_relay1
2 Likes