Duration of motion based options in automation

Friends,

I am trying to create an automation that implements the following actions:

  • When motion detected in dresser, lights turned on at 20% brightness
  • When motion continues to be detected in dresser for 15 seconds, brightness of lights increased to 80%
  • When there is no motion detected for 20 seconds, lights turned off.

The problem is that when the second trigger (motion detected for 15 seconds) is triggered, still option 1 with 20% brightness is triggered.

Secondly, can somebody help me made a custom template sensor that is on when the sensor is in detected mode with a duration of more than 15 or more seconds, and off otherwise.

Thanks in advance.

alias: GF Kavya Dresser and Study Motion Light Automation
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.gf_kavya_dresser_any_motion_sensor
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.gf_kavya_dresser_any_motion_sensor
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 15
  - platform: state
    entity_id:
      - binary_sensor.kavya_dresser_all_presence_sensors
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 20
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.gf_kavya_dresser_any_motion_sensor
            state: "on"
        sequence:
          - service: light.turn_on
            data:
              kelvin: 2700
              brightness_pct: 20
            target:
              entity_id: light.gf_kavya_dresser_all_lights
      - conditions:
          - condition: state
            entity_id: binary_sensor.gf_kavya_dresser_any_motion_sensor
            state: "on"
            for:
              hours: 0
              minutes: 0
              seconds: 15
        sequence:
          - service: light.turn_on
            data:
              kelvin: 2700
              brightness_pct: 80
            target:
              entity_id:
                - light.gf_kavya_dresser_all_lights
                - light.gf_kavya_study_ll_2
      - conditions:
          - condition: state
            entity_id: binary_sensor.kavya_dresser_all_presence_sensors
            state: "off"
            for:
              hours: 0
              minutes: 0
              seconds: 20
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.gf_kavya_dresser_all_lights
    default:
      - service: light.turn_off
        data: {}
        target:
          entity_id:
            - light.gf_kavya_dresser_all_lights
mode: restart

alias: GF Kavya Dresser and Study Motion Light Automation
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.gf_kavya_dresser_any_motion_sensor
    to: "on"
    id: 'on_20'
  - platform: state
    entity_id:
      - binary_sensor.gf_kavya_dresser_any_motion_sensor
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 15
    id: 'on_80'
  - platform: state
    entity_id:
      - binary_sensor.kavya_dresser_all_presence_sensors
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 20
    id: 'off'
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: 'on_20'
        sequence:
          - service: light.turn_on
            data:
              kelvin: 2700
              brightness_pct: 20
            target:
              entity_id: light.gf_kavya_dresser_all_lights
      - conditions:
          - condition: trigger
            id: 'on_80'
        sequence:
          - service: light.turn_on
            data:
              kelvin: 2700
              brightness_pct: 80
            target:
              entity_id:
                - light.gf_kavya_dresser_all_lights
                - light.gf_kavya_study_ll_2
      - conditions:
          - condition: trigger
            id: 'off'
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.gf_kavya_dresser_all_lights
mode: restart

Thanks Tom. Let me try it out and report back.

My experrience with trigger ID is not good. Are trigger IDs limited to the automation that they are being created in, or they can be used in other automations too?

What I experienced in past was wherever I used trigger ID, and duplicated and made another automation out of it, the old trigger IDs automatically came in in the new automation on itself.

Trigger ids are local to each automation.

No sure what you mean by this. If you duplicate something and it contains parts you don’t want, just delete those parts.

Thanks a ton. It all worked well.