I have a simple Zigbee smart switch set up to turn one light on at 17.30 and off at 05.30. I’d like to have it randomly go on and off during those hours. Everything I’ve seen is pretty involved with multiple lights and lots of Yaml coding. Isn’t there something real simple that would do the job?
trigger:
- platform: state
entity_id: light.your_light
to:
for:
minutes: "{{ range(30,90)|random }}" # 30 to 90 minutes feel free to change
condition:
- condition: time
after: "17:30"
before: "05:30"
action:
- service: light.toggle
entity_id: light.your_light
You will still need your light on and off automations. Alternatively they could be incorporated into this automation with a choose action and trigger ids. But that would make it more complicated.
You want to simply turn a light on/off but in a complex fashion that’s not merely based on a fixed schedule but a randomly varying one.
The Automation Editor has limitations (and bugs). In Visual mode it supports some but not all of Home Assistant’s scripting language. All automations are stored as YAML and so the YAML version will always have the ability to employ every possible scripting feature.
Tip
When composing an automation in Visual mode, occasionally toggle between Visual and YAML modes to learn how the Automation Editor converts what you compose using the UI into YAML.
Sorry Tom, I think I lost the flow of the discussion and didn’t realize you were replying to EdwardTFN (although, it was productive because my ‘all-in-one’ automation’s Time Condition did block the 05:30 Time Trigger and needed correction).
Thanks for all the help here. I’m still trying to get the toggle to work. I adjusted the time between 07:00 and 12:30 so I can test it during daylight.
I’m playing around with Tom’s automation and have both on and off switches active.
The toggle, however, doesn’t work as I get a warning:
Logger: homeassistant.helpers.service
Source: helpers/service.py:635
First occurred: 07:01:09 (1 occurrences)
Last logged: 07:01:09
Unable to find referenced entities switch.dining_room_smart_plug_switch or it is/they are currently not available
That entity is listed so I’m confused why it isn’t seen.
I found an interesting solution by “Speak to the Geek” while researching for this topic.
He provides a blueprint to single-light automations.
His approach makes sense because we cannot have the same random pattern for the bedroom, the living room and the bathroom. Each one has their timings and durations.