So for the second time I am trying to slowly pass my automations from yaml to node-red.
I am stuck in one of the most used automations that I have. How to turn off lights if there is no motion for X minutes.
What I have done so far is:
[{"id":"ece70edb.8ef5c","type":"server-state-changed","z":"17be72b6.fc87cd","name":"Kitchen Motion Detection","server":"eaecb825.5ab888","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.motion_sensor_158d0003f3edfc","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":130,"y":440,"wires":[["94cce413.5caff8"]],"info":"binary_sensor.motion_sensor_158d00036d5a35_garage_workbox"},{"id":"ab6affb5.5bb88","type":"api-call-service","z":"17be72b6.fc87cd","name":"Turn on","server":"eaecb825.5ab888","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.shelly_kitchen_lights_cabinet","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":960,"y":420,"wires":[["ad59f9c2.6dbc68"]]},{"id":"dd8cde40.54d79","type":"api-current-state","z":"17be72b6.fc87cd","name":"Is any light on?","server":"eaecb825.5ab888","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.kitchen_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":540,"y":420,"wires":[[],["a04a51cf.1ef3c"]]},{"id":"ad44f84c.c0d828","type":"comment","z":"17be72b6.fc87cd","name":"Kitchen Motion Detection","info":"","x":110,"y":380,"wires":[],"icon":"node-red/bluetooth.png"},{"id":"94cce413.5caff8","type":"switch","z":"17be72b6.fc87cd","name":"On-Off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":440,"wires":[["dd8cde40.54d79","ad59f9c2.6dbc68"],["ad59f9c2.6dbc68"]]},{"id":"a04a51cf.1ef3c","type":"api-current-state","z":"17be72b6.fc87cd","name":"Low illumination?","server":"eaecb825.5ab888","version":1,"outputs":2,"halt_if":"60","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.illumination_158d0003f3edfc","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":770,"y":420,"wires":[["ab6affb5.5bb88"],[]]},{"id":"ad59f9c2.6dbc68","type":"stoptimer","z":"17be72b6.fc87cd","duration":"10","units":"Minute","payloadtype":"num","payloadval":"0","name":"10 min","x":630,"y":500,"wires":[["83780870.ece548"],[]]},{"id":"f8b17db4.bb34d","type":"api-call-service","z":"17be72b6.fc87cd","name":"Turn off","server":"eaecb825.5ab888","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.kitchen_lights","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1220,"y":460,"wires":[[]]},{"id":"4493d623.b25d58","type":"api-current-state","z":"17be72b6.fc87cd","name":"Is TV off?","server":"eaecb825.5ab888","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.lg_kitchen_tv","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1040,"y":500,"wires":[["f8b17db4.bb34d"],["eb7a166.1bf23e8"]]},{"id":"eb7a166.1bf23e8","type":"trigger-state","z":"17be72b6.fc87cd","name":"TV turns off","server":"eaecb825.5ab888","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"media_player.lg_kitchen_tv","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"ygscgf6zloj","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":1210,"y":540,"wires":[["1d7b6933.00b027"],[]]},{"id":"8ac39f82.44d8","type":"api-call-service","z":"17be72b6.fc87cd","name":"Turn off","server":"eaecb825.5ab888","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.kitchen_lights","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1580,"y":540,"wires":[[]]},{"id":"1d7b6933.00b027","type":"stoptimer","z":"17be72b6.fc87cd","duration":"2","units":"Minute","payloadtype":"num","payloadval":"0","name":"2 min","x":1410,"y":540,"wires":[["8ac39f82.44d8"],[]]},{"id":"83780870.ece548","type":"api-current-state","z":"17be72b6.fc87cd","name":"Is any light on?","server":"eaecb825.5ab888","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.kitchen_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":500,"wires":[["4493d623.b25d58"],[]]},{"id":"eaecb825.5ab888","type":"server","z":"","name":"Home Assistant","addon":true}]
What I am trying to do is:
If motion is detected and there is no open light and there is not much sun in the kitchen, turn on a light. Easy and it works perfect.
Now the difficult part.
If for 10 minutes there is no motion and there is a light on, check what happens with TV. If it is off, turn the lights off. If it is on, wait until the TV turns off and then after 2 minutes, close the lights.
Biggest problem here is that the part “If for 10 minutes there is no motion” doesn’t work correct and the lights close and don’t open again after even if there is motion in the room.
Then what I am trying to do with the TV, I haven’t been able to test it so far bcs of the previous issue.
The simple automation that I had before:
- alias: Kitchen light on when movement
trigger:
- entity_id: binary_sensor.motion_sensor_158d0003f3edfc
platform: state
to: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: light.shelly_kitchen_lights_window
state: 'off'
- condition: numeric_state
entity_id: sensor.illumination_158d0003f3edfc
below: 60
action:
- data:
entity_id: light.shelly_kitchen_lights_window
service: light.turn_on
and:
- alias: Kitchen light off when no movement
trigger:
- entity_id: binary_sensor.motion_sensor_158d0003f3edfc
for:
minutes: 10
from: 'on'
platform: state
to: 'off'
action:
- data:
entity_id: light.kitchen_lights
service: light.turn_off
WAF is killing me… Any suggestion would be nice.
But don’t forget that I am noob in node-red so take it easy on me!