I’m struggling to get my automation to work. The idea is to turn on a room’s lights just before sunset if either of three devices are home. I don’t get any errors in the logs, but the automation just doesn’t trigger. Can anyone spot anything wrong:
- alias: Turn living room lights on at sunset if anyone is home
trigger:
platform: sun
event: sunset
offset: "-00:15:00"
condition:
condition: or
conditions:
- condition: state
entity_id: device_tracker.adams_phone_wifi
state: 'home'
- condition: state
entity_id: device_tracker.adams_phone_bt
state: 'home'
- condition: state
entity_id: device_tracker.catherines_phone_wifi
state: 'home'
just create a group with the 3 devices, and use one condition (if group state is on).
A the state of a group is already an or condition. It will be cleaner on your automations and you can use this group’s state for every other presence requirement
I notice your offset is defined with double quotes and the example offset is defined with single quotes. I wouldn’t expect that to matter, but when something doesn’t work I always go back to the example for reasons why.
If that doesn’t solve the problem, the next thing to do is remove the conditions. That will tell you if it is a trigger problem or a condition problem.
could you post the full automation (with action part).
Also could you check in dev-state if the status of the automation itself is on ? (you could force it using initial_state)
What happen when you try to trigger it manually using dev-services ?
I have a similair setup: I want my lights to turn on when I get home after sunset, but also if I’m allready home when the sun sets.
- alias: 'Lights on when home after sunset'
trigger:
- platform: state
entity_id: group.all_devices
from: 'not_home'
to: 'home'
- platform: sun
event: sunset
condition:
condition: and
conditions:
- condition: sun
after: sunset
- condition: state
entity_id: group.all_devices
state: 'home'
action:
- service: scene.turn_on
entity_id: scene.evening
My automation triggers if anyone comes home (anyone who is tracked that is). If you want to only trigger on the mentioned devices, just use multiple entries in your trigger like this:
- alias: 'Lights on when home after sunset'
trigger:
- platform: state
entity_id:
- device_tracker.adams_phone_wifi
- device_tracker.adams_phone_bt
- device_tracker.catherines_phone_wifi
from: 'not_home'
to: 'home'
- platform: sun
event: sunset
condition:
condition: and
conditions:
- condition: sun
after: sunset
- condition: state
entity_id: group.all_devices
state: 'home'
action:
- service: scene.turn_on
entity_id: scene.evening
a group works like an OR, if any of your device is home, the group is home.
I track multiple devices, but only 3 are used to determine presence so I have the following group
Can you still use an offset with sun condition “after: sunset”? I like having the lights come on before sunset as it gets a little dark in my flat before the “real” sunset
Not sure you can get this done in one automation because you have triggers and conditions switched for both cases.
Case one - as you have it above:
trigger: somebody comes home
condition: it’s after sunset
Your second case sound like:
trigger: the sun sets
condition: somebody is home
I’m happy to be corrected here, but creating 2 automations would be my (simple-minded) approach.
Regarding the delay, this is what I use:
- alias: Turn on living room light 13min before sunset if somebody is home
trigger:
platform: sun
event: sunset
offset: "-00:13:00"
condition:
condition: state
entity_id: group.people
state: 'home'
action:
service: homeassistant.turn_on
entity_id: switch.hook_b3
Hmm I just tried this, at it looks like the automation ran as I can see it was in the dev-state, however the lights never actually came on. Can you see anything wrong with it:
- alias: Turn office lights on at sunset if Adam is home
trigger:
- platform: sun
event: sunset
offset: "-00:15:00"
- platform: state
entity_id: group.adams_devices
to: 'home'
condition:
condition: and
conditions:
- condition: sun
after: sunset
after_offset: "-00:15:00"
- condition: state
entity_id: group.adams_devices
state: 'home'
action:
- service: light.turn_on
entity_id: light.desk_lightstrip
- service: notify.pushbullet
data:
message: "Office lights turned on"
I was already home. It seemed the automation triggered at the correct point too as it was last run ~15 minutes before sunset. Hmm, I’ve just checked my logs there’s a fair few “cannot reach the bridge” messages for my philips hue bridge so I suspect it’s that? I have been having some weird wifi issues with my pi which could be the problem. For some reason connectivity is very spotty (things like I can ssh in but it’ll drop out randomly or the typing becomes slow, and my samba share on Windows can’t connect to the pi) on the pi without having changed anything (when I first got it a few weeks ago the wifi connection was brilliant), is there something Home Assistant could be doing to cause slow downs?
Yeah, i tried using an ethernet cable earlier to help but I could never get it to connect.
What’s annoying is that the wifi connection has been super stable up until maybe a couple of days ago, so all my automations have been working really well.
I’m tempted to try nuking the pi and starting fresh to see if that helps, because I haven’t moved the pi and the wifi has suddenly gone, might also be able to get ethernet working then!
Sudden WiFi issues usually point to interference (could be because you’re started using ZigBee, could be a neighbour).
Getting wired networking going is usually a lot easier than WiFi. Generally it’ll just be a case of connecting a cable and rebooting. You’ll then need to disable the WiFi to avoid issues.