Hello, I am having some troubles with an automation that I recently created taking example on internet.
It’s not working, could you help me to make it works, I am a total noob in HA
#https://github.com/mertenats/Open-Home-Automation/blob/master/openhome/configuration/home_assistant/automation/automation_4a.yaml
alias: 'Presence simulator'
hide_entity: False
initial_state: True
trigger:
- platform: state
entity_id: group.trackers_us
from: 'home'
to: 'not_home'
- platform: state
entity_id: 'sun.sun'
to: 'below_horizon'
- platform: event
event_type: event_simulate_presence
condition:
condition: and
conditions:
- condition: state
entity_id: 'sun.sun'
state: 'below_horizon'
- condition: time
before: '23:01:00'
- condition: state
entity_id: group.trackers_us
state: 'not_home'
action:
# https://home-assistant.io/cookbook/perform_actions_based_on_input_select/
# https://home-assistant.io/getting-started/scripts/
- service: notify.PushBullet
data_template:
title: "Info"
message: "Presence simulator is running"
- delay: '00:{{ range(1,15) | random | int }}:00'
- service: light.turn_on
data:
entity_id:
- group.kitchen
- group.living_room
# wait
- delay: '00:{{ (range(30, 50) | random | int ) }}:00'
# turn off all devices
- service: light.turn_off
data:
entity_id:
- group.all_lights
# wait a little bit before turning on another lamp
- delay: '00:00:{{ (range(1, 5) | random) }}'
# generate an event to call again this automation rule
- event: event_simulate_presence
Hello, sorry I asked for help a bit in a rush
The idea here is nobody (my wife and I) is home and the sun is going down, I want to turn on the light of the kitchen and the living room but I different time everyday and FOR different time.
I want to simulate the presence of someone home until 23h00
I added a pushbullet notification to be sure it was working and since I was out yesterday I was execpting it. It never arrived.
If I triger the automation manually via the UI, it works…
Do you have any idea of what could be wrong in my automation that don’t start it, I guess it’s on the trigger level but no idea
Edit: I don’t think it could be linked but trigering it manually I noticed that the time is not correct, it tells me last_triggered: 2018-06-13T12:57:12.975476+00:00
when it suppsoed to be 08H58, I double check the timezone in my config, it’s correct…
Are your operating system and HA configuration in agreement as to selected timezone? If you’re on Linux, you can do this to see what timezone it is configure for:
ls -ld /etc/localtime; cat /etc/timezone
Make sure what those indicate is the same as what’s in your HA configuration.
Hello, first of all I am running HA in a docker container.
When I do the ls ld /etc/localtime I get
3503 Feb 10 06:43 /etc/localtime
When I do the second one it doesn’t find the file
Well, I’ve never used a docker container, so I don’t know how that plays into this. Bottom line, HA (and the python code it’s running) gets the time from the environment, so it’s important that the environment (whatever that is in your case) uses the same timezone as HA’s configuration.
Yes, I don’t see any problems. Not sure why it’s not triggering for you. Also, I agree, it must be the trigger if you manually trigger it and it seems to work that way.
The only thing I might suggest changing is change this:
- platform: state
entity_id: group.trackers_us
from: 'home'
to: 'not_home'
to this:
- platform: state
entity_id: group.trackers_us
to: 'not_home'
The group, I believe, should always be home or not_home, so you shouldn’t need the from: 'home' part. But I don’t think this will really make any difference.
If you have the automation shown in the frontend, then if you click on it (not the toggle switch, but on the name), a box should pop up and there will be a trigger button you can click. E.g.:
I’m not to much into zones, but if you use those, could it not switch from ‘home’ to ‘work’ or ‘school’? And back from ‘work’ to ‘home’ (assuming the device tracker is not changing quickly enough to ‘not_home’ in between)?
In that case it perhaps should be a different trigger.
A group of device_tracker entities will only take on the states home or not_home. It will not “inherit” any zone that any of the entities happen to be in. At least that’s how group.all_devices appears to work.
Like I said, I don’t think this change would affect whether or not it works. It just makes it slightly more compact/efficient.
If everyone in group.trackers_us was not home, then the corresponding condition was satisfiled. It should have run when sun.sun changed to below_horizon (assuming, of course, it was also before 23:01:00.) So, still don’t understand why it didn’t work for you. Unless, you were not home, but someone else in group.trackers_us was home. In that case, the third condition would have prevented it from running.
Note that the last_triggered time is shown as UTC (i.e., ‘+00:00’.) I assume by ‘08H58’ you meant 08:58 (AM) local time. Unless your timezone is UTC/GMT, 12:57:12.975476+00:00 is not your local time. If your timezone is -04:00, then that last_triggered time is probably right.
You are right, the sun trigger should have been enough
If I change the value of the sun myself manually the trigger works, its strange…
I will keep looking for a solution.
Don’t know, if you still have this problem. If yes, you may try to change your automations to use sun platform triggers instead of state platform triggers:
Whatever prevents your trigger from firing properly, changing the platform may help. Plus, the sun platform is a bit easier to configure, especially if you want to use offsets from the actual time of the sun rising or setting.