Issue with conditional automation - Condition not working as expected

Hi,
I’m setting up an automation to ensure my thermostat turns of when both myself and partner are out of home. Hence I use the zone for each of the defined persons as triggers, followed by a choose that assesses the current states.

alias: 'Environment - Turn off thermostat when away '
description: ''
trigger:
  - platform: state
    entity_id: person.me
    to: null
  - platform: state
    entity_id: person.partner
    to: null
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: not
                conditions:
                  - condition: zone
                    entity_id: person.me
                    zone: zone.home
              - condition: not
                conditions:
                  - condition: zone
                    entity_id: person.partner
                    zone: zone.home
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: 'off'
      - conditions:
          - condition: device
            device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: is_hvac_mode
            hvac_mode: 'off'
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: auto
    default: []
mode: single

However some debug traces and up in the default rather than to execute the action.

Last example:
I’m leaving home, while my partner was already away.

Hence I would expect my condition to trigger, as now both persons are not_home. However it ended up in the default.

Debug trace:

{
  "trace": {
    "last_step": "action/0/choose/1/conditions/0",
    "run_id": "7fdf4694a473902518a687d22bde659f",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-01-16T17:25:02.007482+00:00",
      "finish": "2022-01-16T17:25:02.041887+00:00"
    },
    "domain": "automation",
    "item_id": "1635889248367",
    "trigger": "state of person.me",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-01-16T17:25:02.007600+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.environment_turn_off_thermostat_when_away",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-01-16T02:46:06.127489+00:00",
                "mode": "single",
                "current": 0,
                "id": "1635889248367",
                "friendly_name": "Environment - Turn off thermostat when away "
              },
              "last_changed": "2022-01-13T16:45:26.117708+00:00",
              "last_updated": "2022-01-16T02:46:06.141476+00:00",
              "context": {
                "id": "4b870e6f00f2251e5062cefa6e4c2d09",
                "parent_id": "2fa0c3afa7759ae371fd98a6fe7dc738",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "state",
              "entity_id": "person.me",
              "from_state": {
                "entity_id": "person.me",
                "state": "home",
                "attributes": {
                  "editable": false,
                  "id": "me",
                  "latitude": <lat>,
                  "longitude": <long>,
                  "gps_accuracy": 60,
                  "source": "device_tracker.oneplus_8_pro",
                  "user_id": "e8f27a6f86424260a0a5c99eacad2714",
                  "friendly_name": "Thibault"
                },
                "last_changed": "2022-01-16T02:46:06.121219+00:00",
                "last_updated": "2022-01-16T17:24:04.620457+00:00",
                "context": {
                  "id": "1dd58049d6216a33b86b1c3301f7f227",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "person.me",
                "state": "not_home",
                "attributes": {
                  "editable": false,
                  "id": "me",
                  "latitude": <lat>,
                  "longitude": <long>,
                  "gps_accuracy": 10,
                  "source": "device_tracker.oneplus_8_pro",
                  "user_id": "e8f27a6f86424260a0a5c99eacad2714",
                  "friendly_name": "Thibault"
                },
                "last_changed": "2022-01-16T17:25:01.999095+00:00",
                "last_updated": "2022-01-16T17:25:01.999095+00:00",
                "context": {
                  "id": "8a4f452ecacef44dfa59678ebc0dce51",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of person.me"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-01-16T17:25:02.016142+00:00",
          "changed_variables": {
            "context": {
              "id": "8a53e50b727013832d0aac49c8b8e626",
              "parent_id": "8a4f452ecacef44dfa59678ebc0dce51",
              "user_id": null
            }
          },
          "result": {
            "choice": "default"
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2022-01-16T17:25:02.016378+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2022-01-16T17:25:02.016594+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0/conditions/0",
          "timestamp": "2022-01-16T17:25:02.016725+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/0/conditions/0/conditions/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0/conditions/0/conditions/0",
          "timestamp": "2022-01-16T17:25:02.016854+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0/conditions/1": [
        {
          "path": "action/0/choose/0/conditions/0/conditions/1",
          "timestamp": "2022-01-16T17:25:02.017302+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0/conditions/1/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0/conditions/1/conditions/0",
          "timestamp": "2022-01-16T17:25:02.017431+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/1": [
        {
          "path": "action/0/choose/1",
          "timestamp": "2022-01-16T17:25:02.017915+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0",
          "timestamp": "2022-01-16T17:25:02.018058+00:00",
          "result": {
            "result": false
          }
        }
      ]
    },
    "config": {
      "id": "1635889248367",
      "alias": "Environment - Turn off thermostat when away ",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "person.me",
          "to": null
        },
        {
          "platform": "state",
          "entity_id": "person.partner",
          "to": null
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "and",
                  "conditions": [
                    {
                      "condition": "not",
                      "conditions": [
                        {
                          "condition": "zone",
                          "entity_id": "person.me",
                          "zone": "zone.home"
                        }
                      ]
                    },
                    {
                      "condition": "not",
                      "conditions": [
                        {
                          "condition": "zone",
                          "entity_id": "person.partner",
                          "zone": "zone.home"
                        }
                      ]
                    }
                  ]
                }
              ],
              "sequence": [
                {
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "set_hvac_mode",
                  "hvac_mode": "off"
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "device",
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "is_hvac_mode",
                  "hvac_mode": "off"
                }
              ],
              "sequence": [
                {
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "set_hvac_mode",
                  "hvac_mode": "auto"
                }
              ]
            }
          ],
          "default": []
        }
      ],
      "mode": "single",
      "trace": {
        "stored_traces": 20
      }
    },
    "blueprint_inputs": null,
    "context": {
      "id": "8a53e50b727013832d0aac49c8b8e626",
      "parent_id": "8a4f452ecacef44dfa59678ebc0dce51",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Environment - Turn off thermostat when away ",
      "message": "has been triggered by state of person.me",
      "source": "state of person.me",
      "entity_id": "automation.environment_turn_off_thermostat_when_away",
      "context_id": "8a53e50b727013832d0aac49c8b8e626",
      "when": "2022-01-16T17:25:02.007862+00:00",
      "domain": "automation"
    }
  ]
}

Any idea why the condition didn’t execute ?

^^ Have a look at groups (and group behaviour).
That way you will probably make that part much easier. Ans possibly the whole automation.

I’ll take a look at that indeed to simplify the config. But it still does not explain why it does not evaluate properly…

Group question:

  • Should I use the group entity as a trigger of the individual states of the persons ?
  • If hte group is used, can I know within the automation which person triggered the automation ?

I think I’ll have the use the persons as trigger to be able to achieve what I’m looking for. While the group entitty would simply easy the config aspect. But I’d rather ask the question to confirm my understanding and use of groups.

#1 Yes. I would set trigger as group not_home

#2 I did not see that as a requirement from the yaml you posted. What is this going to be used for? Lets say you left home last, what is going to happen?

Indeed in the previous automation I didn’t bother because the persons were used as trigger. Hence in the debug traces I had the relevant evidence.

Here in your suggestion of working with the group, it may perfectly work, but during debug I would not know which person would have triggered the automation.
(as the phone of my partner can be flakky, I’m doing a bit of debug once in a while to keep optimizing my automation and finding appropriate/alternative triggers).

I would advice to use the companion apps wifi sensor (at least if you use Android, no experience of rotten fruit).
It never gives false readings.

But if you must use persons then I would probably use person as you have now in trigger, then as condition (not choose condition like you have now) I would add the group not_home.
That should give you trigger possibilities but also the “simplicity” of group as the condition to make sure the automation doesn’t trigger incorrectly.

Biggest problem on android is the fact the OS closes apps after a while for battery optimization.
Even changing those settings to turn off optimization, does not mean Android will not close the app anyway.
I’ve configured the phone of my partner properly, but sometime I still do not get any updates from the companion app. I’ve attempted to retain app open by adding a widget on her home screen, but still I get missing some updates from time to time.

I see…
A hacky way of doing it but perhaps you can automate a command message every hour to open the app?
Not sure it works, just thought of it.

But either way try the trigger and condition with group as I explained above, it should be an intermediate way.

I would advice to use the companion apps wifi sensor (at least if you use Android, no experience of rotten fruit).
It never gives false readings.

Regarding your recommendation to use Wifi Connection sensor as trigger… I just experienced the issue that my phone did not provide the update to HA when I connected to my home wifi… It properly detected I was home (I also use a widget to ensure app stays running).

But this time I actually had to open up the app on my phone. that seem to have triggered the delivery of the phone sensor states again and my automation proceeded.

So although the Wifi connection does not provide false readings, it may suffer some delay it seems

Have to disabled the battery optimization and allowed the app to run in background and while in sleep (or whatever the steps is that you should take according to the documentations)?

So a few days have passed and I tested the renewed automation config based on my new group as was suggested.

This is my new config:

alias: Test - group for residents at home
description: ''
trigger:
  - platform: state
    entity_id: group.residents_presence
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: group.residents_presence
            state: not_home
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: 'off'
          - service: notify.titi
            data:
              message: Turning of thermostat (all residents away)
      - conditions:
          - condition: device
            device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: is_hvac_mode
            hvac_mode: 'off'
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: auto
          - service: notify.titi
            data_template:
              message: >
                Not changing thermostat, already set to {{
                states('climate.smartthermostat') }}{{ '\n' -}}

                Triggered by: {{ trigger.entity_id }}
    default: []
mode: single

So even when I get home, instead of evaluating the second option in my choose section, it falls back to the default…
So it evaluates the first part, but then fails to continue, although the result of the first section is false

Any idea why the choose goes to default instead of executing properly the second case to evaluate?

{
  "trace": {
    "last_step": "action/0/choose/1/conditions/0/conditions/1",
    "run_id": "08f76886abe2e07b1c7ad3e47c75dc88",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-01-20T22:19:56.195913+00:00",
      "finish": "2022-01-20T22:19:56.214974+00:00"
    },
    "domain": "automation",
    "item_id": "1642412360704",
    "trigger": "state of group.residents_presence",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-01-20T22:19:56.196034+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.test_group_for_residents_at_home",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-01-20T18:59:08.174719+00:00",
                "mode": "single",
                "current": 0,
                "id": "1642412360704",
                "friendly_name": "Test - group for residents at home"
              },
              "last_changed": "2022-01-19T22:34:26.453163+00:00",
              "last_updated": "2022-01-20T18:59:08.196369+00:00",
              "context": {
                "id": "f5407aa1da4cb1f1365105bd58b9d911",
                "parent_id": "7b0a4a7c9020396f8e7a39bfc2d7533d",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "state",
              "entity_id": "group.residents_presence",
              "from_state": {
                "entity_id": "group.residents_presence",
                "state": "not_home",
                "attributes": {
                  "entity_id": [
                    "person.thibault",
                    "person.amaelle"
                  ],
                  "order": 0,
                  "friendly_name": "Presence of Residents at home"
                },
                "last_changed": "2022-01-20T18:59:08.168236+00:00",
                "last_updated": "2022-01-20T18:59:08.168236+00:00",
                "context": {
                  "id": "7b0a4a7c9020396f8e7a39bfc2d7533d",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "group.residents_presence",
                "state": "home",
                "attributes": {
                  "entity_id": [
                    "person.thibault",
                    "person.amaelle"
                  ],
                  "order": 0,
                  "friendly_name": "Presence of Residents at home"
                },
                "last_changed": "2022-01-20T22:19:56.186656+00:00",
                "last_updated": "2022-01-20T22:19:56.186656+00:00",
                "context": {
                  "id": "e108f1e08919bc14213651ce84ac76dd",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of group.residents_presence"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-01-20T22:19:56.198738+00:00",
          "changed_variables": {
            "context": {
              "id": "72ec768283bb96238e26a08a886dcdee",
              "parent_id": "e108f1e08919bc14213651ce84ac76dd",
              "user_id": null
            }
          },
          "result": {
            "choice": "default"
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2022-01-20T22:19:56.198973+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2022-01-20T22:19:56.199111+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/0/entity_id/0",
          "timestamp": "2022-01-20T22:19:56.199219+00:00",
          "result": {
            "result": false,
            "state": "home",
            "wanted_state": "not_home"
          }
        }
      ],
      "action/0/choose/1": [
        {
          "path": "action/0/choose/1",
          "timestamp": "2022-01-20T22:19:56.199515+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0",
          "timestamp": "2022-01-20T22:19:56.199641+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0/conditions/0",
          "timestamp": "2022-01-20T22:19:56.199746+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0/conditions/1": [
        {
          "path": "action/0/choose/1/conditions/0/conditions/1",
          "timestamp": "2022-01-20T22:19:56.199905+00:00",
          "result": {
            "result": false
          }
        }
      ]
    },
    "config": {
      "id": "1642412360704",
      "alias": "Test - group for residents at home",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "group.residents_presence"
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "group.residents_presence",
                  "state": "not_home"
                }
              ],
              "sequence": [
                {
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "set_hvac_mode",
                  "hvac_mode": "off"
                },
                {
                  "service": "notify.titi",
                  "data": {
                    "message": "Turning of thermostat (all residents away)"
                  }
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "or",
                  "conditions": [
                    {
                      "condition": "device",
                      "device_id": "180eb38900273f74617503ed50b01d89",
                      "domain": "climate",
                      "entity_id": "climate.smartthermostat",
                      "type": "is_hvac_mode",
                      "hvac_mode": "auto"
                    },
                    {
                      "condition": "device",
                      "device_id": "180eb38900273f74617503ed50b01d89",
                      "domain": "climate",
                      "entity_id": "climate.smartthermostat",
                      "type": "is_hvac_mode",
                      "hvac_mode": "heat"
                    }
                  ]
                }
              ],
              "sequence": [
                {
                  "service": "notify.titi",
                  "data_template": {
                    "message": "Not changing thermostat, already set to {{ states('climate.smartthermostat') }}{{ '\\n' -}}\nTriggered by: {{ trigger.entity_id }}\n"
                  }
                }
              ]
            }
          ],
          "default": []
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "72ec768283bb96238e26a08a886dcdee",
      "parent_id": "e108f1e08919bc14213651ce84ac76dd",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Test - group for residents at home",
      "message": "has been triggered by state of group.residents_presence",
      "source": "state of group.residents_presence",
      "entity_id": "automation.test_group_for_residents_at_home",
      "context_id": "72ec768283bb96238e26a08a886dcdee",
      "when": "2022-01-20T22:19:56.196303+00:00",
      "domain": "automation"
    }
  ]
}

That is not how you do it.

action:
  - choose:
      - conditions:
          - condition: state
            entity_id: group.residents_presence
            state: not_home
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: 'off'
          - service: notify.titi
            data:
              message: Turning of thermostat (all residents away)
    default: []
  - choose:
      - conditions:
          - condition: device
            device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: is_hvac_mode
            hvac_mode: 'off'
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: auto
          - service: notify.titi
            data_template:
              message: >
                Not changing thermostat, already set to {{
                states('climate.smartthermostat') }}{{ '\n' -}}

                Triggered by: {{ trigger.entity_id }}
    default: []

You need one choose per action, or the default has to be used with the “other” action.

At least that is what I think and use myself if I recall correctly

I’m not sure I agree with your approach… in a choose you can add options and each option will be evaluated. The default will execute if none of the options match…

What you suggest will simply add multiple choose in my automation…which kind of is the same as multiple if-elseif way of working, rather than a case statement…

see examples at: Script Syntax - Home Assistant

Perhaps…
But that is how I usually do it.

But that leaves the device condition.
Devices in conditions is notorious for not working.
Any way you could change that to a state based condition? Is there an entity which shows the HVAC state?

Issue persists, seems like a bug in evaluating the HVAC mode of the thermostat, which return false for the condition and therfore skipping it.

Trace where HVAC mode is set to OFF when leaving home:

{
  "trace": {
    "last_step": "action/0/choose/0/sequence/1",
    "run_id": "acf187509fc7eefac9724230a02ef6aa",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-01-22T10:15:47.992702+00:00",
      "finish": "2022-01-22T10:15:48.021363+00:00"
    },
    "domain": "automation",
    "item_id": "1642412360704",
    "trigger": "state of group.residents_presence",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-01-22T10:15:47.992828+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.test_group_for_residents_at_home",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-01-21T23:33:07.774006+00:00",
                "mode": "single",
                "current": 0,
                "id": "1642412360704",
                "friendly_name": "Test - group for residents at home"
              },
              "last_changed": "2022-01-21T11:23:58.885422+00:00",
              "last_updated": "2022-01-21T23:33:07.784065+00:00",
              "context": {
                "id": "8136d02a5a22dadfa00478159b4994fc",
                "parent_id": "fccf9319cd1e6c2bd25b7b8d9b577a9d",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "state",
              "entity_id": "group.residents_presence",
              "from_state": {
                "entity_id": "group.residents_presence",
                "state": "home",
                "attributes": {
                  "entity_id": [
                    "person.me",
                    "person.partner"
                  ],
                  "order": 0,
                  "friendly_name": "Presence of Residents at home"
                },
                "last_changed": "2022-01-21T23:33:07.762845+00:00",
                "last_updated": "2022-01-21T23:33:07.762845+00:00",
                "context": {
                  "id": "fccf9319cd1e6c2bd25b7b8d9b577a9d",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "group.residents_presence",
                "state": "not_home",
                "attributes": {
                  "entity_id": [
                    "person.me",
                    "person.partner"
                  ],
                  "order": 0,
                  "friendly_name": "Presence of Residents at home"
                },
                "last_changed": "2022-01-22T10:15:47.988096+00:00",
                "last_updated": "2022-01-22T10:15:47.988096+00:00",
                "context": {
                  "id": "0cfe580aea923366d826a075a7c3d819",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of group.residents_presence"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-01-22T10:15:47.993972+00:00",
          "changed_variables": {
            "context": {
              "id": "e01b1f99b758f3d4575e5418e1d4c84e",
              "parent_id": "0cfe580aea923366d826a075a7c3d819",
              "user_id": null
            }
          },
          "result": {
            "choice": 0
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2022-01-22T10:15:47.994110+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2022-01-22T10:15:47.994187+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/0/choose/0/conditions/0/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/0/entity_id/0",
          "timestamp": "2022-01-22T10:15:47.994245+00:00",
          "result": {
            "result": true,
            "state": "not_home",
            "wanted_state": "not_home"
          }
        }
      ],
      "action/0/choose/0/sequence/0": [
        {
          "path": "action/0/choose/0/sequence/0",
          "timestamp": "2022-01-22T10:15:47.997620+00:00"
        }
      ],
      "action/0/choose/0/sequence/1": [
        {
          "path": "action/0/choose/0/sequence/1",
          "timestamp": "2022-01-22T10:15:48.017550+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "titi",
              "service_data": {
                "message": "Turning of thermostat (all residents away)"
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "id": "1642412360704",
      "alias": "Test - group for residents at home",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "group.residents_presence"
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "group.residents_presence",
                  "state": "not_home"
                }
              ],
              "sequence": [
                {
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "set_hvac_mode",
                  "hvac_mode": "off"
                },
                {
                  "service": "notify.titi",
                  "data": {
                    "message": "Turning of thermostat (all residents away)"
                  }
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "device",
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "is_hvac_mode",
                  "hvac_mode": "off"
                }
              ],
              "sequence": [
                {
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "set_hvac_mode",
                  "hvac_mode": "auto"
                },
                {
                  "service": "notify.titi",
                  "data_template": {
                    "message": "Not changing thermostat, already set to {{ states('climate.smartthermostat') }}{{ '\\n' -}}\nTriggered by: {{ trigger.entity_id }}\n"
                  }
                }
              ]
            }
          ],
          "default": []
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "e01b1f99b758f3d4575e5418e1d4c84e",
      "parent_id": "0cfe580aea923366d826a075a7c3d819",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Test - group for residents at home",
      "message": "has been triggered by state of group.residents_presence",
      "source": "state of group.residents_presence",
      "entity_id": "automation.test_group_for_residents_at_home",
      "context_id": "e01b1f99b758f3d4575e5418e1d4c84e",
      "when": "2022-01-22T10:15:47.992995+00:00",
      "domain": "automation"
    },
    {
      "when": "2022-01-22T10:15:48.087799+00:00",
      "name": "SmartThermostat",
      "state": "off",
      "entity_id": "climate.smartthermostat",
      "context_entity_id": "automation.test_group_for_residents_at_home",
      "context_entity_id_name": "Test - group for residents at home",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Test - group for residents at home",
      "message": "turned off"
    },
    {
      "when": "2022-01-22T10:15:48.089167+00:00",
      "name": "Heating on",
      "state": "off",
      "entity_id": "binary_sensor.heat_on",
      "context_entity_id": "automation.test_group_for_residents_at_home",
      "context_entity_id_name": "Test - group for residents at home",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Test - group for residents at home",
      "message": "turned off"
    },
    {
      "when": "2022-01-22T10:15:48.089854+00:00",
      "name": "hvac_mode",
      "state": "off",
      "entity_id": "sensor.hvac_mode",
      "context_entity_id": "automation.test_group_for_residents_at_home",
      "context_entity_id_name": "Test - group for residents at home",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Test - group for residents at home",
      "message": "turned off"
    }
  ]
}

Trace where it fails to validate HVAC mode and goes to the default:

{
  "trace": {
    "last_step": "action/0/choose/1/conditions/0",
    "run_id": "8fa924bd03cb4000cd3f5a50c3258d0c",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-01-22T12:48:58.543454+00:00",
      "finish": "2022-01-22T12:48:58.571352+00:00"
    },
    "domain": "automation",
    "item_id": "1642412360704",
    "trigger": "state of group.residents_presence",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-01-22T12:48:58.543691+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.test_group_for_residents_at_home",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-01-22T10:15:47.993042+00:00",
                "mode": "single",
                "current": 0,
                "id": "1642412360704",
                "friendly_name": "Test - group for residents at home"
              },
              "last_changed": "2022-01-21T11:23:58.885422+00:00",
              "last_updated": "2022-01-22T10:15:48.020962+00:00",
              "context": {
                "id": "e01b1f99b758f3d4575e5418e1d4c84e",
                "parent_id": "0cfe580aea923366d826a075a7c3d819",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "state",
              "entity_id": "group.residents_presence",
              "from_state": {
                "entity_id": "group.residents_presence",
                "state": "not_home",
                "attributes": {
                  "entity_id": [
                    "person.me",
                    "person.partner"
                  ],
                  "order": 0,
                  "friendly_name": "Presence of Residents at home"
                },
                "last_changed": "2022-01-22T10:15:47.988096+00:00",
                "last_updated": "2022-01-22T10:15:47.988096+00:00",
                "context": {
                  "id": "0cfe580aea923366d826a075a7c3d819",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "group.residents_presence",
                "state": "home",
                "attributes": {
                  "entity_id": [
                    "person.me",
                    "person.partner"
                  ],
                  "order": 0,
                  "friendly_name": "Presence of Residents at home"
                },
                "last_changed": "2022-01-22T12:48:58.526008+00:00",
                "last_updated": "2022-01-22T12:48:58.526008+00:00",
                "context": {
                  "id": "c1d23a235e4c1a9c6a5709f8b1a7ab49",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of group.residents_presence"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-01-22T12:48:58.547246+00:00",
          "changed_variables": {
            "context": {
              "id": "c3ba851634aacf97f7eea045c35d54af",
              "parent_id": "c1d23a235e4c1a9c6a5709f8b1a7ab49",
              "user_id": null
            }
          },
          "result": {
            "choice": "default"
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2022-01-22T12:48:58.547542+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2022-01-22T12:48:58.547721+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/0/entity_id/0",
          "timestamp": "2022-01-22T12:48:58.547865+00:00",
          "result": {
            "result": false,
            "state": "home",
            "wanted_state": "not_home"
          }
        }
      ],
      "action/0/choose/1": [
        {
          "path": "action/0/choose/1",
          "timestamp": "2022-01-22T12:48:58.548260+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/1/conditions/0": [
        {
          "path": "action/0/choose/1/conditions/0",
          "timestamp": "2022-01-22T12:48:58.548425+00:00",
          "result": {
            "result": false
          }
        }
      ]
    },
    "config": {
      "id": "1642412360704",
      "alias": "Test - group for residents at home",
      "description": "",
      "trigger": [
        {
          "platform": "state",
          "entity_id": "group.residents_presence"
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "group.residents_presence",
                  "state": "not_home"
                }
              ],
              "sequence": [
                {
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "set_hvac_mode",
                  "hvac_mode": "off"
                },
                {
                  "service": "notify.titi",
                  "data": {
                    "message": "Turning of thermostat (all residents away)"
                  }
                }
              ]
            },
            {
              "conditions": [
                {
                  "condition": "device",
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "is_hvac_mode",
                  "hvac_mode": "off"
                }
              ],
              "sequence": [
                {
                  "device_id": "180eb38900273f74617503ed50b01d89",
                  "domain": "climate",
                  "entity_id": "climate.smartthermostat",
                  "type": "set_hvac_mode",
                  "hvac_mode": "auto"
                },
                {
                  "service": "notify.titi",
                  "data_template": {
                    "message": "Not changing thermostat, already set to {{ states('climate.smartthermostat') }}{{ '\\n' -}}\nTriggered by: {{ trigger.entity_id }}\n"
                  }
                }
              ]
            }
          ],
          "default": []
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "c3ba851634aacf97f7eea045c35d54af",
      "parent_id": "c1d23a235e4c1a9c6a5709f8b1a7ab49",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Test - group for residents at home",
      "message": "has been triggered by state of group.residents_presence",
      "source": "state of group.residents_presence",
      "entity_id": "automation.test_group_for_residents_at_home",
      "context_id": "c3ba851634aacf97f7eea045c35d54af",
      "when": "2022-01-22T12:48:58.544045+00:00",
      "domain": "automation"
    }
  ]
}

Is this with state or device in the condition?

Try it with a state condition instead of device condition… Device triggers and conditions can be finicky.

data_template has been deprecated in most (if not all) integrations, just use data

alias: Test - group for residents at home
description: ''
trigger:
  - platform: state
    entity_id: group.residents_presence
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: group.residents_presence
            state: not_home
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: 'off'
          - service: notify.titi
            data:
              message: Turning off thermostat (all residents away)
      - conditions:
          - condition: state
            entity_id: climate.smartthermostat
            attribute: hvac_mode
            state: 'off'
        sequence:
          - device_id: 180eb38900273f74617503ed50b01d89
            domain: climate
            entity_id: climate.smartthermostat
            type: set_hvac_mode
            hvac_mode: auto
          - service: notify.titi
            data:
              message: >
                Not changing thermostat, already set to {{
                states('climate.smartthermostat') }}{{ '\n' }}
                Triggered by: {{ trigger.entity_id }}
    default: []
mode: single

Thanks for the recommendation. I’ll run some tests with those changes.

But if those device triggers/conditions are finicky, should those not be deprecated and rely on state conditions only?
Through GUI those are very easy to set up, but no warning is given with regards to its stability :sweat_smile:

Device triggers are a (relatively) new addition meant to make it easier for new users to get started creating automations in the GUI. There may still be some wrinkles for the devs to iron out…

If you are able to identify that the device trigger isn’t working properly for your situation, you should open an issue on the github page to bring it to the attention of people who may be able to fix the underlying issue.

glad it isn’t me :slight_smile:
i just set up an automation to shut the lights if no one is home.
But if it is “donker” then activate scene away.
didnt work with condition.
rebuild it with “action” “if” and now it works flawless.
didn’t understand why but if “conditions” are buggy then i understand and keep away from these.
thanks.

b.t.w, i have trackers on myself and girlfriend and made an extra person somebody with bothe my trackers and girlfriend trackers. that way i avoid groups and stil cab see who triggerd the automation.