Setting and entity state using an automation

I am pretty new to HA and have done most of my stuff using Node Red, but I have recently created a dashboard switch which I use to toggle my hot water on and off. This works, but if you turn the hot water on manually, then my automatic schedule to turn the hot water on also fires, and then turns it off - the switch will remain at “on” position, even though the water has actually been turned off.

So, I am looking to create an automation that just waits for the state of the hot water to change from on to off, then changes the switch position. The trigger on the automation fires, but I can’t figure out how to actually change the state on the dashboard switch. I’m sure its pretty simple… any help appreciated.

This is the yaml:

alias: FlipHotWaterSwitch
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.hot_water_power
    from: "on"
    to: "off"
condition: []
action:
  - condition: state
    entity_id: switch.nodered_a6ad9655bc80b367
    state: "off"
mode: single

Hey,
You probably have an error message in your logs.

alias: FlipHotWaterSwitch
trigger:
  - platform: state
    entity_id: binary_sensor.hot_water_power
    to: "off"
action:
  - service: switch.turn_off
    entity_id: switch.nodered_a6ad9655bc80b367
1 Like

Had an error in my response as well. Check again

Ah! Thank you so much - that seems to be working perfectly now. The log just said “error - aborted” which is super helpful :smiley: thanks though!

Great.

As you said you are learning. This can be confusing in the beginning - now that I think about it, the docs are not that well sorted to that regard. You should bookmark these articles!

1 Like

I have a similar problem. Can you help me too?