Device tracker states / automation turn_on

Hi all, im struggling on the device tracker states. I have read alot here and it seems that i need:
from: ‘home’
to: ‘not_home’

I want to turn the screens automations on when both phones leave the house. Then turn it of again when one of the 2 phones get back home.

But this seems only work when leaving home now. Anyone has an idea?

Thanks for the help:

 - alias: 'rolluiken prog aan afwezigheid'
    trigger:
        platform: state
        entity_id: device_tracker.marcel_s7_2, device_tracker.simone_iphone_5se_2
        from: 'home'
        to: ' not_home '
    action:
        service: homeassistant.turn_on
        entity_id: automation.vakantieprogramma_rolluiken_dicht, automation.vakantieprogramma_rolluiken_open

  - alias: 'rolluiken prog uit aanwezig'
    trigger:
        platform: state 
        entity_id: device_tracker.marcel_s7_2, device_tracker.simone_iphone_5se_2
        from: 'not_home'
        to: 'home'
        for: '00:01:00'
    action:
        service: homeassistant.turn_off
        entity_id: automation.vakantieprogramma_rolluiken_dicht, automation.vakantieprogramma_rolluiken_open

I’m not really sure how the ‘leaving home’ automation is working satisfactorily the way you say you want it to work.

All automation triggers are ‘or’. That means that if either of the entities goes from ‘home’ to ‘not_home’ then the automation will trigger and turn on the target automations. Which as you describe is not the way you want that automation to work.

If anything I would say that the ‘arriving home’ automation should be the one working correctly.

That is because when either entity goes from ‘not_home’ to ‘home’ then the automation will also trigger to turn off the target automations.

To get it to turn on the automation only after both phopnes leave you can do it two ways. Either put both device trackers in a group and use the status of that group as the trigger. The group will only be ‘not_home’ when both phones are also ‘not_home’.

Or you could use a template trigger using an ‘and’ for both entities to be ‘not_home’ in the template to set the trigger to be true.

Thanks for the reply. I have it working now with ‘or’ But not with ‘home’ and ‘not_home’.
i used not_home and ‘thuis’ for it and now it works. I will try to make zones and put both cellphones in it. Thanks for the help.

  - alias: 'rolluiken prog aan afwezigheid'
    trigger:
        platform: state
        entity_id: device_tracker.marcel_s7, device_tracker.simone_iphone_5se
        to: 'not_home'
    action:
        service: homeassistant.turn_on
        entity_id: automation.vakantieprogramma_rolluiken_dicht, automation.vakantieprogramma_rolluiken_open

  - alias: 'rolluiken prog uit aanwezig'
    trigger:
        platform: state 
        entity_id: device_tracker.marcel_s7, device_tracker.simone_iphone_5se
        to: 'thuis'
    action:
        service: homeassistant.turn_off
        entity_id: automation.vakantieprogramma_rolluiken_dicht, automation.vakantieprogramma_rolluiken_open

Hi, I think I have a same kind of a problem…
I have two automations. 1 for activating the alarm system and holiday timed lamp schedule when my wife and I leave home. And 2, when one of us comes home, deactivation of the alarm system and holiday timed lamp schedule.

But… Only the deactivation automation with the coming home is working.

I don’t know how to make the activation work. I have 6 or 7 zones in home-assistant.

This is what iI have now:

- id: automation 56
  alias: alarm en vakantie-licht AAN bij weg
  trigger:
    platform: state
    entity_id: device_tracker.iphonevanbart6_3, device_tracker.iphonevanciska2_0
#    from: "home"
    to: "not_home"


  condition:
      condition: and
      conditions:
      - condition: state
        entity_id: device_tracker.iphonevanbart6_3
        state: "not_home"
      - condition: state
        entity_id: device_tracker.iphonevanciska2_0
        state: "not_home"


  action:
    - service: homeassistant.turn_on
      entity_id: input_boolean.vakantie, input_boolean.alarm_huis
    - service: notify.pushberichten
      data:
        message: "alarm en vakantie-modus"
        title: "beveiliging AAN"
        target: ""

- id: automation 56a
  alias: alarm en vakantie-licht UIT bij weg
  trigger:
    - platform: state
      entity_id: device_tracker.iphonevanbart6_3
      to: 'home'
    - platform: state
      entity_id:  device_tracker.iphonevanciska2_0
      to: 'home'


  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.vakantie, input_boolean.alarm_huis
    - service: notify.pushberichten
      data:
        message: "alarm en vakantie-modus"
        title: "beveiliging UIT"
        target: ""

hi Bart, Try to change not_home to ‘away’

1 Like

I don’t think that is the problem.

device tracker states are always ‘home’ or ‘not_home’. ‘away’ is only shown in the front end.

@bart

Can you trigger the actions manually from the automation pop-up window "trigger’ button?

1 Like

I think that it can be done the way they were doing it as a comma separated list.

But I’m also pretty sure you can do it using a dash separated list as you have it above, too.

However I’m positive you can do it with the two discreet triggers listed as you recommend. :wink: And I think I like it better that way too if for nothing else than for readability.

if the manual trigger worked I was going to suggest changing the format of the triggers next.

Here is a section of the docs that specifically gives a comma separated list in the entity_id field of a state trigger. So it should work.

https://www.home-assistant.io/docs/automation/trigger/#state-trigger

Well, go figure. Special casing this isn’t going to help people understand why their YAML syntax doesn’t work the same everywhere. Thanks for pointing this out; I’ll remove my previous posts since they don’t actually contribute this particular conversation.

2 Likes

Thanks for the help! I could trigger the automation manual.

I think the problem is the ’ CONDITION’ section.
could be 2 options then:

  1. When my phone goes to ‘not_home’ it triggers the automation. But probably home-assistant doesn’t have my phone already as ‘not_home’ in the condition section. so, the trigger and check state condition are in home-assistant system in the wrong line-up.
    or…
  2. I have a lot of divert zone’s. Probably when I am “AT WORK” zone, home-assistant doesn’t see me in the condition ’ not_home’ because I am ‘AT_WORK’.

I really don’t have a clue.

I now just made 2 automation. For each phone one. Hope this works :slight_smile:

#(try)
- id: automation 56
  alias: alarm en vakantie-licht AAN bij weg1
  trigger:
    - platform: state
      entity_id: device_tracker.iphonevanbart6_3
      to: 'not_home'

#(what I had before...)
#  condition:
#      condition: and
#      conditions:
#      - condition: state
#        entity_id: device_tracker.iphonevanbart6_3
#        state: 'not_home'
#      - condition: state
#        entity_id: device_tracker.iphonevanciska2_0
#        state: 'not_home'

  condition:
    - condition: state
      entity_id: device_tracker.iphonevanciska2_0
      state: 'not_home'

  action:
    - service: homeassistant.turn_on
      entity_id: input_boolean.vakantie, input_boolean.alarm_huis
    - service: notify.pushberichten
      data:
        message: "alarm en vakantie-modus"
        title: "beveiliging AAN"
        target: ""

#(try)
- id: automation 56b
  alias: alarm en vakantie-licht AAN bij weg2
  trigger:
    - platform: state
      entity_id: device_tracker.iphonevanciska2_0
      to: 'not_home'


  condition:
    - condition: state
      entity_id: device_tracker.iphonevanbart6_3
      state: 'not_home'


  action:
    - service: homeassistant.turn_on
      entity_id: input_boolean.vakantie, input_boolean.alarm_huis
    - service: notify.pushberichten
      data:
        message: "alarm en vakantie-modus"
        title: "beveiliging AAN"
        target: ""


#(works)
- id: automation 56a
  alias: alarm en vakantie-licht UIT bij weg
  trigger:
    - platform: state
      entity_id: device_tracker.iphonevanbart6_3
      to: 'home'
    - platform: state
      entity_id: device_tracker.iphonevanciska2_0
      to: 'home'


  action:
    - service: homeassistant.turn_off
      entity_id: input_boolean.vakantie, input_boolean.alarm_huis
    - service: notify.pushberichten
      data:
        message: "alarm en vakantie-modus"
        title: "beveiliging UIT"
        target: ""



1 Like

I finally got it to work good with the 2 cellphones. After reading all posts here with the not_home and home you would think this doesnt work, but it does.

  - alias: 'rolluiken prog aan afwezigheid'
    trigger:
        platform: state
        entity_id: device_tracker.marcel_s7, device_tracker.simone_iphone_5se
        to: 'not_home'
    condition:
        condition: and
        conditions:
        - condition: state
          entity_id: device_tracker.marcel_s7
          state: 'not_home'
        - condition: state
          entity_id: device_tracker.simone_iphone_5se
          state: 'not_home'
#        - condition: time
#          after: '20:00'
    action:
        service: homeassistant.turn_on
        entity_id: automation.vakantieprogramma_rolluiken_dicht, automation.vakantieprogramma_rolluiken_open

  - alias: 'rolluiken prog uit aanwezig'
    trigger:
        platform: state 
        entity_id: device_tracker.marcel_s7, device_tracker.simone_iphone_5se
        to: "thuis"
  #  condition:
  #      condition: and
  #      conditions:
  #      - condition: state
  #        entity_id: device_tracker.marcel_s7
  #        state: "thuis"
  #      - condition: state
  #        entity_id: device_tracker.simone_iphone_5se
  #        state: "thuis"
    action:
        service: homeassistant.turn_off
        entity_id: automation.vakantieprogramma_rolluiken_dicht, automation.vakantieprogramma_rolluiken_open
```
1 Like