State != "home"

Hello,

I try to make an automation that when someone leaves the house AND the rest of the family is not home, a light goes out. Because I use zones, I want to switch off the light when everybody is NOT home but for some reason it’s not working:

- alias: 'Iemand gaat weg'
  hide_entity: True
  trigger:
    - platform: state
      entity_id: device_tracker.me, device_tracker.other
      from: 'home'
      to: 'not_home'
      for:
        seconds: 20
    - platform: state
      entity_id: input_boolean.kid1, input_boolean.kid2
      from: 'on'
      to: 'off'
  condition:
    condition: and
    conditions:
     - condition: template
       value_template: '{{ states.device_tracker.me != "home" }}'
     - condition: template
       value_template: '{{ states.device_tracker.other != "home" }}'
     - condition: state
       entity_id: input_boolean.kid1
       state: 'off'
     - condition: state
       entity_id: input_boolean.kid2
       state: 'off'
  action:
    - service: switch.turn_off
      entity_id: switch.light

For some reason when one of the device.trackers is HOME and one of the input_boolean is set from ON to OFF, the light switches OFF.

When I don’t use zones and only home or not_home and work with state it works like a charm:

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

Can anyone find what’s wrong?

Thx

Erik

Entity id should be group.all_devices

Also, triggers work as if they had an OR operator (AND is not possible). In other words: any trigger being met will trigger the automation (assuming the conditions are met, of course).

I tried that but that does not affect anything.

When I change this:

 - condition: template
   value_template: '{{ states.device_tracker.me != "home" }}'

to this (for me and other):

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

everything works.

It would need to be states.device_tracker.me.state for that template to work.

1 Like

OK, that is what I need…

Don’t look at the trigger part. That part works. The problem is in the condition part.

I’ll try that. thanks

The problem is that when you use zones the not_home status is not always reflected (ie shows you as ‘shops’ instead), the only way to get ‘not_home’ is to use the group.

It looks to be working now if I try at home with fake GPS. I’ll test it later today.