Light with Resettable Timer

Hi all

wondering if any of you can help me with setting up timer light that will automatically dim when there’s no motion and un-dim when there’s motion. This below automation works but only if there’s time the state change is from 0 to 8. However, if we stayed in the living room for more than 15 minutes, it doesnt reset the timer because the state didnt change back from 8 to 0.

the Aeotech multi sensor - motion sensor will reset from 8 to 0 in 8 minutes, once it no longer detects motion. It will remain to have value 8 if motion is constantly detected

Thanks!

Automation:

alias: Living Room Light un-DIM when Motion
trigger:
  platform: state
  entity_id: sensor.aeotec_multisensor_6_burglar_2
  from: '0'
  to: '8'
condition:
  - condition: time
    after: '17:00:00'
    before: '23:00:00'
  - condition: state
    entity_id: light.lr_standing_lamp
    state: 'on'
action:
  service: script.livingroom_light_15mins_dim

script:

alias: dim and undim living lamp on motion
sequence:
- event: LOGBOOK_ENTRY
  event_data:
    name: EVENT
    message: Motion Detected - Dim Timer Activated
- alias: Motion Detected - un-Dimming
  service: scene.turn_on
  entity_id: scene.livingroom_normal
- alias: delay 15 minutes
  delay:
    minutes: 15
- alias: Motion Not Detected - Dimming
  service: scene.turn_on
  entity_id: scene.livingroom_dim

scene:

- name: Livingroom Dim
  entities:
     light.lr_standing_lamp:
      state: on
      transition: 2
      brightness: 30
      color_temp: 189
      
- name: Livingroom Normal
  entities:
     light.lr_standing_lamp:
      state: on
      transition: 2
      brightness: 253
      color_temp: 189

no one? :slight_smile:

You desire for the light to dim after 15 minutes regardless if motion is still detected in the room?

Hi K,

i desire the light to remain on if motion is detected and ONLY to dim if 15minutes has passed and no motion being detected.

Hi kwetiaw,

I’ve done what you’re trying to achieve with the addition of different delays depending on the time of day + increasing delay when sensor gets triggered a few time within a timeframe to avoid having to change the delays manually.

2 tips:

  1. conditions can also help limiting the execution of actions in an automation as well as in scripts, just try to avoid templated ones (although this fact changed recently, they used to add unnecessary delays) as 90% of the time a state, numeric_value or time condition will suffice.

  2. don’t try to combine everything together (I started like this, thinking it would reduce the delays) and look into ways to split your scripts and automations, then you can also switch them on or off as needed.

In your case you’ll want to start the dimmer separately, just add a separate trigger for your motion detector with multiple state conditions, you should add a boolean switch or binary_sensor template to know if you want to trigger the light scene or not.

condition:
condition: and
conditions:
- condition: state
entity_id: light/group.xxx
state: “on”
- condition: state
entity_id: script.dimmer_roomX
state: “on”
action:
service: homeassistant.turn_off
entity_id: script.dimmer_roomX

This way you will cancel the timed dimmer and start it again without triggering the scene.

The template binary sensor is a bit more complex, just know that when it moves from seconds to minutes it will be rounded, so you can extract the values in a template :

{% if {{ relative_time(states.light.lifx_salon3.last_updated).split(" ")[1]|int|round() }} > "10" %}
  On
{% else %}
  Off
1 Like

I will give this a try when I get home tonight. Thanks!