Is there a way to create a random light schedule for say, when you are on holiday. I have so far 5 Philips hue lights named
- light.dining_room_light
- light.bedroom_light
- light.living_room_light
- light.hall_light
- light.landing_light
and was wondering if it was possible to have say 2 or 3 on for 60-90 minutes then switch to another random set etc. Or am I just trying to take things a tad too far ??
It looks like @Danielhiversen is using a series of automations and scripts to track whether or not he’s been home in the past 48 hours. So, his automation triggers once the sun is below -4 degrees, but only if he’s not home.
You could just as easily get rid of this condition if you plan on enabling your “away mode” manually, or use some other condition.
yeah cheers, I already do that myself to a lesser degree (well not now ) it was the 48 hours bit I couldn’t work out how it was ran, i.e. is it a manual switch on the frontend? thanks
I have kind of butchered it and have come up with this… it is used along with 2 other I have on most of the time during the evening anyway and used a similar idea to turn them all off after a certain now random time… loving it thanks again
- alias: 'Switch on Random Lights when we are out'
hide_entity: False
trigger:
platform: numeric_state
entity_id: sensor.solar_angle
below: -20.0
condition:
condition: state
entity_id: group.family
state: 'not_home'
action:
- delay: '0{{ range(0,1) | random | int }}:{{ range(20,59) | random | int }}:00'
- service: light.turn_on
entity_id: light.dining_room,light.kitchen
data:
rgb_color: [255, 255, 255]
brightness: 150
- delay: '0{{ range(0,1) | random | int }}:{{ range(20,59) | random | int }}:00'
- service: light.turn_off
entity_id: light.dining_room,light.kitchen
- delay: '0{{ range(0,2) | random | int }}:{{ range(10,59) | random | int }}:00'
- service: light.turn_on
entity_id: light.bedroom,light.bathroom
data:
rgb_color: [255, 215, 255]
brightness: 150
- delay: '0{{ range(0,1) | random | int }}:{{ range(20,59) | random | int }}:00'
- service: light.turn_off
entity_id: light.bathroom
That’s great but if the family come back that evening, the delay method will not be tested further against the “not_home” condition and wouldn’t that make the rest of your evening pretty erratic?
Sorry for the delay in my answer as I didn’t have much time and I had to test it but no, turning off automations doesn’t stop what has been delayed in that automation from being run. It just won’t trigger anymore.
It appears to be randomizing the delay from 00:20:00 to 00:59:00 or 01:20:00 to 01:59:00 (20 to 59 minutes or between an hour and 20 minutes to almost 2 hours)
This is how I do my random lights when I am away from home. The below automation calls the script every 15 minutes plus 1 to 10 minutes random. The script checks if the light is on/off and trips it the other way. There is a group of inside lights that it chooses from.
This is pulling the entity_id attribute from the group.inside_lights state object.
Lets break down the object: states.group.inside_lights.attributes.entity_id
states is the state machine. This object contains all the objects/domains for home assistant. group is the domain. Domains are organizational areas for home assistant. I.E. Light, switch, group, input_boolean, climate are all domains of home assistant. inside_lights is the object_id. The domain + object_id equals the entity_id. I.E. group.inside_lights. attributes is the property where all ‘extra’ attributes are stored, things like brightness for a light. entity_id is the attribute that is inside the attributes property.
Now on to the filter. The | random filter chooses a random item in a collection. The collection can be a string or a list or tuple. If you use | random on a string, it will choose a random letter in the string. If you use | random it will choose a random item in the collection.
First, I have improved the automation, first it checks every 15 minutes, if the alarm is armed away and it is after sunset: then it adds an additional randomness to the lights and then toggles a random light on or off.
It’s because @rebelnme isn’t formatting his code properly and you are copying from that. The byproduct is that you end up using invalid string indication characters.
This should work for you:
alias: TEST
trigger:
platform: state
entity_id: input_boolean.trigger
to: 'on'
action:
- delay: '00:{{ range(1,10) | random | int }}:00'
- service: homeassistant.toggle
data_template:
entity_id: '{{ states.group.away_lights.attributes.entity_id | random }}'
Sorry about that. Evidently when I copied the text from my editor to the web page editor, it changed the characters. Those are not the characters in my automation. And, yes you need to indent the entity_id under the data_template.