Automation listening more than one trigger and possibly self triggering

Hi,
I try to control a circulation pump for hot water main pipe in my house.
I created a helper of type input_boolean and an automation. I also created a helper of type timer to limit the runtime of the pump if something wents wrong.
I measure the temperature at the end of the circulation pipe, so I know the point in time when the main pipe is filled with hot water.

This looks not that complicated, I thougt.

The automation gets 4 triggers, input off-on, input on-off, timer elaped and temperatur above limit.

When I have to switch the pump off, I have to switch my relay (Shelly plus 1) and cancle the timer.

If the timer elaped or the temperature limit is reached, I have to do the same; more or less, BUT I have also to switch the input_boolean off, otherwise it remains on and my UI shows the wrong state.

BUT when I do so, the event input_boolean on-off is fired and my automation (the same as the running one) is listening.

How to deal with this situations in HA correctly?

Is the current work done by the automation and after firing the next event a new cycle starts over, or works it totally different.

I have a solution, but get warnings in the log and some times it stucks.

Thanks for helping.

With best regards

Gerhard

Show the YAML code for the automation, correctly formatted; and also the logs.

Surround the code with three backticks:

```
code here
```

which should end up looking like this:

code here
id: '1708780275099'
alias: Zirkulation Pumpe with timeout
description: ''
trigger:
  - platform: state
    entity_id:
      - input_boolean.zirkulationspumpe_2
    id: Switch On
    to: 'on'
    from: 'off'
  - platform: state
    entity_id:
      - input_boolean.zirkulationspumpe_2
    to: 'off'
    id: Switch Off
    from: 'on'
  - platform: numeric_state
    entity_id:
      - sensor.shelly1_wwzirkulation_zirkulation_temp
    above: 26
    id: Steigleitung voll
    for:
      hours: 0
      minutes: 0
      seconds: 5
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.zirkulation_pumpe_timeout
    id: timer elapsed
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Switch On
        sequence:
          - if:
              - condition: numeric_state
                entity_id: sensor.shelly1_wwzirkulation_zirkulation_temp
                below: 22
              - condition: state
                entity_id: input_boolean.urlaubsmode
                state: 'off'
            then:
              - service: timer.start
                target:
                  entity_id: timer.zirkulation_pumpe_timeout
                data: {}
              - type: turn_on
                device_id: 5148ffbdfbf5a87f871c65ea0f3d6e40
                entity_id: 38d2bc0cff63e3486dc52831a62a3ced
                domain: switch
            else:
              - service: input_boolean.turn_off
                metadata: {}
                data: {}
                target:
                  entity_id: input_boolean.zirkulationspumpe_2
      - conditions:
          - condition: trigger
            id:
              - Switch Off
        sequence:
          - type: turn_off
            device_id: 5148ffbdfbf5a87f871c65ea0f3d6e40
            entity_id: 38d2bc0cff63e3486dc52831a62a3ced
            domain: switch
          - service: timer.cancel
            target:
              entity_id:
                - timer.zirkulation_pumpe_timeout
            data: {}
      - conditions:
          - condition: trigger
            id:
              - Steigleitung voll
          - condition: device
            type: is_on
            device_id: 5148ffbdfbf5a87f871c65ea0f3d6e40
            entity_id: 38d2bc0cff63e3486dc52831a62a3ced
            domain: switch
        sequence:
          - type: turn_off
            device_id: 5148ffbdfbf5a87f871c65ea0f3d6e40
            entity_id: 38d2bc0cff63e3486dc52831a62a3ced
            domain: switch
          - service: timer.cancel
            target:
              entity_id:
                - timer.zirkulation_pumpe_timeout
            data: {}
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.zirkulationspumpe_2
      - conditions:
          - condition: trigger
            id:
              - timer elapsed
        sequence:
          - type: turn_off
            device_id: 5148ffbdfbf5a87f871c65ea0f3d6e40
            entity_id: 38d2bc0cff63e3486dc52831a62a3ced
            domain: switch
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: input_boolean.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: input_boolean.zirkulationspumpe_2
    default:
      - type: turn_off
        device_id: 5148ffbdfbf5a87f871c65ea0f3d6e40
        entity_id: 38d2bc0cff63e3486dc52831a62a3ced
        domain: switch
      - service: input_boolean.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: input_boolean.zirkulationspumpe_2
mode: single

Triggered by the state of input_boolean.zirkulationspumpe_2 at 27. Februar 2024 um 14:48:41

Stopped because only a single execution is allowed at 27. Februar 2024 um 14:48:41 (runtime: 0.00 seconds)

Not all shown logbook entries might be related to this automation.

Hope this helps.
With best regards

Gerhard
Hope that helps

That’s a lengthy automation. Here’s my interpretation of it:

It triggers from:

  • input_boolean turning on
  • input_boolean turning off
  • temperature over 26 for 5 minutes
  • timer finishing

If triggered from input_boolean turning on:

  • if the temperature is below 22 and it’s not a holiday, start the timer and turn on the pump
  • otherwise, turn the input_boolean off (which will trigger the automation again!)

If triggered from input_boolean turning off:

  • turn off the pump
  • cancel the timer

If triggered by temperature, and the pump is on:

  • turn the pump off
  • cancel the timer
  • wait 1s
  • turn the input_boolean off (which will trigger the automation again!)

If triggered by the timer finishing:

  • turn the pump off
  • wait 1s
  • turn the input_boolean off (which will trigger the automation again!)

The default sequence (pump off, input_boolean off) should only be executed if you run the automation manually, and that will trigger another run if the input_boolean was on beforehand.

Read up on the automation modes, and see if any of those will help you:

You were more or less correct with yout interpretation.
The problem is:
How can I reflect the state of the pump in my UI (best with not directly refere the device).
My UI is ‘connected’ to the input_boolean’, and when the timer triggers the automation, the state of the input_boolean isn’t changed.

Thats a very basic pattern for automations, so how can I do this with HA?

With best regards

Gerhard

You refer to your pump switch with a device_id: does it have an entity ID, like switch.pumpe?

Hi Troon,
I know, but I want to seperate UI from automation (seperation of concerns, a golden rule).
Now I have set the automation mode to ‘queued’, that works out. I also could delete lot of duplicates! If the timer expires, it just switches the input_boolean to ‘off’, like I can do manual. And this puts an event in the queue to trigger the general ‘on-to-off’ actions (switch the pump off and cancle the timer).
UI follows all the states, looks fine now.
Thanks.
One problem remaining (as usual): In the history, the temperatures were logged, the pump status (relay in device) is logged but the timer and the input_booleean always stay in their idel states.
Not really that bad, config that for debugging, but …

With best regards

Gerhard