Hi all. New to the forum and to the whole platform, but already impressed by some of the community answers and examples. I haven’t, however, found one to address my current little project:
I would like an automation to turn on a light with an offset from sunset. That bit is fine. In my example it’s 2 hours prior.
Then, within this automation, I would like to try and use a wait_template to, well, wait until a fixed time, eg. 11PM. Sample code:
- id: '9827657219565'
alias: Timed Light Testing
trigger:
- platform: sun
event: sunset
offset: -02:00:00
action:
- service: homeassistant.turn_on
entity_id:
- switch.nightlights_entryway
# Some sort of "Wait until 23:00 instruction here"
- service: homeassistant.turn_off
entity_id:
- switch.nightlights_entryway
For the commented line, I have tried referencing the time_date and the worldclock sensors. I just can’t seem to get the config to check out. This is an example from another forum post that I’ve not had any luck with:
Why do you need a wait template to do something at a fixed time? This is just a simple automation to do that. You could still combine it into one automation if that is your goal…
You can try something like this: insert a random delay before executing your actions: - delay: '00:{{ (range(0, 5)|random|int) }}:{{ (range(5, 55)|random|int) }}'
Hmm, cheers, I was hoping to avoid that but it’s how I’m currently doing it. The thing is, I’ve heard that scripts are essentially the same as Actions, and I’ve had a bit of success there with a “wait until state change”. Maybe as an interim step I will try making a script to handle the waiting, then call that. Seems sorta clumsy.
I don’t want to need separate “on” and “off” actions for things that usually follow fixed patterns and aren’t interrelated to other actions, just trying to avoid Automation Sprawl really
Now THAT is looking really good! The “>” may be the only difference between that and some of my earlier attempts. Hmm.
Yes, I’m completely new to YAML and have quickly picked up on the importance of correct indentations and formatting. Not having a history with it is a challenge, and a lot of the examples I’ve seen for things are from older versions of HA or are formatted subtly differently to one another, so I’m still piecing together any sort of understanding at all.
With a dummy trigger:time instead of a sunset, your example is behaving perfectly. Thanks for the time and brainspace!