Idea check a HA sensor on_bott and switch the relay

Hello.
I have, maybe a stupid, idea.

Y have a sonoff with epshome that have a 1 relay. its simple.
This relay have a usb fan that send air to a router.
My idea is only power on the relay in “winter” when i have a helper in “winter mode”.

When the “winter mode” is on, the relay is off. and when the “winter mode” is off, the relay is on.

I can make this with a automation but i think its interesting in the on_bott of esphome because when i lost the power or other problem. the esphome allways will be boot in the corres relay status.

my problem? i dont know how to make this
this code is my logical, but the code im sure is wrong. :stuck_out_tongue:
someone can help me?
thanks a lot!!!

  on_boot:
    priority: 600
    then:
        - platform: homeassistant
          id: winter_mode
          entity_id: input_boolean.modo_invierno_calefaccion
          internal: true
        - if:
            condition:
              winter_mode = off
            then:
              - switch.turn_on: relay
            else:
              - switch.turn_off: relay

I would do it like this:
Create a binary_sensor out of the HA input_boolean and use the on_press and on_release events to switch the relay.

binary_sensor:
  - platform: homeassistant
    id: winter_mode
    entity_id: input_boolean.modo_invierno_calefaccion  
    on_press:
       - switch.turn_off: relay
    on_release:
       - switch.turn_on: relay

If you lose power the ESP will fetch the input_boolean automatically on boot.

1 Like

thanks a lot!!!
i will try!