Motion Sensor Automation With Timer

I have a motion sensor that triggers lights in my kitchen. I want the lights to stay on while I’m in there, and if no motion is detected for them to dim and then turn off.

One thing I found as if they begin the “off” automation and I walk back in there, they will still turn off. I set the “off” automation to turn off then back on in order to stop it if it’s currently running. Is there a more elegant way to do this?

- id: '1608659020753'
  alias: Kitchen Motion Daytime
  trigger:
  - type: motion
    platform: device
    device_id: ac21d93e1d4ae70f9dd21699230e185f
    entity_id: binary_sensor.hue_motion_sensor_1_motion
    domain: binary_sensor
  condition:
  - condition: sun
    before: sunset
    after: sunrise
  action:
  - service: hue.hue_activate_scene
    data:
      group_name: Kitchen
      scene_name: Relax
  - service: automation.turn_off
    data:
      entity_id: automation.kitchen_motion_off
  - service: automation.turn_on
    data:
      entity_id: automation.kitchen_motion_off
  mode: restart
- id: '1608659065203'
  alias: Kitchen Motion Night Time
  trigger:
  - type: motion
    platform: device
    device_id: ac21d93e1d4ae70f9dd21699230e185f
    entity_id: binary_sensor.hue_motion_sensor_1_motion
    domain: binary_sensor
  condition:
  - condition: sun
    before: sunrise
    after: sunset
  action:
  - service: hue.hue_activate_scene
    data:
      group_name: Kitchen
      scene_name: Dimmed
  - service: automation.turn_off
    data:
      entity_id: automation.kitchen_motion_off
  - service: automation.turn_on
    data:
      entity_id: automation.kitchen_motion_off
  mode: restart
- alias: Kitchen Motion Off
  trigger:
  - platform: state
    entity_id: binary_sensor.hue_motion_sensor_1_motion
    to: 'off'
    for: "00:02:30"
  action:
  - service: hue.hue_activate_scene
    data:
      group_name: Kitchen
      scene_name: Nightlight
  - delay: 00:00:30
  - service: light.turn_off
    data:
      entity_id: light.kitchen_lights
  mode: single

Tip:

If you ever find yourself creating logic that relies on turning on/off other automations, the logic is probably needlessly Byzantine.

I suggest you either re-invent it or use one of the existing blueprints for motion-activated lights (there are many) as inspiration for a new design.

Check my posting history; helping people fix or streamline their automations is my chief interest here.

I noticed your original reply stated you came here looking for a simpler solution … and then you changed it to say you’re not interested in opinions on what you’re doing.

Good luck with that.

@123 sorry wasn’t trying to be an ass (but I think I was). I wasn’t posting hoping for someone to tell me not to make my lights dim before they turn off ya know? Didn’t mean to take it personally and probably misread your reply

What about adding an action condition to check the motion sensor is still off before dimming and before turning off light?

Thank you for your hard work on this amazing Blueprint! I would like to display the amount of time left on the timer in a card on my interface. I know when you create a separate timer helper it is possible, can you use helper timers with this blueprint?