Adding a verification step to ensure that an automation has fired correctly

Hello,

I have a few automations to control many devices in my home, like lights, heaters and a fireplace valve. I wanted to know if there was a way to check, post automation action, if the action succeeded? For example, this morning, I noticed that my fireplace was still off, even though the automation ran successfully at 5 AM; this is a random occurrence since it has worked 95% of the time since I programmed it.

Basically, I want the action to run, and then have HA check the state of the device a few seconds later to ensure it worked; if not, run the action again until it works. I thought of creating a new automation that listens for the first automation running successfully and then runs.

This is my current automation:

alias: Fireplace On
description: ''
trigger:
  - platform: time
    at: '05:00:00'
  - platform: state
    entity_id: group.family
    from: not_home
    to: home
  - platform: numeric_state
    entity_id: sensor.openweatherdetailed_temperature
    below: '2'
condition:
  - condition: numeric_state
    entity_id: sensor.openweatherdetailed_temperature
    below: '2'
  - condition: state
    entity_id: group.family
    state: home
  - condition: time
    after: '04:59:00'
    before: '21:31:00'
  - condition: state
    entity_id: climate.fireplace
    state: 'off'
action:
  - device_id: 3a934fde44e100dbab83f72180951938
    domain: climate
    entity_id: climate.fireplace
    type: set_hvac_mode
    hvac_mode: heat_cool
mode: single

Is this something that templates would allow me to do? If so, I’d like some guidance!

Thanks!

Ricky

This will try the action every two seconds, until the state changes or it has tried 15 times.

action:
  - repeat:
      sequence:
        - device_id: 3a934fde44e100dbab83f72180951938
          domain: climate
          entity_id: climate.fireplace
          type: set_hvac_mode
          hvac_mode: heat_cool
        - delay: 2
      until:
      - condition: or
        conditions:
        - "{{ repeat.index >= 15 }}"
        - "{{ is_state_attr('climate.fireplace', 'hvac_mode', 'heat_cool') }}"
1 Like

Will give it a try! Thanks so much

Worked like a charm!

Screenshot_20211124-072533|236x499

1 Like

Bumping this thread. I would like for HA to send me a mobile notification (to be added once I solve the below problem) if/when the action fails after 20 attempts. I have created a few counters for my different automations and I am calling them as an “until” condition. The part I can’t figure out is how to create a follow-up action if the counter hits 20 (aside from creating a subsequent automation to listen for the counter to hit 20, send the notification and then reset the counter to 0):

alias: Fireplace On
description: ''
trigger:
  - platform: time
    at: '05:00:00'
  - platform: state
    entity_id: group.family
    from: not_home
    to: home
  - platform: numeric_state
    entity_id: sensor.openweatherdetailed_temperature
    below: '2'
condition:
  - condition: numeric_state
    entity_id: sensor.openweatherdetailed_temperature
    below: '2'
  - condition: state
    entity_id: group.family
    state: home
  - condition: time
    after: '04:59:00'
    before: '21:31:00'
action:
  - repeat:
      until:
        - condition: state
          entity_id: climate.fireplace
          state: heat_cool
        - condition: state
          entity_id: counter.fireplace_on
          state: '20'
      sequence:
        - service: counter.increment
          target:
            entity_id: counter.fireplace_on
        - device_id: 3a934fde44e100dbab83f72180951938
          domain: climate
          entity_id: climate.fireplace
          type: set_hvac_mode
          hvac_mode: heat_cool
        - delay:
            hours: 0
            minutes: 0
            seconds: 5
            milliseconds: 0
mode: single

Since the original topic has been marked as solved, you’d be better off creating a new topic instead.

However, you can solve this new problem with a choose after the repeat. If your counter has a state of 20, send a notification.

Thanks a million!