Away Switches off all devices

Hi guys,
So the what’s supposed to happen is, when we both go out of the house, all devices should turn off,
but what’s happening is, devices are switched off even if one person leaves the house.
What is my code missing. Thanks.

- alias: Away
  initial_state: True  # This makes sure that the automation is enabled after a HA Restart.
  trigger:
    platform: state
    entity_id: 
        - device_tracker.life360_ajitha_krishna
        - device_tracker.life360_kamal_krishna
    from: home
  action:
  - service: switch.turn_off
    entity_id: all
  - service: light.turn_off
    entity_id: all

either device tracker is triggering the action.
put the device trackers in a group and force the group to change state only if all trackers leave.

1 Like

Or just adding a condition that you are both ‘not_home’ should also work

  - alias: Away
    trigger:
      - platform: state
        entity_id: 
          - device_tracker.life360_ajitha_krishna
          - device_tracker.life360_kamal_krishna
        from: 'home'
    condition:
      - condition: state
        entity_id:
          - device_tracker.life360_ajitha_krishna
          - device_tracker.life360_kamal_krishna
        state: 'not_home'
    action:
      - service: switch.turn_off
        entity_id: all
      - service: light.turn_off
        entity_id: all

Please note that I removed the intial state as : -

  1. setting this also removes the last triggered attribute from such automations on a restart (making any automation using this either crash or requires special checks to be put in place)
  2. if you ‘have’ to turn off automations (not really good practice) as part of ‘some other’ scheme. Then you can list all such automations to turn on again following a restart
1 Like

this is throwing me error:
Invalid config for [automation]: value should be a string for dictionary value @ data['condition'][0]['entity_id']. Got None. (See /config/configuration.yaml, line 102).

Well, 3 things : -

  1. It passes config check at my end,
  2. Look at what I gave you …
  3. Vs. What you posted back to me

Do you see any differences ?

Also we can’t see the rest of the automation so it’s difficult to see context
Now your yaml spacing is different to mine, it does ‘appear’ to be valid yaml (again, without context I can’t be 100% certain)
AND I am somewhat unfamiliar with the new ‘short-hand’ way of listing triggers, conditions and actions (you get into habits and it takes a while to accomodate new habits). So, I ‘may’ have got the syntax wrong. But the following is the way it ‘should’ have been written under 0.111.x : -

automation:
  - alias: Away
    trigger:
      - platform: state
        entity_id: 
          - device_tracker.life360_ajitha_krishna
          - device_tracker.life360_kamal_krishna
        from: 'home'
    condition:
      - condition: state
        entity_id: device_tracker.life360_ajitha_krishna
        state: 'not_home'
      - condition: state
        entity_id: device_tracker.life360_kamal_krishna
        state: 'not_home'
    action:
      - service: switch.turn_off
        entity_id: all
      - service: light.turn_off
        entity_id: all

Note that the condition are listed separately and because this is a default condition it is ‘and’ by default.
So you can go back and paste the whole of the suggested automation into place OR paste the older method (without the short-cut) and if you still get errors; you will need to post the whole of your automation back here.
You are also aware (?) that ‘lead in’ spacing is different according to where you have the automation as well aren’t you ? ie configuration.yaml has it one way (the same way as packages) whilst automation.yaml inherits the spacing from configuration.yaml and therefore it’s ‘different’
It’s just easier to copy the spacing from an existing working example THOUGH with multiple keys you need to list them with a preceeding dash (see and compare your original to either of mine).