Why is this automation turning light on when entering the room and triggering the camera sensor, but not turning off after 10 minutes of inactivity? Got help in making this work (and finally stop throwing errors), but light doesn’t turn off after 10 minute time. Actually, I think it might flash off and then off again, but does not stay off.
Why is this automation turning light on when entering, but not off after 10 minutes inactivity?
alias: Lights On and Off on Timer in Office
description: Lights On and Off on Timer in Office
trigger:
platform: state
entity_id:
binary_sensor.birch_neolink_1_motion
from: “off”
to: “on”
Also, although writing clever code like this is compact, I think it is much clearer, and much better for self documentation, to use trigger IDs and the choose action.
Format your code properly. Because you have not done so, all of the quote characters have been turned into “smart quotes” by the forum software which are not valid in Jinja / YAML.
It also means we can’t see indentation errors you may have made.
The code that @templeton_nash asked you to try was copy/pasted from your original, containing the wrong quotes.
My apologies. Still new here. I’ve been using the pre-formatted text button. I think it is block quote that’s needed? Here is my code, modified with EdwardTFN suggestion. It now turns off after the prescribed time, but immediately turns back on, even with nobody in the room. So getting closer.
alias: Lights On and Off on Timer in Office
description: Lights On and Off on Timer in Office
trigger:
- platform: state
entity_id:
- binary_sensor.birch_neolink_1_motion
from: "off"
to: "on"
- platform: state
entity_id:
- binary_sensor.birch_neolink_1_motion
to: "off"
for:
minutes: 1
condition: []
action:
- service: light.turn_{{ states('binary_sensor.birch_neolink_1_motion') }}
target:
entity_id: light.jasco_products_43080_light
mode: single
Or maybe look at the log trace for the device to see what was the last thing to turn the light on again. Maybe there’s another automation in play? I’ve had instances where HA accidentally saved a copy of the automation I was working on, with flawed logic in it.
I’m at a loss. Trace is beyond my scope. Let me make a comment and tell me I’m wrong. When new people here ask how to do an automation to make lights go on with motion, and off with absense of motion, they get comments like “there are a hundred of these, do a search”. Well, I’ve tried about 5 that were posed, did the modifications as necessary, and none of them worked. When I get good people trying to help me, none of their solutions work. And these are experienced people (like you reading this) with an automation that would seem to be very very common.
I’m aware that HA is a work in progress, but for new people, this is really, really hard. I’m going to have to give up on this.
By the way, have you tried to use the Blueprint already available with your Home Assistant?
When creating a new automation, you are offered to create your automation from an existing blueprint and some are offered, including one named “Motion-activated Light”. That is tested by a lot of users and it is quite good and simple.
Maybe I’m misunderstanding something fundamental. Rick are you saying with this automation, I can go into Services → Automation → Create Automation → Create New Automation → 3 dots Edit in YAML, then paste it in exactly save for the name of my sensor and switch, and that should work.
Because every time I do that, I get errors and it won’t save. Specifically: Message malformed: extra keys not allowed @ data[‘0’]
My automation looks like this:
- id: '1628660691232'
alias: Lights-Turn On Front Porch Light When Front Door Cam Detects Motion
description: ''
trigger:
- platform: state
entity_id:
- binary_sensor.birch_neolink_1_motion
from: 'off'
to: 'on'
action:
- service: switch.turn_on
data: {}
target:
entity_id: light.jasco_products_43080_light
Used the automation from the blueprint, and that did turn the light off after I left for seconds, but immediately turned it back on. In other words, the light will not stay off.
Would this still happen if I was using a motion detector instead of a camera? Is that the issue? Does the camera see the light off as motion?