Automation trouble, sometimes that is

I have a automation that triggers on button hold and the second trigger in the automation is on the release of that button. But for some reason the release trigger sometimes does not work.

alias: 1e badkamer ventilator
id: '1e_badkamer_ventilator'
trigger:
  - platform: state
    entity_id: binary_sensor.1e_badkamer_warm_water
    to: "off"
  - platform: event
    event_type: deconz_event
    event_data:
      id: 1e_badkamer_dimmer
      event: 4001
action:
  - service: switch.turn_on
    entity_id: switch.1e_badkamer_ventilator
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.1e_badkamer_warm_water
        from: "off"
        to: "on"
      - platform: event
        event_type: deconz_event
        event_data:
          id: 1e_badkamer_dimmer
          event: 4003
  - delay: "00:05:00"
  - service: switch.turn_off
    data:
      entity_id: switch.1e_badkamer_ventilator
mode: restart

How can I change this automation so it always works? Together with the other triggers… Thanks in advance.

Have you tried it with two separate automations?

The delay of 5 minutes and the restart mode makes so that if you re-press the button within 5 min of releasing it, the ventilator won’t stop.
I assume it is as you want it?

I wouldn’t know how to split this up and make it work with the two initial triggers.

No, I was under the impression that the “restart” mode made it so that the timer would restart and a new 5 min would start counting. The sensor part works great. The part triggered with the button does not (at least not every time)

No. “restart” re-execute the full automation when it’s re-triggered while still being executed.
What are you expected results, exactly?

Then the explanation in the documentation is not really clear on that.

I want the fan to turn on if one of the initial triggers get triggered. And the timer to restart when one of the initial triggers get triggered again within those 5 min. Also the timer should start only when the sensor has toggled to it’s original position. (the sensor is a modified contact sensor with a temp sensor to the warm water inlet of the shower)

To make it more clear how I intend to have it all I’ve made a flowchart of the whole thing:

My last effort was working flawlessly with my test sensor, test switch and test button and a 5 sec timer. But now that I set it up for the real deal after even one day it failed to turn off the fan switch. Please I really love some help as I am really desperate for answers.

alias: 1e badkamer ventilator aan en uit
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.1e_badkamer_warm_water
    id: warm_water
  - device_id: 9c05bef1cd794483a2fd923ad772d2aa
    domain: deconz
    platform: device
    type: remote_button_long_press
    subtype: turn_off
    id: button_press
condition: []
action:
  - type: turn_on
    device_id: b3e8ea8642f0619b4bc2073a52b4107c
    entity_id: switch.1e_badkamer_ventilator
    domain: switch
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.1e_badkamer_warm_water
            state: 'on'
        sequence:
          - service: timer.start
            data:
              duration: '00:05:00'
            target:
              entity_id: timer.badkamer_ventilator_timer
          - wait_for_trigger:
              - platform: state
                entity_id: timer.badkamer_ventilator_timer
                to: idle
          - type: turn_off
            device_id: b3e8ea8642f0619b4bc2073a52b4107c
            entity_id: switch.1e_badkamer_ventilator
            domain: switch
    default: []
mode: single

Have you examined the automation’s trace to see what it is doing when it fails to turn off the fan switch?

Next time I will try that. The problem is that is always occurs when I don’t have the time to debug. Hope I have the time next time it occurs.

Ok, This morning it failed. But by the time I got to my computer I had already more then the 5 history states so the failed timeline had disappeared. Can I prolong the history states so I can see more then 5?

Yes:

automation:
  - alias: "Automation Name"
    trace:
      stored_traces: 10
    trigger:
      - platform: ...

EDIT: The doc is currently wrong. It should be trace: