vient41
(Vient41)
October 26, 2023, 8:14pm
1
Hi,
I tried to create the follwing automation:
This automation will trigger when the PIR sensor detects motion, it checks if it’s between sunset and sunrise (nighttime) and if the light is off. If these conditions are met, it turns on the light with the appropriate brightness. After 3 minutes of inactivity (no more PIR triggers), it turns off the light. If the PIR sensor is triggered again within the 3-minute delay, the automation continues, and the light remains on.
using this yaml, but got the following error : Message malformed: extra keys not allowed @ data[‘0’]
- alias: "PIR Sensor Light Control"
trigger:
platform: state
entity_id: binary_sensor.pir_sensor
to: "on"
action:
- choose:
- conditions:
- condition: sun
after: sunset
before: sunrise
sequence:
- service: light.turn_on
entity_id: light.your_light_entity_id
data:
brightness: 255
- conditions:
- condition: sun
after: sunrise
before: sunset
sequence:
- service: light.turn_on
entity_id: light.your_light_entity_id
data:
brightness: 25
- delay: '00:03:00'
- condition: state
entity_id: binary_sensor.pir_sensor
state: "off"
- service: light.turn_off
entity_id: light.your_light_entity_id
- service: light.turn_off
data:
entity_id: light.your_light_entity_id
Or
- service: light.turn_off
data: {}
target:
entity_id: light.your_light_entity_id
The same goes for your turn on actions, entity_id
needs to be in the “data” object or in a “target” object.
vient41
(Vient41)
October 26, 2023, 8:49pm
3
Thank you for your reply
- alias: "PIR Sensor Light Control"
trigger:
platform: state
entity_id: binary_sensor.pir_sensor
to: "on"
action:
- choose:
- conditions:
- condition: sun
after: sunset
before: sunrise
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.your_light_entity_id
data:
brightness: 100
- conditions:
- condition: sun
after: sunrise
before: sunset
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.your_light_entity_id
data:
brightness: 15
- delay: '00:03:00'
- condition: state
entity_id: binary_sensor.pir_sensor
state: "off"
- service: light.turn_off
data: {}
target:
entity_id: light.your_light_entity_id
This doesn’t work either, let me know if you meant something else, happy to change accordingly.
WallyR
(Wally)
October 26, 2023, 8:53pm
4
Try to make the service call in the HA developer tools.
When it works, then switch to YAML mode and look at the setup.
It will give you a hint to how the service call must be made in the script.
You’ve gone too far the other direction…
You need to use your entities’ actual IDs not the stand-ins like light.your_light_entity_id
which I used because you did provide the real ones…
- alias: "PIR Sensor Light Control"
trigger:
platform: state
entity_id: binary_sensor.pir_sensor
to: "on"
action:
- choose:
- conditions:
- condition: sun
after: sunset
before: sunrise
sequence:
- service: light.turn_on
data:
brightness: 100
target:
entity_id: light.your_light_entity_id
- conditions:
- condition: sun
after: sunrise
before: sunset
sequence:
- service: light.turn_on
target:
entity_id: light.your_light_entity_id
data:
brightness: 15
- delay: '00:03:00'
- condition: state
entity_id: binary_sensor.pir_sensor
state: "off"
- service: light.turn_off
data: {}
target:
entity_id: light.your_light_entity_id
vient41
(Vient41)
October 28, 2023, 8:34pm
6
Hey, none of these worked, I will just try from the GUI…