Away Mode: Cancel by changing an entity state

Hey all!

I’m currently tweaking the automations for when Away mode is enabled. Currently it turns off all the lights, TV, heating etc. when Away mode = on.

However, there is some times that there is someone still in the house. Guests are already mostly covered (I detect the presence of guests by my guest wifi ssid and prevent the away mode) - but sometimes I leave my kids in the house and I don’t want it to be enabled then (or if the guest detection fails). Due to them leaving their phones at home on school days, presence detection based on device isn’t an option.

My idea was on the triggering of the Away automation, announce in the house it’s about to start, and watch for a state change in one of the lights. So if someone is in the house, give them like 5-10 mins to walk over and change the state of that light, and it will cancel the rest of the automation flow.

Problem is: I can’t figure out a way to cancel the actions based on the state change trigger. I have put in a “Wait for trigger” and then just watch the state of that light, but then I’m completely stuck on how to cancel the next steps if the state did change.

Any ideas welcome! Thanks - Jay.

Check the value of wait.trigger after the wait_for_trigger.

If its value is none then it means the wait_for_trigger never triggered but simply timed out. You can use that information to decide what the automation does next (if anything).

You can check if wait.trigger is none with an inline Template Condition (if the condition isn’t met then the automation terminates) or with a choose (if you need more flexibility for deciding what the automation does next)

Thanks Taras for the hint! I’ve had a go, but I can’t seem to find the proper syntax to build a Choose with those value templates…

Any chance you could point me in the right direction with an example?

Which one of the following two examples you should use depends on what you want the automation to do if wait_for_trigger times out. The first example simply exits the automation, the second example provides more flexibility to do additional things.

Example 1

Inline Template Condition checks if wait.trigger is not none.

  • If it’s not none, execution proceeds to the service call and reports success.
  • If it’s none, execution terminates immediately.
  - wait_for_trigger:
    - platform: state
      entity_id: light.whatever
      to: 'on'
    timeout: '00:05:00'
  - condition: template
    value_template: "{{ wait.trigger != none }}"
  - service: persistent_notification.create
    data:
      title: Light Status
      message: "Success: Turned on within 5 minutes."

Example 2

First conditions in choose checks if wait.trigger is none.

  • If it’s none, execution proceeds to the service call and reports failure.
  • If it’s not none, it proceeds to execute the service call in default and reports success.
  - wait_for_trigger:
    - platform: state
      entity_id: light.whatever
      to: 'on'
    timeout: '00:05:00'
  - choose:
    - conditions: "{{ wait.trigger == none }}"
      sequence:
      - service: persistent_notification.create
        data:
          title: Light Status
          message: "Failure: Timed out after 5 minutes."
    default:
    - service: persistent_notification.create
      data:
        title: Light Status
        message: "Success: Turned on within 5 minutes."
  - any actions placed here and will be executed after 'choose' is completed,
    regardless if 'wait.trigger' is 'none' or not
1 Like

Taras, you are an absolute hero! Thank you - working great now!!!

1 Like