I have spent the better part of my morning trying to figure out my service_templates. I have a script that runs when my chromecast starts playing. I want it to turn on the stereo (if it was off), change the input and turn on a specific light scene if the sun is down.
The commands are IR commands, and the on command is the same as the off command, so hence why I try to check if it is currently on or off. It works fine when the stereo was off, but it seems to stop executing everything if the stereo was already on. I.e., it doesn’t change the channel and activate the scene. This is my code:
If you look at your error log, you probably have an error related to passing the entity ID data with no service when your template returns false. If you don’t pass a service, you can’t pass the data for that service (oh how I wish HA would just skip that step in these cases though!)
How are you activating this script? You may need to set this up with a bit of a workaround where you launch a script that simply determines if the stereo is on first, and then from there launches one of two secondary scripts; one that starts by turning the stereo on if it was off, and another that doesn’t include that step at all if it was already on.
Thank you for your response. Sorry for my late reply, I haven’t had the time to look at it again before now. It seems you are absolutely right. That is quite annoying indeed. I was launching this script by checking if the state of the chromecast changed from ‘off’’ to ‘playing’.
Would it be possible to use a data_template for the entity_id, together with the service_template? That way I could either also supply an empty entity_id, or call a script that does nothing but wait for a couple of milliseconds. I had a fiddle around but it kept saying invalid config when I attempted the data_template.
My guess would be that you cannot do that as I think HA will still try to pass the blank value for both which causes the error.
Another alternative could be to do something else like submit something to a log as your action with data instead of it just being blank, or splitting things up as I suggested in my previous post.