Need an automation to trigger True if part of it has run

My vacuum runs every other day at 4pm, unless no one is home. This automation works perfectly.

However, I’d like to set it so that if it missed the 4pm start time because no one is home - that it send an actionable notification to our phones asking if it should start when we return home. I can handle the notification, but how do I do something like has_vacuum_run to True, then check that variable when we get home?

edit: And if it matters, I’d like to keep all this in a single automation, hence the defined trigger_id.

For reference, here’s the automation in its current state:

alias: "[Time] Run vacuum"
description: ""
trigger:
  - platform: time
    at: "16:00:00"
    id: run_vacuum
condition: []
action:
  - if:
      - condition: trigger
        id:
          - run_vacuum
      - condition: numeric_state
        entity_id: zone.home
        above: 0
      - condition: template
        value_template: "{{ ((now()|as_timestamp/86400)|int%2) == 0 }}"
    then:
      - service: mqtt.publish
        data:
          qos: 0
          retain: false
          topic: valetudo/roborock_s6/MapSegmentationCapability/clean/set
          payload: >-
            {"segment_ids":["17","16","19","24","22","23","21","18","20"],"iterations":1,"customOrder":true}
    else: []
mode: single

If anyone cares, this is what I ended up with. I created a Helper to store state. I really would rather it store that in the automation, but I couldn’t figure it out.

alias: "[Time] Run vacuum"
description: ""
trigger:
  - platform: time
    at: "16:00:00"
    id: run_vacuum
  - platform: time
    at: "00:00:00"
    id: reset_boolean
  - platform: zone
    entity_id: person.zac
    zone: zone.home
    event: enter
    id: zac-home
  - platform: zone
    entity_id: person.april
    zone: zone.home
    event: enter
    id: april-home
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: run_vacuum
    id: run_vacuum_now
condition: []
action:
  - if:
      - condition: trigger
        id:
          - run_vacuum
      - condition: numeric_state
        entity_id: zone.home
        above: 0
      - condition: template
        value_template: "{{ ((now()|as_timestamp/86400)|int%2) == 0 }}"
    then:
      - service: mqtt.publish
        data:
          qos: 0
          retain: false
          topic: valetudo/roborock_s6/MapSegmentationCapability/clean/set
          payload: >-
            {"segment_ids":["17","16","19","24","22","23","21","18","20"],"iterations":1,"customOrder":true}
    else:
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.no_vaccum_run
  - if:
      - condition: trigger
        id:
          - reset_boolean
    then:
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.no_vaccum_run
  - if:
      - condition: trigger
        id:
          - zac-home
          - april-home
    then:
      - service: notify.mobile_app_zac_s_phone
        data:
          message: I didn't run the vacuum while you were gone. Shall I now?
          data:
            actions:
              - action: run_vacuum
                title: Run vacuum
  - if:
      - condition: trigger
        id:
          - run_vacuum_now
      - condition: numeric_state
        entity_id: zone.home
        above: 0
    then:
      - service: mqtt.publish
        data:
          qos: 0
          retain: false
          topic: valetudo/roborock_s6/MapSegmentationCapability/clean/set
          payload: >-
            {"segment_ids":["17","16","19","24","22","23","21","18","20"],"iterations":1,"customOrder":true}
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.no_vaccum_run
    else: []
mode: single

Use an input_boolean helper.

After your publish to MQTT, set it to on.

In the else, set it to off.

input_boolean.turn_on or input_boolean.turn_off are the commands.

I hope I understood your request.

1 Like

Yeah, that’s exactly what I did. But IMHO, it really would be cleaner if it were all handled inside the automation.

Yeah. I saw our posts crossed.

I understand what you wanted. But, there are no persistent or global variables in HA. At least they gave us the helpers!

1 Like