Zone not_home a valid state?

HI,

experimenting with some automations using the zoning on my 2 phones, I built these under the impression there’s only zone home, and the one’s one creates extra, following the documentation here https://www.home-assistant.io/components/zone/

however, in several of my message templates using from and to_state.state, the zone not_home is displayed… Is this also an existing state for zone?

Yes, but only for “Home” zone.

not_home is only valid when you’re not home and not in another defined zone.
Personally my conditions are != "home" for when I’m not home, regardless of where I am.

2 Likes

thanks, that was my ‘solution’ too:

  {% if trigger.from_state.state == 'home' %}
    {{ trigger.from_state.attributes.friendly_name }} left {{trigger.from_state.state}}
  {% elif trigger.to_state.state == 'home' %}
    {{ trigger.to_state.attributes.friendly_name }} arrived at {{trigger.to_state.state}}
  {% elif trigger.to_state.state != 'home' %}
    {{ trigger.to_state.attributes.friendly_name }} arrived at {{trigger.to_state.state}}
  {% else %}
    {{ trigger.to_state.attributes.friendly_name }} left {{trigger.from_state.state}} and arrived at {{trigger.to_state.state}}
  {% endif %}

not sure if this runs alright, but I want it to state when the devices leave home , arrive home (no matter from where), or any movement in between the other zones. the thing with the last line is i think it only displays when the whole journey has finished? Could this be valid?

had this before, but it kept triggering I left not_home and arrived at work…

#          {% if trigger.to_state.state == 'not_home' %}
#            {{ trigger.to_state.attributes.friendly_name }} left {{trigger.from_state.state}}
#          {% elif trigger.from_state.state == 'not_home' %}
#            {{ trigger.to_state.attributes.friendly_name }} arrived at {{trigger.to_state.state}}
#          {% else %}
#            {{ trigger.to_state.attributes.friendly_name }} left {{trigger.from_state.state}} and arrived at {{trigger.to_state.state}}
#          {% endif %}

by the way you may want to have 2 automations: one for people who arrive and one for people who leave.
The more you try to cram into a single automation, the more difficult it becomes to catch all possibilities and the more difficult it becomes to troubleshoot.

yes, i do think thats what i am experiencing at the moment …:wink:

since there is no group.all_zones by default (i think) this lists all zones (without home. not_home)
{{ states.zone | map(attribute='name')| list}}

How can I use that for a conditional value_template to check if the trigger.to_state.state is in that list?

would this be valid:

{% set zones =  states.zone | map(attribute='name') %}
  {{ states('trigger.to_state.state') in zones }}

(left out the |list, since it isn’t necessary to output the list, only check it the trigger is in the map?)

I have a zone called “Home”.
This works for me and returns True

{% set zones =  states.zone | map(attribute='name') %}
{% set test = "Home" %}
{{ test in zones }}

so I guess your example above should work :slight_smile:

difficult to check this all with the trigger versus a real entity_id, but nonetheless this seems safer, because it renders a list of all zones with there entity_id, rather their name. Enabling a trigger.zone check:

  - condition: template
    value_template: >
      {% set zones = states.zone | map(attribute='entity_id')|list %}
      {{trigger.to_state.state is in ['home','not_home'] or
        trigger.zone is in zones}}

Note that {% set zones = states.zone | map(attribute='entity_id')|list %} will give you a list of zone entities indeed, so ['zone.work', 'zone.home'] etc
trigger.to_state.state will return a state, e.g. home, not_home, work and so will not work

If you were to fix this however, I guess the condition would always be true?
I mean a device_tracker can be home, in a preset zone, or away (not_home)…

exactly, thats why I use it… trigger.zone should be in that list, or in [‘home’,‘not_home’], which aren’t in that list but are also valid states for trigger Home, which I dont have set.

thinking the trigger.to_state.state can’t be in {% set zones = states.zone | map(attribute='entity_id')|list %} so it wont trigger?

Or would trigger.to_state.state also use the zones for valid states?

the thing is the state trigger would also fire when any of the attributes of the devices change, and does so even when to or from are declared.
This value_template is there tp prevent that from happening and only use true states as condition under which the action should fire.

Morning all , coming back on this topic , i need an advise to how to manage the sitauation :slight_smile:I have push notification if a camera gets a movement , that works.
I want the notification working only when i am not home , but i have also a work zone , so i assume myself is defined as “work” and not “not_home” , any idea to fix the loop?
I assume the automation should check the following if your state is not home trigger the notification if a movement is catched ; i just do not know how to create a negative if.

Thanks

condition:
  condition: template
  value_template: >
    {{states('person.you') != 'home'}}
1 Like

Hi , thanks , something like that ?

- alias: Motion notification
  description: ''
  trigger:
  - entity_id: binary_sensor.stairsmotionsensor
    from: 'off'
    platform: state
    to: 'on'
  condition:
  condition: template
  value_template: >
    {{states('person.me') != 'home'}}
  action:
  - service: notify.mobile_app_xxx
    data:
      message: Motion alert

yes, with a bit of spacing and cleaning up:

- alias: Motion notification
  description: ''
  trigger:
    platform: state
    entity_id: binary_sensor.stairsmotionsensor
    #from: 'off' not necessary, because of being binary
    to: 'on'
  condition:
    condition: template
    value_template: >
      {{states('person.me') != 'home'}}
  action:
    service: notify.mobile_app_xxx
    data:
      message: Motion alert
1 Like

Many thanks

welcome, glad to be of help. let us know how you fare :+1:

It works great!! thank you

1 Like

This last bit helped me with a similar situation.