Not sure why the conditions are not working. I want the lights to come on at sunset (if my wife or I are home) or when one of gets home, given it is after sunset. I know I want the sun to be below the horizon and one of us (my wife or I) to be home. But the action is not firing, which makes me think my AND is always returning a false statement.
- alias: Turn on Bedroom Lamp/Stairs Lamp if one of us is home and after sunset.
trigger:
- platform: sun
event: sunset
- platform: state
entity_id: device_tracker.wilsonama_amandasphone, device_tracker.wilsonbry_bryansphone
to: 'home'
condition:
condition: and
conditions:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
- condition: or
conditions:
- condition: state
entity_id: device_tracker.wilsonama_amandasphone
state: 'home'
- condition: state
entity_id: device_tracker.wilsonbry_bryansphone
state: 'home'
action:
service: switch.turn_on
entity_id: switch.tplink_sp_04, switch.tplink_sp_01
- platform: state
entity_id: device_tracker.wilsonama_amandasphone
to: 'home'
- platform: state
entity_id: device_tracker.wilsonbry_bryansphone
to: 'home'
I’m not really sure, but when I tried to do the same thing about 2 years ago, creating a group made it much cleaner and easier to maintain, since I have four devices.
You can do this without restarting HA, just create the group, modify the automation, then reload groups and automations.
I agree with @dap35 that a group will make this easier. (Actually, if there are only these two device_trackers, then there is already a group you can use – group.all_devices.) However, having said that, I see no reason why the automation shouldn’t work. Are you sure the automation is turned on?
BTW, the default for a list of conditions is AND. So you could simplify your automation to:
- alias: Turn on Bedroom Lamp/Stairs Lamp if one of us is home and after sunset.
trigger:
- platform: sun
event: sunset
- platform: state
entity_id: device_tracker.wilsonama_amandasphone, device_tracker.wilsonbry_bryansphone
to: 'home'
condition:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
- condition: or
conditions:
- condition: state
entity_id: device_tracker.wilsonama_amandasphone
state: 'home'
- condition: state
entity_id: device_tracker.wilsonbry_bryansphone
state: 'home'
action:
service: switch.turn_on
entity_id: switch.tplink_sp_04, switch.tplink_sp_01
So I figured out why it was not working (at least it works now.). My thought is that when the sunset event is triggered the elevation of the sun is 0. I assume that below_horizon means < 0 and the condition is not meet. Below is my remedy:
- alias: Turn on Bedroom Lamp/Stairs Lamp if one of us is home and after sunset.
trigger:
- platform: sun
event: sunset
offset: "00:05:00"
- platform: state
entity_id: device_tracker.wilsonama_amandasphone
to: 'home'
- platform: state
entity_id: device_tracker.wilsonbry_bryansphone
to: 'home'
condition:
condition: and
conditions:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
- condition: or
conditions:
- condition: state
entity_id: device_tracker.wilsonama_amandasphone
state: 'home'
- condition: state
entity_id: device_tracker.wilsonbry_bryansphone
state: 'home'
action:
service: switch.turn_on
entity_id: switch.tplink_sp_04, switch.tplink_sp_01