Please help debug automation with timed trigger that does not always work with Shelly 1 ( Tasmota )

Hi all! I’m experiencing this issue that I’ve really tried to debug for quite some time now, but I can’t figure out what is going wrong :frowning:

Please let me try to give a tldr of my issue. Details will follow :slight_smile:
I have a Shelly 1 that has been flashed with Tasmota controlling my bathroom fan. Then there’s an automation that will turn off the fan if it has been on for more than 20 minutes. The issue is that the fan sometimes will just stay on after 20 minutes has passed, but most often the automation works and turns off the fan.

More details:
What I would like my automations to achieve in a perfect world:

  • If the humidity in the bathroom rises above 70% the fan should turn on
  • If the humidity in the bathroom falls below 55% and the fan was turned automatically as a result of high humidity, the fan should turn off
  • The fan should not turn off when humidity falls below 55% if it was turned on manually ( not from an automation )
  • Regardless of how the fan was turned on, it should turn off automatically after 20 minutes.
    ( If the humidity levels triggered the fan on and has not fallen below my target after 20 minutes, I expect my auto-on automation to just turn on the fan again )

Yesterday this issue happened and I checked the “debug automation” thing in the GUI and saw that the automation had seemingly run successfully, but the fan was still on and there were no indications at all that the fan had been turned off at any point… In a bullet list what happened yesterday just in case:

  • The fan was turned on manually using the wall switch
  • After 20 minutes the fan was still running
  • I checked Debug automation in my app and saw that the automation had executed successfully after the fan had been turned on for 20 minutes.
  • I then checked the fan state and input_boolen state and could not see any indication of them being toggled or turned off.

I’ve also previously tried to have a boolean sensor that turns on after my fan timeout of 20 minutes and use that sensor as the trigger in my automation. This did not solve my problem.

Hardware / Software:

  • My “switch” is a Shelly 1 flashed with Tasmota ( previously had issues with the Shelly suddenly disconnecting - Tasmota fixed this )
  • Humidity sensor is the Aqara one.
  • Running HA in a docker container currently at version 2021.11.1, but I’ve always had this issue.

Please let me know what more information I can give you to help debug this! :slight_smile:

My automations:
All the automations have been created using the GUI, hence the “not-so-tidy” YAML.

Side-note; The part of the automations that turns the fan off automatically if the humidity falls below 55% has been added very recently. My issue was present before this addition, and is still present after.

Auto-start the fan:

alias: Bathroom Fan Auto-On
description: Turn on the bathroom fan if the humidity rises above 70% and the fan is off
trigger:
  - type: humidity
    platform: device
    device_id: 81ed3b395ca2560fecd8adaa8c4bd782
    entity_id: sensor.bathroom_humidity
    domain: sensor
    above: 70
condition:
  - condition: device
    type: is_off
    device_id: d51577c92ae65b547bcfd90c20f48f74
    entity_id: switch.tasmota
    domain: switch
action:
  - type: turn_on
    device_id: d51577c92ae65b547bcfd90c20f48f74
    entity_id: switch.tasmota
    domain: switch
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.bathroom_fan_automatic_on
mode: single
max: 10

Auto-off the fan:

alias: Bathroom Fan Auto-Off
description: Turns off the Bathroom fan if left on for a given time period
trigger:
  - platform: state
    to: 'on'
    id: bathroom_auto_off_1
    entity_id: switch.tasmota
    from: 'off'
    for:
      hours: 0
      minutes: 20
      seconds: 0
      milliseconds: 0
  - type: humidity
    platform: device
    device_id: 81ed3b395ca2560fecd8adaa8c4bd782
    entity_id: sensor.bathroom_humidity
    domain: sensor
    below: 55
    id: bathroom_auto_off_2
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: bathroom_auto_off_2
          - condition: state
            entity_id: input_boolean.bathroom_fan_automatic_on
            state: 'on'
        sequence:
          - type: turn_off
            device_id: d51577c92ae65b547bcfd90c20f48f74
            entity_id: switch.tasmota
            domain: switch
      - conditions:
          - condition: trigger
            id: bathroom_auto_off_1
        sequence:
          - type: turn_off
            device_id: d51577c92ae65b547bcfd90c20f48f74
            entity_id: switch.tasmota
            domain: switch
    default: []
mode: single

Helper automation:

alias: Bathroom Fan Reset input_boolean
description: Ensure Auto-On input_boolean is set to 'off' when Bathroom Fan is turned off
trigger:
  - platform: device
    type: turned_off
    device_id: d51577c92ae65b547bcfd90c20f48f74
    entity_id: switch.tasmota
    domain: switch
condition: []
action:
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.bathroom_fan_automatic_on
mode: single