Why does my choose condition block not work?

I’m trying to set up an automation that activates “boost mode” on my ventilation system when the bathroom humidity goes above a certain level. Within the same automation I also want to turn boost mode off if humidity falls below another lever, and I want a button to force boost off - in case the user is in the bath and don’t want to listen to the ventilation right now. :slight_smile:

However, I can’t get this to work. No matter which trigger I activate, the button or the humidity sensors, no action is performed. The trace is always “Choose: No action executed”

Can you see what I’m doing wrong?

(the actions work; switch.ftx_boost can turn_on and turn_off correctly when I run them manually.)

alias: Ventilation Control - Bathroom Humidity
description: Manage boost mode on the ventilation system in response to bathroom humidity and manual override.
trigger:
  # Trigger for high humidity to turn on boost
  - platform: device
    device_id: 342d6a8703e4223f16fee46888880014
    entity_id: sensor.7adcffd4d7e5aef6880d7b76eedc4d9e
    domain: sensor
    type: humidity
    above: 75
    for:
      hours: 0
      minutes: 1
      seconds: 0

  # Trigger for low humidity to turn off boost
  - platform: device
    device_id: 342d6a8703e4223f16fee46888880014
    entity_id: sensor.7adcffd4d7e5aef6880d7b76eedc4d9e
    domain: sensor
    type: humidity
    below: 65
    for:
      hours: 0
      minutes: 5
      seconds: 0

  # Trigger for button press to manually turn off boost
  - platform: device
    device_id: 60d20024b8c64073f4657697e96c1e9b
    domain: zha
    type: remote_button_short_press
    subtype: turn_on

condition: []
action:
  - choose:
      # Case 1: High humidity - Turn on boost
      - conditions:
          - condition: template
            value_template: "{{ trigger.type == 'humidity' and trigger.above == 75 }}"
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.ftx_boost

      # Case 2: Low humidity - Turn off boost
      - conditions:
          - condition: template
            value_template: "{{ trigger.type == 'humidity' and trigger.below == 65 }}"
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.ftx_boost

      # Case 3: Manual override - Turn off boost
      - conditions:
          - condition: template
            value_template: "{{ trigger.type == 'remote_button_short_press' and trigger.subtype == 'turn_on' }}"
          - condition: state
            entity_id: switch.ftx_boost
            state: 'on'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.ftx_boost

  mode: single

Where did that come from?

The available trigger variables are listed here: Automation trigger variables - Home Assistant

You’re using the trigger object incorrectly in your templates. It refers to properties that don’t exist.

Ninja’d by tom_l

Hi Ulf Benjaminsson,

Also there are no trigger variables to template on when using device triggers.
Automation trigger variables - Home Assistant.
If you want to use trigger variables you will need to not use device triggers (switch to state triggers),
Why and how to avoid device_ids in automations and scripts,
or teach your AI some new tricks.

Replace your humidity triggers with numeric_state and your button trigger with state.
Assign a trigger Id to each trigger.
Use the trigger Id for each choose.

Job done. No templates (or AI hallucinations) required.

Thanks!

Here is the fixed version:

alias: Ventilation Control - Bathroom Humidity
description: >-
  Manage boost mode on the ventilation system in response to bathroom humidity
  and manual override.
trigger:
  - platform: numeric_state
    entity_id: sensor.lumi_lumi_weather_humidity_4
    above: 75
    for:
      minutes: 1
    id: high_humidity
  - platform: numeric_state
    entity_id: sensor.lumi_lumi_weather_humidity_4
    below: 65
    for:
      minutes: 5
    id: low_humidity
  - platform: device
    domain: zha
    device_id: 60d20024b8c64073f4657697e96c1e9b
    type: remote_button_short_press
    subtype: turn_on
    id: manual_override
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: high_humidity
        sequence:
          - target:
              entity_id: switch.ftx_boost
            action: switch.turn_on
            data: {}
      - conditions:
          - condition: trigger
            id: low_humidity
        sequence:
          - target:
              entity_id: switch.ftx_boost
            action: switch.turn_off
            data: {}
      - conditions:
          - condition: trigger
            id: manual_override
          - condition: state
            entity_id: switch.ftx_boost
            state: "on"
        sequence:
          - target:
              entity_id: switch.ftx_boost
            action: switch.turn_off
            data: {}
mode: single

I can not for the life of me figure out how to get rid of the button as “device” and its “device id”. I’ve rifled through every part of ZHA and automation GUI and can not find a friendly name for the button, nor any entity to signal if it’s been pressed.

Followup question; how do I make the button press block the automation from restarting the fans again for some period of time after pressing it?

My bad - buttons don’t have a state - they fire events.

You can see it on the right hand side of the device page under the Logbook section - pressing the button should generate an event and create a logbook entry.

Alternatively, go to Developer Tools > Events tab and enter zha_event under “event to subscribe to”, then hit Start Listening. Pressing the button should generate the event you want.

1 Like