Problem with automation for turning thermostat off when we are all away from home


alias: Thermostat off when gone
description: ""
trigger:
 - platform: device
   device_id: 
   domain: device_tracker
   entity_id: 
   type: leaves
   zone: zone.home
 - platform: device
   device_id: 
   domain: device_tracker
   entity_id: 
   type: leaves
   zone: zone.home
 - platform: device
   device_id: 
   domain: device_tracker
   entity_id: 
   type: leaves
   zone: zone.home
condition:
 - condition: and
   conditions:
     - condition: device
       device_id: 
       domain: device_tracker
       entity_id: 
       type: is_not_home
     - condition: device
       device_id: 
       domain: device_tracker
       entity_id: 
       type: is_not_home
     - condition: device
       device_id: 
       domain: device_tracker
       entity_id: 
       type: is_not_home
action:
 - device_id: 
   domain: climate
   entity_id: 
   type: set_hvac_mode
   hvac_mode: "off"
 - device_id: 
   domain: mobile_app
   type: notify
   message: Nobody is home, Thermostat is disabled!
mode: single

for some reason its not triggering the check if any of us are home so when one of us leaves it turns the thermostat off. What am I doing wrong here?

Is ‘is_not_home’ real? Is it really ‘away’?

You could also check state of zone.home for 0. Right?

I posted this as the yaml but I used the visual editor to make it so that is how it was coded using the “condition: and”

I tried making another automation to test using “State = 0 persons” as the trigger and ran it and it still did the task even though my phone is home (as confirmed by looking at HA to verify the GPS is correctly showing that I am home)

If you associate these trackers with person entities:

Then you can simplify your triggers and conditions to:

alias: Thermostat off when gone
description: ""
trigger:
 - platform: state
   entity_id: zone.home
   to: 0
action:
 - device_id: 
   domain: climate
   entity_id: 
   type: set_hvac_mode
   hvac_mode: "off"
 - device_id: 
   domain: mobile_app
   type: notify
   message: Nobody is home, Thermostat is disabled!
mode: single

The state of the zone is the count of the number of people (not trackers) in it. So when it goes to 0 there is no one home and so disables your thermostat.

Also some friendly advice: Why and how to avoid device_ids in automations and scripts

1 Like

person:
  - name: x
    id: 
    device_trackers:
      - device_tracker.
  - name: x
    id: 
    device_trackers:
      - device_tracker.
  - name: x
    id: 
    device_trackers:
      - device_tracker.

I added this to my configurations.yaml and refreshed


alias: testing away with lights
description: ""
trigger:
  - platform: state
    entity_id:
      - zone.home
    attribute: persons
    to: "0"
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.light_1
        - light.light_2
mode: single

tried this automation and still had the action completed even though I’m home

What do you mean by:

If you run it manually it will always run the actions.

If you set the trigger correctly:

trigger:
  - platform: state
    entity_id:
      - zone.home
    to: "0"

It will only trigger when you all leave.

1 Like

That must be my problem now then! I didn’t realize when I manually run the action it would be completed regardless I assumed it would run, recognize I was home and cease the action from being completed.

So I will switch over my automations now using this and see what happens later when the house is empty and report back. Thank you!

Yeah manually running an automation only tests the actions, not the triggers or conditions.

You can test the conditions as well as the actions (but still not triggers) by using the automation.trigger service in Developer Tools → Services and setting the skip conditions option to false:

service: automation.trigger
target:
  entity_id: automation.foobar
data:
  skip_condition: false

So testing your original automation that way should have prevented the actions running.

Okay so I’ve left my home and the automation now isn’t firing at all despite the house being empty

Your trigger is still incorrect. Should be:

trigger:
  - platform: state
    entity_id:
      - zone.home
    to: 0

Not:

  - platform: state
    entity_id:
      - zone.home
    attribute: persons
    to: "0"

Look in developer tools → states. What is the value of the attribute “persons”.


alias: Nobody home everything off
description: ""
trigger:
  - platform: state
    entity_id:
      - zone.home
    to: "0"
condition: []
action:
  - service: light.turn_off
    target:
      entity_id:
        - light.light_1
        - light.light_2
        - light.elliotts_light
        - light.hallway_light
        - light.kitchen_1
        - light.kitchen_2
        - light.guest_room_1
        - light.guest_room_2
        - light.living_room_light_1
        - light.living_room_light_2
        - light.living_room_light_3
        - light.dreamview_t1
    data: {}
  - service: fan.turn_off
    data: {}
    target:
      entity_id: fan.sonoff_10017100af
  - service: camera.enable_motion_detection
    data: {}
    target:
      entity_id: camera.doorbell
  - service: switch.turn_off
    target:
      entity_id:
        - switch.makeup_station_socket_1
        - switch.living_room_socket_1
        - switch.everything_socket_1
        - switch.stinks_tv_socket_1
        - switch.upstairs_computer_socket_1
        - switch.fan_socket_1
    data: {}
  - service: climate.turn_off
    data: {}
    target:
      entity_id: climate.thermostat
  - service: media_player.turn_off
    data: {}
    target:
      entity_id:
        - media_player.bedroom_tv_2
        - media_player.living_room
  - service: notify.mobile_app_1s_iphone
    data:
      message: Everything is off!
mode: single

I believe this is correct? I followed the instructions on the pages you sent. Hoping this one works!

I checked what was defined as “person” and we are all listed as I put them in the config.yaml so I suppose that worked.

I think I figured it out! Turns out I have TWO entities for myself?
IMG_3973

It looks like my phone as well as my computer are registered as entities. Is there any way that I can set it to ignore every entity except for me, my dad and my wife?

Or is there a way to remove/exclude this entity from all automations/zones?

Just delete person_2

1 Like

Jekyll and Hyde

1 Like