I’m a new HA user, running 0.65.5 smoothly on a Synology with Docker.
I’m starting with some basic automations but I find it very hard to do anything at all.
The task I’m trying to accomplish seems trivial though:
I’d like to turn on a light (Yeelight RGB) with a specific color and in low brightness when there is a movement (Xiaomi motion sensor linked to the Xiaomi Gateway), only between 23PM and before 6AM, and turn it off if there is no movement for 1.5 minutes.
If I manually switch on the light, I do not wish to have an automatic “turn off”.
The 1.5 minutes timer should only start if the light has been turned on by the automation.
I have found the following code which seems to do what I want and I have adjusted it to add the RGB color and the brightness.
It turns on the light as expected, but I get an error when it tries to turn the light off, because of the added parameters
- alias: Gateway light on/off based on motion
trigger:
- platform: state
entity_id: binary_sensor.motion_sensor_id
to: 'on'
- platform: state
entity_id: binary_sensor.motion_sensor_id
to: 'off'
for:
minutes: 1
seconds: 30
condition:
condition: time
after: '23:00'
before: '06:00'
action:
action:
service_template: >
{% if trigger.to_state.state == "on" %}
light.turn_on
{% elif trigger.to_state.state == "off" %}
light.turn_off
{% endif %}
data_template:
entity_id: light.pilar
brightness: 1
rgb_color: [255,0,255]
The error I receive is:
Invalid service data for light.turn_off: extra keys not allowed @ data[‘brightness’]. Got '1’
extra keys not allowed @ data[‘rgb_color’]. Got [‘255’, ‘0’, ‘255’]
I understand the error is caused by the additional RGB/brightness parameters, however I have no idea how to do such a scenario differently and as simple as possible.
I hope someone out there will be able to give me some pointers
Turnoff won’t accept additional options and the triggers are confusing (as it will trigger either the binary is set on or is set off for 1.5 min). Try this (there’s an automation and two separate scripts). Whenever a motion is detected the light will turn on and the timer of 1.5 min will be reset after each trigger.
You could also just have one automation that turns on the light and an input boolean (e.g. input_boolean.motion_lights), and then another automation that triggers on the motion sensor going to “off” for 1.5 min, has a condition that the boolean is on, and then turns off the light and the boolean.