I have an automation which turns off a light at a certain time but I want it only to do so if no movement has been detected. If movement is detected I want to call script to extend the off time by 4 minutes.
I do it like this, or at least I thought I could but the home_asisstant.turn_off doesn’t like the extra data. Why doesn’t it just ignore it?
Is there a way around this? How can I call different scripts (or services) based on a condition if they need different data?
I don’t think that will work because the last “else” statement contains more than one line.
there might be a way to do that with a single line and comma’s but I don’t know enough about that to tell you how it needs done. I just remember seeing it done once a while back.
Sorry, out of town. Those templates won’t work. Jinja can only output 1 result. It can do multiple lines but the yaml will see it as “one output”. So you won’t be able to assign 2 attributes in 1 template. At that point, you’re better off making a script. I can’t really create a template cause I’m on my phone. But the general idea is 2 scripts, one does one action. The other does the other action. Then you programatically call the scripts. Pass all the variables you want because scripts will ignore things that the script doesn’t use. You won’t be able to use the entity_id attribute though as that is used by the service call for turning on a script.
Thanks and no problem about the delay in responding!
I have already reworked everything so that I am doing pretty much what you suggested.
In fact I have decided that service_template (rather like wait_template but that is discussed elsewhere ) should be used with caution and only in the very simplest of circumstances as it tends to promises more than it can deliver(*). Breaking things up into even smaller scripts and using condition seems to be the best way to do these decision based flows.
I do wish that a script with a service_template with no satisfying condition would just continue processing and that a service could receive ‘unnecessary’ data.
(*)Improved documentation on both of these regarding how they actually work at a more internal level wouldn’t go amiss and would remove the expectation that they can offer more than they do.