This should be an easy automation, but it isn’t. I have two presence trackers based on pinging our phones. I also have a boolean switch for visitiors, the idea being if me and my wife are going out, we can turn on the visitors switch so the babysitters aren’t plunged into darkness 5 minutes after we leave
The first time I set it up I put both the device trackers in a group and used that as the trigger. When the state goes from home to away the action is called, so long as the visitors switch is off (condition). This didn’t seem to work. One of us would leave the house while one stayed at home and that person would be plunged into darkness.
Then I tried this:
alias: Turn All Lights off When We Leave
trigger:
- entity_id: device_tracker.steve
from: home
platform: state
to: away
- entity_id: device_tracker.max
from: home
platform: state
to: away
- entity_id: input_boolean.visitors
from: 'on'
platform: state
to: 'off'
condition:
- condition: state
entity_id: device_tracker.steve
state: away
- condition: state
entity_id: device_tracker.max
state: away
- condition: state
entity_id: input_boolean.visitors
state: 'off'
action:
- data:
entity_id: group.all_lights
service: light.turn_off
Which I thought was working fine, until we came back from a day out to find the kitchen cupboard lights were still on, oops.
Can anyone suggest a way I can make this automation work properly, i.e. if one of us leaves the lights stay on, but if both leave (not necessarily at the same time), the lights turn off?
You could make a group for your device trackers and use the group as the trigger.
The condition then only checks the visitors boolean.
I don’t have device tracker but for my lights the corresponding group is “on” if at least one light is on, otherwise it’s “off”. Maybe a group of device trackers then provides “home” and “away” or “on” and “off”, that’s what you need to check.
That setup is exactly what I use, group all the device trackers for each person into a group for that person (so that it doesn’t matter if the WiFi goes to sleep, as long as one of the other tracks shows it at home), and group those groups for everybody. Then I use that master group for detecting if everybody is away.
This is what I do also and has been working well… and if your visitors are regular enough that they have your WiFi password you can start naming their devices in HA by checking the Mac ID in known_devices… my in-laws show up on my “who’s home list” and that is used to prevent certain alerts or lights from triggering while they are home and wife and I both away…
I have tried the device group before but it didn’t work. When my wife goes out during the day and I stay at home working the kitchen lights go off (the only lights we have on during the day). I have just checked back through my groups.yaml file and can see that my device tracker is listed as ‘device_tracker.stev’ rather than ‘device_tracker.steve’ even though I can see my tracker name and face in the front end. I have corrected this, updated the automation and restarted Hass. Hopefully this will work now! Thanks.
I know I am late to the party, @Nimdy, but here is my configuration.
First, I set up a binary_sensor:
binary_sensor:
- platform: template
sensors:
people_home:
value_template: >-
{{ is_state('device_tracker.my_phone_ping', 'home')
or is_state('device_tracker.my_phone_gps', 'home')
or is_state('device_tracker.roommate_phone_ping', 'home')
or is_state('device_tracker.roommate_phone_gps', 'home') }}
Then, my automation looks like this:
- alias: Turn Off Lights When House is Empty
description: 'Turns off all lights when no one is in the house'
trigger:
platform: state
entity_id: binary_sensor.people_home
to: 'off'
action:
service: light.turn_off
entity_id: all
I have tried the solutions offered in this thread but with no luck, when I leave home with my youngest my eldest is plunged in darkness .
I would appreciate it if someone could point me in the right direction on how to setup HA to check two devices present before turning off or leaving on the lights.
Not direct answer on your problems but: never let performing critical operations to automatons. Never.
Make system send you notification that no one left home but there are lights on. Then you can turn lights off remotely if needed. You can use Actionable notifications which offers button to execute action(s)