Hi there, I have created the below automations, which are supposed to turn off the lights when either my wife or me is leaving the house and nobody is home.
Sometimes it´s working, sometimes not. I believe it´s because I don´t understand whats the difference between a zone, away and not_home.
An example when it´s working:
We´re leaving both almost at the same time
An example when it´s NOT working:
I´m leaving earlier, and as I only need 5 minutes with my bike to get to work, I´m entering the zone “work” before my wife is leaving the home zone. When she´s leaving, none of the 2 automation will be triggered.
Now, my understanding was when I´m in another zone, which is not the home zone, I´m “not_home”, and if I´m in none oi my defined zones, I am “away”.
But obviously not, can someone fix my wrong thinking?
But what exactly is “not_home”? When I´m at work in my work zone, I´m physically not at home, but I can´t find this state anywhere, as my person.philipp entity is at “work”.
So you have a work zone then? But when you leave home it must go from home to not_home to work? Maybe check the zone docs… I’m only interested in home or not_home here.
‘away’ is just a frontend representation of the actual ‘not_home’ state. In conditions or triggers, you always use home/not_home (unless of course you have made your own device_trackers that actually have a state ‘away’, but I would suggest you’d not do that…)
further more, if you have zones defined, a device_tracker can either be in that/those zones, or be home/not_home. Of course a zone would also be not_home (except for the zone.home…) but you’d need to check for these states in a condition or trigger.
to give you an idea:
- condition: template
value_template: >
{% set zones = states.zone | map(attribute='name')|list %}
{{trigger.to_state.state in ['home','not_home'] or
trigger.from_state.state in ['home','not_home'] or
trigger.to_state.state in zones or
trigger.from_state.state in zones}}
this checks on both home/not_home and the zones. Iow, if a device is in a zone, it is not home/not_home…
But the “not_home” state gets overwritten as soon as I enter any of my defined zones, right? This is confusing me, because for me “not_home” is NOT home, even if I´m in a zone called work, sports or something else.
@David:
Yes, when I´m leaving home the state goes from “home” to “not_home”. But after 5 Minutes it changes from “not_home” to “work”
And when second person leaves home, the automation checks the state from my person for “not_home”, and because this is not true (as the state is “work”) the automation won´t trigger.
I guess maybe a combinded or condition would help to check if I´m at work
in the first automation you could add an or for person.philipp to be in a zone, hence my code snippet.
well, you should get to get to grips with HA Logic, don’t fight it…
of course it depends on the type of device_tracker. A simple network tracker is always home/not_home, Life360 or other gps trackers can follow the zones, and a person can be a composite tracker, all depending on the trackers you define the person to be based on.
btw you can write this as follows, since conditions are by default ‘and’-ed:
condition:
- condition: state
state: not_home
entity_id: person.philipp
- condition: time
after: 06:00:00
before: 08:00:00
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
having said that, I would suggest the use of condition: template, which has the benefit of being able to test the conditions in the developer/template page.
Bit disturbed that you seem to have text-based sensors for workday and homeworking. It would be more elegant to have them as binary_sensors that are 'on' or 'off'.
You can simplify further, as conditions are AND-ed by default. Without changing your sensors:
condition:
- condition: state
entity_id: sensor.workday
state: "True"
- condition: state
entity_id: sensor.homeworking
state: "True"
- condition: state
entity_id: input_boolean.chauffage
state: "on"
- "{{ is_state('person.raph_k', 'home') }}"
…and there’s no real need to use a template for your home detection. You could just as easily do this, like all your other conditions:
- condition: state
entity_id: person.raph_k
state: "home"
For these sensors, on my lovelace I have them used as switches in order to preset the days of the week as work or not; homeworking or not (for the heater).
(my sensors to determine it (same for homeworking))
- platform: template # determine if today is selected as working day or day off
sensors:
workday:
entity_id: sensor.date
value_template: >
{% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
{% set today_name = sensor_names[now().weekday()] %}
{% set entity_id = 'input_boolean.offwork_'+today_name %}
{{ is_state(entity_id, 'on') }}
I didn’t know the conditions are AND-ed by default, but indeed, it make sense, tanks for the tip
Initially my goal were to use the ‘condition: zone’ with a group of person:
- condition: zone
entity_id: group.family
zone: zone.zone.home
but homeassistant doesn’t like it, that’s why I used a template.