I need help with an automation logic

I have a washer automation that checks if anybody is home to notify them that the washer is done
I have it coded in a template that look for our device trackers states.
If I am home = notify me
If my wife is home = notify my wife
if we are both home = notify us both
the one I am struggling with is if we both are not home, the automation still triggers but since it doesn’t know who to notify since both of us are NOT home it fails and stops.
Is there a way to have it hold on to the notify service until at least one of us show up at home and then run the action template?

here is the notify template

alias: Send alert when Washing Machine is  finished
description: ''
trigger:
  - platform: state
    entity_id: sensor.washing_machine_status
    from: Washing
    to: Idle
    for:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
condition: []
action:
  - service: >
      {% if is_state('device_tracker.iphone_12_pro_max', 'home') and
      is_state('device_tracker.danas_iphone', 'home') %}
        notify.tarik_and_dana
      {% elif is_state('device_tracker.danas_iphone', 'home') %}
        notify.dana
      {% elif is_state('device_tracker.iphone_12_pro_max', 'home') %}
        notify.tarik
      {% else %} notify.dana {% endif %}
    data:
      message: The washer is finished! Make sure to move clothes to the Dryer
  - service: notify.alexa_media_laundry
    data:
      message: >-
        The Washer is finished! Please make sure to move the clothes to the
        Dryer as soon as possible
      data:
        type: announce
        method: tts
  {% if is_state('device_tracker.iphone_12_pro_max', 'home') and
  is_state('device_tracker.danas_iphone', 'home') %}
    notify.tarik_and_dana
  {% elif is_state('device_tracker.danas_iphone', 'home') %}
    notify.dana
  {% elif is_state('device_tracker.iphone_12_pro_max', 'home') %}
    notify.tarik
  {% else %}
     do something - send e-mail / delay / turn on wash room light
  {% endif %}

I’m not aware of any built in way to do this. However, you could set a helper boolean if nobody is home. Then, have another automation that checks if that boolean is set when someone gets home and notifies them if so.

it’s hard to know since you only posted part of the automation…

but you could use one (or both) of the device trackers going to “home” as a trigger for the automation.

then in the conditions check that the washer is done (however you have accomplished that - again without any more info it’s hard to give any concrete advice) before you run the notification action.

Updated op with whole automation. I am using washer status sensor to change it to idle when a sonoff s31 drops below a certain power and then the input_ washer _ boolean trigger the alert when its set to idle

where does that boolean get set?

I think you perhaps should write this automation in a different way, but you could put a wait for trigger after the main sequence and then run the sequence again. Just put a small delay in the “no one home” option.

wait_for_trigger:
  - platform: state
    entity_id: person.self
    to: home
  - platform: state
    entity_id: person.wife
    to: home
1 Like

Oh, good idea, I forgot about wait_for_trigger. So, the action sequence could just be something like the following:

action:
  - choose:
    - alias: "If nobody is home, wait"
      conditions:
        - condition: state
          entity_id:
            - device_tracker.danas_iphone
            - device_tracker.iphone_12_pro_max
          state: not_home
      sequence:
        - wait_for_trigger:
          - platform: state
            entity_id:
              - device_tracker.danas_iphone
              - device_tracker.iphone_12_pro_max
            to: home
  - service: >-
      {% if is_state('device_tracker.iphone_12_pro_max', 'home') and
      is_state('device_tracker.danas_iphone', 'home') %}
        notify.tarik_and_dana
      {% elif is_state('device_tracker.danas_iphone', 'home') %}
        notify.dana
      {% elif is_state('device_tracker.iphone_12_pro_max', 'home') %}
        notify.tarik
      {% endif %}
    data:
      message: The washer is finished! Make sure to move clothes to the Dryer
  - service: notify.alexa_media_laundry
    data:
      message: >-
        The Washer is finished! Please make sure to move the clothes to the
        Dryer as soon as possible
      data:
        type: announce
        method: tts
2 Likes

This sounds good. Is that used as a condition or action?

This might work. I am gonna try it out after work

Nice! One small tweak to recommend. In the “nobody home” leg of the choose block, put the wait for trigger. In the default leg, put just a delay of one second, and then put all of the notifying etc. after the choose block. That way the action templates don’t need to be reproduced.

1 Like

something like this?

  - choose:
    - conditions:
      - condition: state
        entity_id: device_tracker.iphone_12_pro_max
        state: not_home
      - condition: and
        conditions:
        - condition: state
          entity_id: device_tracker.danas_iphone
          state: not_home
      sequence:
      - wait_for_trigger:
        - platform: state
          entity_id: device_tracker.danas_iphone
          to: Home
          for:
            hours: 0
            minutes: 5
            seconds: 0
            milliseconds: 0
        - platform: state
          entity_id: device_tracker.iphone_12_pro_max
          to: Home
          for:
            hours: 0
            minutes: 5
            seconds: 0
            milliseconds: 0
        continue_on_timeout: false
    default:
    - delay:
        hours: 0
        minutes: 0
        seconds: 1
        milliseconds: 0
1 Like

I may be forgetting the form that choose needs to be in, but, is that not what I wrote? The choose sequence is only entered if nobody is home. Otherwise, the condition isn’t met and the sequence proceeds on to notify. No need for template reproduction. Unless you’re saying to just have the choose define every action, since the templates are basically reproducing a choose.

Also, not sure what the default delay of one second is for.

If you like it like that, that’s fine, but it’s personally easier for me to read in the form I used:

condition:
  condition: state
  entity_id:
    - device_tracker.danas_iphone
    - device_tracker.iphone_12_pro_max
  state: not_home

If you want to use those and conditions instead, yours are a bit malformed:

condition:
  alias: "Paulus home AND temperature below 20"
  condition: and
  conditions:
    - condition: state
      entity_id: "device_tracker.paulus"
      state: "home"
    - condition: numeric_state
      entity_id: "sensor.temperature"
      below: 20

I’m also curious what @Dolores will say the delay is for.

You’re certainly on the right track, especially after those few points are acknowledged!

EDIT: Oh, I also think states are case-sensitive, so you’ll probably want to use home instead of Home.

1 Like

EDIT: my response is bogus as indicated by r-j-taylor below. I’ve deleted it.

1 Like

In the first example of the documentation for choose, no default is provided. I’ve also personally used choose without default.

1 Like

no worries man lol That’s how we learn

How does this look @r-j-taylor ?

  - conditions:
      - condition: state
        entity_id:
          - device_tracker.iphone_12_pro_max
          - device_tracker.danas_iphone
        state: not_home
    sequence:
      - wait_for_trigger:
          - platform: state
            entity_id:
              - device_tracker.danas_iphone
              - device_tracker.iphone_12_pro_max
            to: home
            for:
              hours: 0
              minutes: 5
              seconds: 0
              milliseconds: 0
        continue_on_timeout: false```

then run the service action after this

Only thing would be that five minute time out. That means that, unless either of you get home within five minutes of the trigger, you won’t be notified. If that’s the behavior that you want, then it should be fine!

My original statement was incorrect, please ignore.

oh shoot, I meant for it to be 5 minutes after we get home and device trackers switch to home because we might not hear the tts announcement if it’s instant