Hi,
I have an automation to switch on lights when motion is detected and after 3 minutes after a detection is cleared switch light off. I found how in this topic
I created this YAML for it:
alias: Verlichting Hal nacht
description: Licht hal aan op 20% tussen 23:15 en 07:45 voor 3 minuten bij beweging
triggers:
- trigger: state
entity_id:
- >-
binary_sensor.hal_bewegingssenor_hal_boven_hal_bewegingssenor_hal_boven_motion_sensor_status
to: "on"
- trigger: state
entity_id:
- >-
binary_sensor.hal_bewegingssenor_hal_boven_hal_bewegingssenor_hal_boven_motion_sensor_status
to: "off"
for:
minutes: 3
conditions:
- condition: time
after: "23:15:00"
before: "07:45:00"
enabled: false
actions:
- metadata: {}
data:
brightness_pct: 100
target:
device_id:
- e7322370ab952c69324324804139376a
- d6874503c6ef5288149aa0b3d261494c
action: light.turn_{{ trigger.to_state.state }}
mode: single
When motion is detected the light go on to 100% then is stops, when motion is cleared and 3 minuts are past I would expect lights to go off. This does not happen. I checked the state of the motion sensor and this goes from detected and then to cleared. I noticed that in the visual editor states are called detected & cleared:
As always I probably make a thinking error. Hope that someone can point me to what I am doing wrong here.
Thanks, Bernard
I may be wrong, but I don’t think trigger to state works with device IDs. Have you tried using the entity ID of the light, as in the original example you looked at?
Thanks for the hint, changed the from device to entity. Still the same motion detected lights on, but after 3 minutes not switched off. New YAML:
alias: Verlichting Hal nacht
description: Licht hal aan op 20% tussen 23:15 en 07:45 voor 3 minuten bij beweging
triggers:
- trigger: state
entity_id:
- >-
binary_sensor.hal_bewegingssenor_hal_boven_hal_bewegingssenor_hal_boven_motion_sensor_status
to: "on"
- trigger: state
entity_id:
- >-
binary_sensor.hal_bewegingssenor_hal_boven_hal_bewegingssenor_hal_boven_motion_sensor_status
to: "off"
for:
minutes: 3
conditions:
- condition: time
after: "23:15:00"
before: "07:45:00"
enabled: false
actions:
- target:
entity_id:
- light.verlichting_hal_boven_hal_verlichting_hal_boven_dimmer_1
- light.hal_verlichting_hal_beneden_hal_verlichting_hal_beneden_dimmer_1
data:
brightness_pct: 20
action: light.turn_{{ trigger.to_state.state }}
mode: single
Looking at the logs/traces I found that it gets triggered to switch off but the statement:
brightness_pct: 20
is causing it to fail to switch off. I am not able to set the brightness using this way of motion detection and switching on and off.
Any thoughts on how to get this done? Motion detected, lights on for 3 min at 20% brightness then switch off.
Now it will use last state and that is to much light in nighttime.
Thanks for helping out.
Solved it by triggering on detection to switch on then timer 3 min then switch off, YAML:
alias: Verlichting Hal nacht
description: Licht hal aan op 20% tussen 23:15 en 07:45 voor 3 minuten bij beweging
triggers:
- trigger: state
entity_id:
- >-
binary_sensor.hal_bewegingssenor_hal_boven_hal_bewegingssenor_hal_boven_motion_sensor_status
to: "on"
conditions:
- condition: time
after: "23:15:00"
before: "07:45:00"
enabled: true
actions:
- action: light.turn_on
metadata: {}
data:
brightness_pct: 20
target:
device_id:
- d6874503c6ef5288149aa0b3d261494c
- e7322370ab952c69324324804139376a
- delay:
hours: 0
minutes: 3
seconds: 0
milliseconds: 0
- action: light.turn_off
metadata: {}
data: {}
target:
device_id:
- d6874503c6ef5288149aa0b3d261494c
- e7322370ab952c69324324804139376a
mode: single