Help: Automation with trigger IDs (motion trigger) always chooses the default action

Could somebody help me spot the mistake I am making in this automation. I made it via the Home Assistant automatons UI.

I want the study lamp to be turned on when the motion sensor is turned-on and study lamp to be turned off 5 minutes after the motion sensor is turned off.

I’ve tried to use the trigger ids mithu-table-on and mithu-table-off for the two motion trigger states, and use that in the action part of the automation.

alias: 'Study Lamp Toggle: Based on trigger IDs (motion trigger) and 2 time conditions'
description: ''
trigger:
  - type: motion
    platform: device
    device_id: c316cb8ed428d88d280ad86fc793f20f
    entity_id: binary_sensor.motion_table_mithu
    domain: binary_sensor
    id: mithu-table-on
  - type: no_motion
    platform: device
    device_id: c316cb8ed428d88d280ad86fc793f20f
    entity_id: binary_sensor.motion_table_mithu
    domain: binary_sensor
    id: mithu-table-off
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: time
    before: '08:00:00'
    after: '05:00:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - sun
      - fri
      - sat
  - condition: time
    before: '21:45:00'
    after: '17:00:00'
    weekday:
      - mon
      - tue
      - wed
      - thu
      - sun
      - fri
      - sat
action:
  - choose:
      - conditions:
          - condition: trigger
            id: mithu-table-on
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.study_lamp_mithu
      - conditions:
          - condition: trigger
            id: mithu-table-off
        sequence:
          - service: light.turn_off
            data:
              flash: short
            target:
              entity_id: light.study_lamp_mithu
    default: []
mode: single

Debug trace shows this:

How are you testing this? Your general conditions cancel each other out. You will need to wrap your conditions in an OR condition.

From the trace, it appears you are probably triggering it manually or using the “Run Action” function. When you do that, there is no trigger with an id, so neither of your Choose option conditions evaluate to True.

1 Like

Thank you so much for your reply. Yes I am triggering it manually with the ‘Run Action’ button. It doesn’t work otherwise too so its the conditions not wrapped with an OR condition probably. I will check that out now.

– EDIT–
Yes it worked as intended after wrapping the conditions with OR condition. Here is the corrected version:

alias: 'Study Lamp toggle: based on motion trigger using trigger ids and two time conditions'
description: ''
trigger:
  - type: motion
    platform: device
    device_id: c316cb8ed428d88d280ad86fc793f20f
    entity_id: binary_sensor.motion_table_mithu
    domain: binary_sensor
    id: mithu-table-on
  - type: no_motion
    platform: device
    device_id: c316cb8ed428d88d280ad86fc793f20f
    entity_id: binary_sensor.motion_table_mithu
    domain: binary_sensor
    id: mithu-table-off
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: or
    conditions:
      - condition: time
        before: '08:00:00'
        after: '05:00:00'
        weekday:
          - sun
          - sat
          - fri
          - thu
          - wed
          - tue
          - mon
      - condition: time
        before: '21:45:00'
        after: '17:00:00'
        weekday:
          - sun
          - sat
          - fri
          - thu
          - wed
          - tue
          - mon
action:
  - choose:
      - conditions:
          - condition: trigger
            id: mithu-table-on
        sequence:
          - service: light.turn_on
            data:
              transition: 180
            target:
              entity_id: light.study_lamp_mithu
      - conditions:
          - condition: trigger
            id: mithu-table-off
        sequence:
          - service: light.turn_off
            data:
              transition: 180
            target:
              entity_id: light.study_lamp_mithu
    default: []
mode: single