I’ve a sensor who detect if the window is opened, and in that case will ask a Shelly relay to switch off heating, then switch on when window is closed.
I’ve done two automations, I’m interested to know if that can be achieved with only one ?
Use the trigger to/from state to derive the service to call.
trigger:
- platform: state
entity_id: binary_sensor.door_window_sensor_1
# When this changes state and remains stable for 10 seconds...
for: '00:00:10'
condition: []
action:
# to_state will be either off or on. Do the inverse.
- service_template: "switch.turn_{{'off' if trigger.to_state.state == 'on' else 'on'}}"
entity_id: switch.shellyPM
I just guessed about being able to use ‘for’ without a ‘from’ or ‘to’. Guess not.
So we’ll just add both as triggers to the same automation. It will work this way as well.
trigger:
- platform: state
entity_id: binary_sensor.door_window_sensor_1
from: 'off'
to: 'on'
for: '00:00:10'
- platform: state
entity_id: binary_sensor.door_window_sensor_1
from: 'on'
to: 'off'
for: '00:00:10'
condition: []
action:
# to_state will be either off or on. Do the inverse.
- service_template: "switch.turn_{{'off' if trigger.to_state.state == 'on' else 'on'}}"
entity_id: switch.shellyPM
Hello, I would like to add a simple automation. If window is open -> heating “off”. If window is closed -> heating “auto”. Can I implement all in one automation, like: If window is open -> heating “off” else heating “auto”?