Inconsistent automation results using conditions with Choose to control lights with a remote

Hi everyone. Im really stumped by this odd behaviour from HA automations. I have a hue dimmer remote(i have others as well and the same problem happens) which i want to control the living room lights with. Usually the remote works as configured. But sometimes randomly, it seems to not work as if it ignores a button press and might work on the next try or two.
Im using choose to capture the triggers. I have a yaml below of the automation which i can use to reproduce locally.

alias: Ground Remote
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.dimmer_living_room_action
    to:
      - on_press
      - off_press
      - on_hold
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.dimmer_living_room_action
            state: on_press
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 100
            target:
              entity_id:
                - light.g_sofa_lamp
                - light.g_vertical_lamp
      - conditions:
          - condition: state
            entity_id: sensor.dimmer_living_room_action
            state: off_press
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id:
                - light.g_sofa_lamp
                - light.g_vertical_lamp
      - conditions:
          - condition: state
            entity_id: sensor.dimmer_living_room_action
            state: on_hold
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: 20
            target:
              entity_id:
                - light.g_sofa_lamp
                - light.g_vertical_lamp
    default:
      - service: system_log.write
        data:
          level: error
          message: >-
            Inoperable Automation state. The new state: {{trigger.to_state.state}}
mode: queued

Now what I expect when im testing with triggers on_press and off_press, I should fall in the respective choose condition. But it will fall in the default. and the log message will still have the expected new state.
Do you see anything im doing wrong? Any suggestions to where to log to debug further?

Here is the log output of a ignored button press:

Inoperable Automation state. The new state: off_press

Here you can see the trace where the state is off_press but it does not fall in the 2nd condition but goes to default as if the condition does not match somehow.

Is it possible the sensor switches back to some other state quickly after being in one of the trigger states?

Download the trace’s json and post it.

1 Like

Indeed the dimmer is firing off multiple events and what you are saying makes sense. since some of these events set the action state to empty string or None.
Thank you that does help. I have modified another automation like this:

alias: 2 Office 3Button
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.2_office_3button_action
    to: 1_single
    variables:
      triggered_action: 1_single
  - platform: state
    entity_id:
      - sensor.2_office_3button_action
    to: 2_single
    variables:
      triggered_action: 2_single
condition: []
action:
  - choose:
      - conditions:
          - "{{ triggered_action == '1_single'}}"
        sequence:
          - service: light.turn_on
            data:
              color_temp: 500
              brightness_step_pct: 25
            target:
              entity_id: light.office_lights
      - conditions:
          - "{{ triggered_action == '2_single'}}"
        sequence:
          - service: light.turn_on
            data:
              color_temp: 444
              brightness_step_pct: -25
            target:
              entity_id: light.office_lights
mode: queued
max: 10

Let me know if there is a better way to do this. Thank you for the help.

alias: 2 Office 3Button
description: ""
trigger:
  - platform: state
    entity_id: sensor.2_office_3button_action
    to: 
      - '1_single'
      - '2_single'
condition: []
action:
  - service: light.turn_on
    data:
      color_temp: "{{ 500 if trigger.to_state.state == '1_single' else 444 }}"
      brightness_step_pct: "{{ 25 if trigger.to_state.state == '1_single' else -25 }}"
    target:
      entity_id: light.office_lights
mode: queued
max: 10

Thanks for the suggestion. @123 With your suggestions, wouldnt the inconsistency return. since the variable is changed mid execution by other zigbee2mqtt messages. I believe its better to capture that trigger value as a variable and use it later as i did in conditions or even like you wrote with jinja templates.

There’s no need to do that. The trigger variable persists throughout the execution of all actions.

It’s not; that’s not how the automation works.

The automation’s mode is queued. That means if it’s triggered again while it’s busy processing its actions, the second request is queued. After it completes processing its actions, it processes the next queued request.

Reference: Script Modes