Use case: I have a window fan and only want to be able to switch it on if the window is open. If it is accidentally turned on with the window closed, it can cause damage to the motor. I know I can create an automation to catch when the state goes to ‘on’ and then switch it back to off right away.
I was wondering I there is a way to go one better and prevent the switch from executing? Like a disable concept?
Just to add onto this I’ve tweaked the code a little to suit what I’m using it for (similar thing not being able to send the swing ir command if the fan isnt on) but it doesnt seem to actually work it never actually toggles the swing switch?
Two things to narrow it down. If you get rid of the template and just do entity_id: switch.wall_fan_swing does it turn on? If you toss the template in the template area on the ui (Developer Tools - Template) does it give the result you are expecting?
Totally agree with @rabittn but I think the value template should just be what is used to maintain the state of the switch and not affect the actual service from executing.
Ill re-explain the problem so what im trying to do is have it so that I can only use the swing toggle if the fan is already on, both are sent via IR so I’m trying to use home assistant to keep track of the status eg
Fan is off you cannot send the swing command
Fan is on you can send the swing command
I have to do it that way because it remembers the last option for swing so if the fan was turned off with swing on then swing on needs to remain untouchable until the fan is switched back on.
Hopefully they makes a bit more sense also @azeroth12 I tried your code and I still have the same issue, the “real ir switch that sends the command” is not toggled in home assistant and also the template switch always automatically switches itself off if the fan is off and vice versa if the fan is on (itll turn itself back to the on position if I try switch it off)
Sorry for the thread hijack I just thought our issues were similar.
ERROR (MainThread) [homeassistant.helpers.script.1p_svetlo_kuchyne_bodovky] 1P Světlo Kuchyně bodovky: Error executing script. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data[‘entity_id’]
Error is showing, when I turn on switch with following setting in configuration.yaml: