Implementing Different Auto-Off Times Based on Trigger + Optimization

Hi everyone,

I’m working on an automation for my above-sink lights that uses 1 dimmer switch (Hue 4-button dimmer) and 1 motion sensor (Hue indoor motion sensor). I’ve got the basic functionality working, but I’m struggling to set different auto-off times based on the initial trigger.

Here’s the desired behavior:

  1. Dimmer Switch Trigger:
  • When the dimmer switch is pressed:
    • Lights turn on to full brightness.
    • If there’s no motion for 5 minutes, the lights automatically turn off.
  1. Motion Sensor Trigger:
  • When motion is detected (and it’s dark enough):
    • Lights turn on to an appropriate brightness level (using a script).
    • If there’s no motion for 1 minute, the lights automatically turn off.

Current Automation:

alias: Above Sink Lights Motion Detection

description: >-

triggers:

  - device_id: Kitchen dimmer

    domain: hue

    type: initial_press

    subtype: 1

    trigger: device

    id: kitchen-dimmer-pressed

  - type: motion

    device_id: Kitchen motion sensor

    domain: binary_sensor

    trigger: device

    id: kitchen-motion-detected

  - type: no_motion

    device_id: Kitchen motion sensor

    domain: binary_sensor

    trigger: device

    for:

      hours: 0

      minutes: 1

      seconds: 0

    id: kitchen-nomotion-detected

  - device_id: Kitchen dimmer

    domain: hue

    type: initial_press

    subtype: 4

    trigger: device

    id: kitchen-dimmer-pressed-off

conditions: []

actions:

  - choose:

      - conditions:

          - condition: trigger

            id: kitchen-dimmer-pressed

        sequence:

          - target:

              entity_id: scene.kitchen_shine

            action: scene.turn_on

            data:

              transition: 1

      - conditions:

          - condition: trigger

            id: kitchen-motion-detected

          - type: is_illuminance

            condition: device

            device_id: Kitchen motion sensor

            domain: sensor

            below: 16

        sequence:

          - action: script.kitchen_sensor_light_conditions

            data: {}

          - if:

              - condition: state

                entity_id: light.kitchen

                state: "off"

            then:

              - action: input_boolean.turn_off

                metadata: {}

                data: {}

                target:

                  entity_id: input_boolean.kitchen_light_manual

      - conditions:

          - condition: trigger

            id: kitchen-dimmer-pressed-off

        sequence:

          - target:

              entity_id: scene.kitchen_light_off

            action: scene.turn_on

            data: {}

      - conditions:

          - condition: trigger

            id: kitchen-nomotion-detected

        sequence:

          - target:

              entity_id: scene.kitchen_light_off

            action: scene.turn_on

            data: {}

mode: restart

The Challenge:

I’m unable to figure out how to track the initial trigger and set the corresponding auto-off timer. I’ve tried using trigger-ids and more conditions, but I haven’t been successful.

Additionally, I’m experiencing some issues with the automation’s responsiveness:

  • Sometimes (it doesn’t happen every time), when the lights turn off automatically, they take a noticeable amount of time to turn back on when motion is detected again

Any advice on how to address this issue would be greatly appreciated.

Thanks in advance for your help!

Hi Piet,
Welcome to the forum. Let’s see if I can be of any assistance.

My suggestion would be to look in the Blueprints Exchange - Home Assistant Community category. there are several versions of motion light control blueprints there that Forum Community Members have contributed. You are free to use one of these, or look at their code to see how they did things so you know how to do it. You can even ‘take control’ of a blueprint which will generate an automation (or script) for you to adapt or use as you see fit.

Thank you for your suggestion. I’ve explored the Blueprints Exchange but haven’t found a blueprint that perfectly aligns with my needs. Some blueprints offer extensive customization but can be overwhelming to configure and to debug, while others are simpler but lack the flexibility I’m looking for:

  • Triggers on both dimmer switch and motion sensor events.
  • Adjusts light brightness based on time of day and occupancy.
  • Includes customizable delay timers for turning lights off.