i tried to turn of lights automaticly when two named persons aren’t home.
I read the documentations about Conditions form HA, but all of these 3 options aren’t working.
Sorry when this questions is asked often. I found a similar topic with the same problem, but there solution was like option 1.
here ist my code:
condition:
condition: and
conditions:
- condition: state
entity_id: "device_tracker.xy"
state: "not_home"
- condition: state
entity_id: "device_tracker.xx"
state: "not_home"
Did I missunderstood something or ist it just on my HA instance?
As a condition, this should return true when both persons are not_home. Technically the and isn’t needed here: conditions that are placed below one another in an automation are by default ‘and’ (unless they are in an ‘or’). You only ever need the 'and ’ inside an ‘or’ for complex tests.
But that is not your problem. What you are missing is a trigger. When should HA check if both people are not home? This should be when either device tracker changes from home to something else. So you need two state triggers above the conditions. Conditions are just things that must also be true when the trigger happens.
There is one other potential problem with the automation. When you define more zones, the state can also have other values, such as “Work” or “School”. So the best way is to use a “not” combined with “home”.
Check my post above - I think you’re missing the difference between conditions and triggers. This is not a complete automation, it is just a test. (Aside from all the other possible and needed improvements).
This does what you probably want to achieve - send a message when the last person leaves home:
alias: example
description: ""
trigger:
- platform: state
entity_id:
- zone.home
to: "0"
not_from:
- unavailable
- unknown
condition: []
action:
- service: notify.persistent_notification
data:
message: The last person left home
mode: single
If you are only interested in two persons being gone, and not any others, it would be this (so a third person could still be home!):
alias: example
description: ""
trigger:
- platform: state
entity_id:
- device_tracker.jasper_s_telefoon
- device_tracker.rianne_s_telefoon
from: home
not_to:
- unavailable
- unknown
condition:
- condition: not
conditions:
- condition: state
entity_id: device_tracker.jasper_s_telefoon
state: ""
- condition: not
conditions:
- condition: state
entity_id: device_tracker.rianne_s_telefoon
state: home
action:
- service: notify.persistent_notification
data:
message: The both Rianne and Jasper are not home
mode: single
I’m sorry, i didn’t post all of my code.
Of course i’ve set a trigger for both persons.
platform: state
entity_id:
- device_tracker.xy
- device_tracker.xx
from: home
to: not_home
for:
hours: 0
minutes: 0
seconds: 0
i’m not using the zones from HA.
I just use the nmap tracker addon to check the wifi connections.
this is what the automations webpage shows me, when i want to change the configs in YAML …
These 3 steps (trigger, conditions and action) are seperated for me
Sure i could use the standard zone “home”, but nobody will ever be “home” cause tracking is disabled on the mobile phones.
Now it is working. I was wrong with editing on the webpage.
I tried to use the “condition: and” function in another function in condition. So i mixed up functions in the condition. my fault.
Next time i will instant code in the YAML file of HA.
If you link the device trackers you mention to the right person, it will work with the home zone. It doesn’t need to be a phone tracker or even a gps tracker. IP tracking from the router will work just as well, provided your battery does not die or wifi isn’t turned off. Because then the router will think your gone and kill the lights, same as with your automation I’m afraid. Or is it a BLE tracker?
I use for this NMAP Tracker. When I’m right, it creates a new Entity named device.tracker.
But ur right, if the battery dies or the wifi is turned of, it will kill the lights.
I think it is a realy rare chance, that both batteries dies at the same time or either the wifi will be turned off.