I have an automation to turn on/off the oil supply to my range cooker and it mostly works great, however I have had a number of instances where the turn on action fails due to network upgrades during the night coinciding with the switch on/off action. The automation is;
alias: Aga to automatic mode
description: ""
trigger:
- platform: state
entity_id:
- schedule.aga_on_off
condition:
- "{{ trigger.to_state.state in ['on', 'off'] }}"
action:
- service: switch.turn_{{ trigger.to_state.state }}
target:
entity_id: switch.switch_2f4bc2
I would appreciate some help to modify or have a simple version of the above to re-trigger the service call based on the state of the switch (ie, if the switch becomes available then it forces to the current state of the schedule).
I have tried something like:
alias: Aga-on-off check based on switch
description: ""
trigger:
- platform: state
entity_id:
- sensor.switch_2f4bc2_energy_apparentpower
from: unavailable
condition: []
action:
- service: switch.turn_{{ state.entity_id.schedule.aga_on_off }}
data: {}
target:
entity_id: switch.switch_2f4bc2
mode: single
Hoping that when the sensor changes from unavailable, that the switch will be set to the current state of the schedule. I have searched the documentation but without success.
I put together this library to do this. I use it for all my switches, lights, climate controls etc., because command do not always work. Using it requires some skill with shell.
Here is a specific example generated by that library
Thank you for this and I will dive into your solution when I get time. I have managed to write an automation that will ensure that the switch is turned on when the switch becomes available again, however, it would be useful to understand how to use the actual helper status as the switch type rather than having a specific condition:
alias: Aga Ensure on if it should be on
description: ""
trigger:
- platform: state
entity_id:
- sensor.switch_2f4bc2_energy_apparentpower
from: unavailable
condition:
- condition: state
entity_id: schedule.aga_on_off
state: "on"
action:
- service: switch.turn_on
data: {}
target:
entity_id: switch.switch_2f4bc2
mode: single