So an automation that start the automation and stops then i am home again?
Yeah, just use ‘homeassistant.turn_on’ or ‘homeassistant.turn_off’ and call out the automation you want to turn on and off using it’s entity id.
Thanks dude, sure thats the way
Hi
I still need help
I need to run my script continuesly until sun.sun is above_horizon.
How should the automation look like?
how often do you want it to run? Once every minute?
The script is turning lights on and off with some delays.
Lets say 30minutes is the script running, and after that, it should run again, but only if the sun.sun is below_horizon.
As soon as the sun.sun is above_horizon the script can stop then its done turning the lights on and off.
Its for my alarm system, anti thief with the lights
oh then you don’t even need to turn it on or turn it off. Just use a time_pattern trigger with a condition
trigger:
platform: time_pattern
minutes: /30
condition:
condition: state
entity_id: sun.sun
state: 'above_horizon'
action:
service: script.xxxxx
So the scripts should only start then i am away from home only.
So the automation is running, lets say each minutes and run the script if the conditions are true?
My script is still not triggered.
automations will only trigger if the conditions are true. So it will attempt to run every x minutes if conditions are met.
Okay, thank you
I have something not too dissimilar. I’d suggest something slightly different. @petro’s suggestion is fine, but this might work a little better for you.
First, make the script run long enough to cover the whole time between sunset and sunrise, even if you include random delays.
Next, create an automation that starts the script when the sun is below the horizon AND you’re not home. (I assume you want it to start if you leave after sunset, yes?) This can be done with a template trigger.
Lastly, create another automation that stops the script when the sun goes above the horizon OR you come home.
If you like this idea, let me know if you need any concrete examples.
But what if he leaves before sunset ?
The expression becomes true when both conditions are met, and that’s when the automation triggers. If he leaves before sunset the expression will not be true yet, so it won’t trigger. But when the sun sets, if he’s still gone, the expression will become true and the automation will trigger.
EDIT: So then you ask, what happens if he comes back home, and then leaves again, all while the sun is still set? It will trigger again when he leaves, because once a template trigger fires it won’t fire again until the expression becomes False, and then True again.
Sorry, I thought I found a gap but you had it covered.
Thank you guys.
I need to have the script running only then i am not_home and the sun.sun is below_horizon.
The issue i got now with @petro solution, is that the script is keep running, how can i stop it, lets say the scripts are half way done, and i come home, i want the script to stop, and not continue.
will script.turn_off work?
yep it will
I see this in my log:
Script script.anti_thief_light already running.
I see this now, then i am using script.turn_off
AttributeError: 'NoneType' object has no attribute 'is_on'