Light with motion - Override with switch?

To get NodeRed to show you the updated fields, your input_boolean in this case, restart the NodeRed addon in the supervisor/add-on store menu.

It took me a lot of searching to figure that out as I had the same issue.

Thanks for handy tip this will save me time as I have been restarting whole system when I want nodered to see file changes. Now I just need to restart hass and node red.

Hope you had backup :grimacing:

I am building up on it. It’s a good flow

Yea, I make a habit of taking one and storing it off the device every change I make. It went surprisingly quick. And my new Pi4 is fast. .

i found this flow … it 's great! : when motion is detected, the light turns on automatically. The light goes off after X minutes if no movement is detected during that period. If a movement is detected while the light is still on, the X-minute countdown is restarted.

If the light is turned on using the wall switch or UI HA or Alexa, the node that monitors the motion sensor is deactivated and the light stays on until it is turned off using the wall switch. After it’s turned off, the operation by the motion sensor works again.

It’s not a my job, but of BonaniTech https://bonani.tech/motion-activated-lights-with-switch-override/ .
I have tested it and works fine !

here Json code :

[{“id”:“db0e7316.57d11”,“type”:“api-call-service”,“z”:“dc65fbf7.4d2b88”,“name”:“luce accesa”,“server”:“176cc63b.d54b7a”,“version”:1,“debugenabled”:true,“service_domain”:“light”,“service”:“turn_on”,“entityId”:“light.led_cucina_2”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:761.000114440918,“y”:4159.4012241363525,“wires”:[[]]},{“id”:“57666d4d.0dee14”,“type”:“trigger”,“z”:“dc65fbf7.4d2b88”,“op1”:"",“op2”:"",“op1type”:“nul”,“op2type”:“pay”,“duration”:“1”,“extend”:true,“units”:“min”,“reset”:"",“bytopic”:“all”,“name”:“1min”,“x”:636.000078201294,“y”:4291.400710105896,“wires”:[[“d146ceba.8be6b”]]},{“id”:“d146ceba.8be6b”,“type”:“api-call-service”,“z”:“dc65fbf7.4d2b88”,“name”:“luce spenta”,“server”:“176cc63b.d54b7a”,“version”:1,“debugenabled”:true,“service_domain”:“light”,“service”:“turn_off”,“entityId”:“light.led_cucina_2”,“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:777.9999828338623,“y”:4251.400319099426,“wires”:[[]]},{“id”:“7f23104.9db16f”,“type”:“change”,“z”:“dc65fbf7.4d2b88”,“name”:“RESET”,“rules”:[{“t”:“set”,“p”:“reset”,“pt”:“msg”,“to”:“true”,“tot”:“bool”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:608.0000143051147,“y”:4210.400446891785,“wires”:[[“57666d4d.0dee14”]],“icon”:“node-red/timer.svg”,“l”:false},{“id”:“76462d42.6f2d14”,“type”:“trigger-state”,“z”:“dc65fbf7.4d2b88”,“name”:“luce cucina”,“server”:“176cc63b.d54b7a”,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityid”:“light.led_cucina_2”,“entityidfiltertype”:“exact”,“debugenabled”:true,“constraints”:[{“id”:“x0pn43xrg7”,“targetType”:“entity_id”,“targetValue”:“sensor.ha_uptime”,“propertyType”:“current_state”,“propertyValue”:“new_state.state”,“comparatorType”:">",“comparatorValueDatatype”:“num”,“comparatorValue”:“1”}],“constraintsmustmatch”:“all”,“outputs”:2,“customoutputs”:[],“outputinitially”:false,“state_type”:“str”,“x”:122.9999828338623,“y”:4177.40066242218,“wires”:[[“8a0e1bc9.27f3d8”],[“8744431.199e9c”]]},{“id”:“6623682f.c875e8”,“type”:“trigger-state”,“z”:“dc65fbf7.4d2b88”,“name”:“Motion Sensor”,“server”:“176cc63b.d54b7a”,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityid”:“binary_sensor.shenzhen_neo_electronics_co_ltd_battery_powered_pir_sensor_v2_sensor”,“entityidfiltertype”:“exact”,“debugenabled”:true,“constraints”:[{“id”:“7876m3tojhp”,“targetType”:“this_entity”,“targetValue”:"",“propertyType”:“current_state”,“propertyValue”:“new_state.state”,“comparatorType”:“is”,“comparatorValueDatatype”:“str”,“comparatorValue”:“on”}],“constraintsmustmatch”:“all”,“outputs”:2,“customoutputs”:[],“outputinitially”:false,“state_type”:“str”,“x”:437.9999828338623,“y”:4211.400319099426,“wires”:[[“7f23104.9db16f”,“2d3a7a0a.ddc576”],[“57666d4d.0dee14”]]},{“id”:“8744431.199e9c”,“type”:“change”,“z”:“dc65fbf7.4d2b88”,“name”:“ENABLE”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“enable”,“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:322.9999828338623,“y”:4241.400319099426,“wires”:[[“6623682f.c875e8”,“7f23104.9db16f”]],“icon”:“font-awesome/fa-toggle-on”,“l”:false},{“id”:“8a0e1bc9.27f3d8”,“type”:“change”,“z”:“dc65fbf7.4d2b88”,“name”:“DISABLE”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“disable”,“tot”:“str”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:324.9999694824219,“y”:4180.40044593811,“wires”:[[“6623682f.c875e8”,“7f23104.9db16f”]],“icon”:“font-awesome/fa-toggle-off”,“l”:false},{“id”:“6b176dd3.6fcef4”,“type”:“server-state-changed”,“z”:“dc65fbf7.4d2b88”,“name”:“luce cucina”,“server”:“176cc63b.d54b7a”,“version”:1,“exposeToHomeAssistant”:false,“haConfig”:[{“property”:“name”,“value”:""},{“property”:“icon”,“value”:""}],“entityidfilter”:“light.led_cucina_2”,“entityidfiltertype”:“exact”,“outputinitially”:false,“state_type”:“str”,“haltifstate”:“on”,“halt_if_type”:“str”,“halt_if_compare”:“is”,“outputs”:2,“output_only_on_state_change”:true,“x”:107.99999046325684,“y”:4241.400666236877,“wires”:[[],[“8744431.199e9c”]]},{“id”:“2d3a7a0a.ddc576”,“type”:“time-range-switch”,“z”:“dc65fbf7.4d2b88”,“name”:“After Sunset”,“lat”:“41.804279”,“lon”:“12.465473”,“startTime”:“sunset”,“endTime”:“sunrise”,“startOffset”:"-60",“endOffset”:"+60",“x”:594.9334411621094,“y”:4155.067371368408,“wires”:[[“db0e7316.57d11”],[]]},{“id”:“176cc63b.d54b7a”,“type”:“server”,“z”:"",“name”:“Home Assistant luigi”,“legacy”:false,“addon”:true,“rejectUnauthorizedCerts”:true,“ha_boolean”:“y|yes|true|on|home|open”,“connectionDelay”:true,“cacheJson”:true}]

I hope it could be help everyone .
Luigi

1 Like

I’m guessing your flow turns the light off after a certain time of no motion?

I think the only way to do this is with a boolean. So your switch turns the boolean (and the light) on. The motion trigger checks the state of the boolean and doesn’t switch the light off if the boolean is on. Turning the switch off turns the boolean off and your motion/timer kicks in again. There might be other ways but this seems logical and simple to me. And if it ain’t broke, don’t fix it :slight_smile:

Hey all!

Need some testers…

Trying a new Node Red automation to do the same as above - Override automation triggers by manually turning on a switch/light entity - but all within nodered, no input booleans required!

Please try it and let me know how you go.

[{"id":"42796725.b8ef68","type":"stoptimer","z":"51ba5037.15188","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":630,"y":440,"wires":[["1ae7f22d.4bb1ae"],[]]},{"id":"ff8d2198.3f5ba","type":"api-call-service","z":"51ba5037.15188","name":"OFF","server":"b4442cdf.ce6f4","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.porch_light_level","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":830,"y":500,"wires":[[]]},{"id":"bb65a20d.680f4","type":"api-call-service","z":"51ba5037.15188","name":"ON","server":"b4442cdf.ce6f4","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.porch_light_level","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":830,"y":380,"wires":[[]]},{"id":"4adee514.4b3efc","type":"server-state-changed","z":"51ba5037.15188","name":"Motion On","server":"b4442cdf.ce6f4","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.porch_multisensor_burglar","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"8","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":220,"y":380,"wires":[["5d208b59.f51424"],[]]},{"id":"399a8417.2f05ec","type":"time-range-switch","z":"51ba5037.15188","name":"After Sunset?","lat":"-23.465567","lon":"345.024548","startTime":"sunsetStart","endTime":"sunrise","startOffset":"","endOffset":"","x":620,"y":380,"wires":[["bb65a20d.680f4"],[]]},{"id":"354e3c8c.df7a04","type":"server-state-changed","z":"51ba5037.15188","name":"Light Switch","server":"b4442cdf.ce6f4","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.porch_light_level","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":230,"y":460,"wires":[["fa89edf2.2bc66"]]},{"id":"1ae7f22d.4bb1ae","type":"api-current-state","z":"51ba5037.15188","name":"Still Motion?","server":"b4442cdf.ce6f4","version":1,"outputs":2,"halt_if":"8","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"sensor.porch_multisensor_burglar","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":610,"y":500,"wires":[["42796725.b8ef68"],["ff8d2198.3f5ba"]]},{"id":"5d208b59.f51424","type":"traffic","z":"51ba5037.15188","name":"","property_allow":"payload","filter_allow":"0","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"1","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":true,"differ":false,"x":435,"y":380,"wires":[["399a8417.2f05ec","42796725.b8ef68"]],"l":false},{"id":"fa89edf2.2bc66","type":"change","z":"51ba5037.15188","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"1","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":355,"y":460,"wires":[["5d208b59.f51424"]],"l":false},{"id":"b4442cdf.ce6f4","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

Sorry to bother you, but I’m new to this world, node red and home assistant, could you tell me how you created the boolean input. Thank you

The signal from your traffic node will always hit the timer, switched or motion. So not sure it will do as you want. To me this seems doable with a simple ‘current state’ node of the switch to allow motion changes. I’m thinking like this:

One caveat, is the light will stay on 30sec after motion high… so if you have constant motion for 1min, you’ll be in the dark. This can be fixed by adding a 20sec loop node like I have done on my flow below.

I have a similar idea working, but since I’m using esphome devices (that can operate relays independent of HA) I don’t think my flow would apply to all users. My flow uses 2 timers for each switch position… 3min and 1hr… the 1hr could be swapped with a wait until node (wait until switch is off) to suit your case. Here’s my flow:

Again if you don’t use esphome or have a device that can toggle it’s relay without HA, it won’t work. I just figured I’d share in case it gives any insight… maybe could be modified for what you need. Note there’s more going on than just motion+switch. The motion affects 2 light systems, one that is over my workbench area sometimes needs to stay on… the other is a hallway of sorts so 3min is plenty. It also uses presence detection, and I have an input boolean I use to kill lights in front for 4th of july fireworks (yes, my garage lights are that bright). The 2min loop is there in case the motion sensor stays on for a long time (timer won’t reset without a message, so the loop feeds messages during constant motion). Also, I use a lum sensor instead of daytime… more or less same idea using different sensors.

You can create input booleans in your configuration.yaml file.

However, I’ve realised in my nodered flow, I was only utilising 1 out of 2 input booleans I created.

Furthermore, if you look for the previous post, I believe I’ve now overcome the need for input booleans for this nodered flow.

@truglodite
The traffic node is set to allow by default. The light entity will block traffic when turned on, so nothing is allowed through the flow when it’s turned on.
However, if the motion turns the light on, yes the traffic node will then be blocked, however, the flow what’s already passed it and triggered the timer/off part of the flow.

It’s actually been working flawlessly!

How would the light switch turn on the relay, unless you have another flow that does that (or esphome or similar non-HA method)?

The light is the only entity. There is no “switch” as such. Which is why this automation took a little more effort than say switch (binary sensor) controlling a light.

I have a combination of smart bulbs or zwave inwall switches might that do not use a separate switch to be controlled. So this automation is for when you are turning the light entity on manually from either the home assistant ui, google, etc.

Hej.
I have a automation with a lightsensor to turn on/off my group lights. When i use my switch to turn on/off a light in my light group the lights go on/off again. How do i fix that in node red?

Hi.
I’ve been following this thread for a while, and have been able to make automations with switch overrides because of it.
One thing i can’t figure out, though:
How do I get the helper entity to switch to ON when I turn on the lights from Lovelace UI (from web page or phone companion)?

Thanks

The actual light entity that controls the traffic light node should trigger the traffic light regardless if it has been controlled via the Lovelace UI, google home, or manually at the wall.

Is this what you’re asking?

Are you trying to “keep” the light on after the motion has turned it on? Or is the light off, and then when you use the switch it turns on then off? Hope you can explain it a little better please. :slight_smile:

Ok, so this thread is about overriding the motion sensor with a light switch, right? The way I’ve done that, is by setting a boolean helper to ON when the light is turned on by the switch, and to OFF when it’s turned off by the switch.
If the boolean is set to ON, the motion sensor does not kick in.
All well and good.
But when I turn on the light via the Lovelace UI, the boolean helper does not change to ON, and therefore creating a “hole” or a weakness in the automation if you will.
So how can the boolean helper be set to ON if I use Lovelace to turn on the lights?

By the way: I see there are some new approaches on how to achieve this override, by using this “traffic light” method. I will certainly test this. But I would think the problem remains if I turn on the light using Lovelace.

Thanks

This thread is about override the motion when the light is turned on manually, whether via a UI or directly, in the case of the switch not having an entity in HA, and the light being the entity itself. ie in-wall zwave or Shelly switch.

I was originally using input Booleans to overcome this, but with node red, and my latest iteration, input booleans are no longer required.

Can you share a copy of your latest iteration? Thanks.
But how do I override the motion sensor using the UI then?

Thanks again

I’m not home atm, but I’ll share the flow when I get back.

Basically the light entity itself triggers the traffic light node to either let the motion trigger through or not.

This is what I’ve been using and it works great!

There is either motion or a front door sensor that triggers the light on, if it state was off, but only between sunset/sunrise, and if the light was not turned on manually. The light will stay on for 30 seconds, unless there is continued motion.

The light entity controls the traffic light node, which either manually turned on via ui or wall switch, stops the flow after motion or the door sensor, and won’t trigger the timed automation. Once the light is turned off, the flow is free to flow as needed.

>  [{"id":"e1c0767e.cd2e68","type":"stoptimer","z":"9666b67f.350038","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":930,"y":2680,"wires":[["dd5f99e9.d1a4e8"],[]]},{"id":"4c728887.ab0ef8","type":"api-call-service","z":"9666b67f.350038","name":"OFF","server":"b4442cdf.ce6f4","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.porch_light_level","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1130,"y":2740,"wires":[[]]},{"id":"a5fc4210.f7d8","type":"api-call-service","z":"9666b67f.350038","name":"ON","server":"b4442cdf.ce6f4","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.porch_light_level","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1310,"y":2580,"wires":[[]]},{"id":"8f1b82cd.9b5de","type":"server-state-changed","z":"9666b67f.350038","name":"Motion On","server":"b4442cdf.ce6f4","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.porch_multisensor_burglar","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"8","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"x":310,"y":2580,"wires":[["bf028e78.7cd76"],[]]},{"id":"387fd025.f78b8","type":"time-range-switch","z":"9666b67f.350038","name":"After Sunset?","lat":"","lon":"","startTime":"sunsetStart","endTime":"sunrise","startOffset":"","endOffset":"","x":920,"y":2580,"wires":[["433a2db6.630d84"],[]]},{"id":"11f7df4e.15b451","type":"server-state-changed","z":"9666b67f.350038","name":"Light Switch","server":"b4442cdf.ce6f4","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.porch_light_level","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":310,"y":2740,"wires":[["1a5f9a47.7572f6"]]},{"id":"dd5f99e9.d1a4e8","type":"api-current-state","z":"9666b67f.350038","name":"Still Motion?","server":"b4442cdf.ce6f4","version":1,"outputs":2,"halt_if":"8","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"sensor.porch_multisensor_burglar","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":930,"y":2740,"wires":[["e1c0767e.cd2e68"],["4c728887.ab0ef8"]]},{"id":"e447f651.fb6528","type":"traffic","z":"9666b67f.350038","name":"","property_allow":"payload","filter_allow":"0","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"1","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":true,"differ":false,"x":710,"y":2620,"wires":[["e1c0767e.cd2e68","387fd025.f78b8"]]},{"id":"1a5f9a47.7572f6","type":"change","z":"9666b67f.350038","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"1","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":435,"y":2740,"wires":[["e447f651.fb6528"]],"l":false},{"id":"83b6d8fb.d9e0e8","type":"server-state-changed","z":"9666b67f.350038","name":"Front Door Sensor","server":"b4442cdf.ce6f4","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.front_door","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":330,"y":2660,"wires":[["bf028e78.7cd76"],[]]},{"id":"433a2db6.630d84","type":"api-current-state","z":"9666b67f.350038","name":"Already On?","server":"b4442cdf.ce6f4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.porch_light_level","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1130,"y":2580,"wires":[[],["a5fc4210.f7d8"]]},{"id":"bf028e78.7cd76","type":"api-current-state","z":"9666b67f.350038","name":"On/Off","server":"b4442cdf.ce6f4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.porch_light_auto","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":510,"y":2600,"wires":[["e447f651.fb6528"],[]]},{"id":"b4442cdf.ce6f4","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]