Need help with Switch override for motion sensor for turning on lights

an upate here, the motion sensor remains disabled even if i turn off the switch manually.

any idea why? i have the aqara zigbee switches

You should export your flow when asking for help, it makes it easier for people to make adjustments.

You can use a current state to check if it is sundown to turn the light on.

After the light turns off use that to re-enable the motion trigger. Disconnect the lower output.

thank you, but thats not what the switch override function I am looking for…

Maybe this will help. When the switch comes on it disables the motion sensor trigger. Then when the light goes off, from the switch or from the timer, motion is re enabled.

Thanks can you pls post the code for this?

That is really just visual, nothing is set in the nodes. If you post what you have, I will fix it for you.

First select/highlight all the nodes of your flow. On the right, in node red, the hamburger menu. You will see export, select that option. When the dialog box opens select copy to clip board.

Read this post for how to post code on the forum, then post your code.

Hello Mike thanks for your replies.
I have uploaded the code here.
https://pastebin.com/raw/xLmqy62A

The motion sensor still stays disabled after it has triggered the lights turn on flow.
See the screenshot attached below.

Pls note, I am using an Aqara Motions sensor, hence i have to add the extra flow at the end for the motion sensor to manually go and check for the timer…

I would use an event state for the switch, it won’t let me add the light entity, so you will need to define it.

[{"id":"e433ab36.c6b358","type":"api-call-service","z":"032af85c90a1c4f5","name":"Mudroom Lights ON","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1320,"y":240,"wires":[[]]},{"id":"16bf9a80.ccead6","type":"api-call-service","z":"032af85c90a1c4f5","name":"Mud Room Lights OFF","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1320,"y":440,"wires":[[]]},{"id":"56668319.4c687c","type":"trigger-state","z":"032af85c90a1c4f5","name":"Motion Sensor","server":"","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":830,"y":240,"wires":[["f7c35a29892a7203"],["f7c35a29892a7203"]]},{"id":"279d7f80.57b5d","type":"change","z":"032af85c90a1c4f5","name":"ENABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":675,"y":300,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-on","l":false},{"id":"a2d4c1a6.bb35a","type":"change","z":"032af85c90a1c4f5","name":"DISABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":675,"y":240,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-off","l":false},{"id":"0ffe09c3914bab93","type":"stoptimer","z":"032af85c90a1c4f5","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":1050,"y":360,"wires":[["5660b85435a6eb11"],[]]},{"id":"5660b85435a6eb11","type":"api-current-state","z":"032af85c90a1c4f5","name":"Motion Sensor Status","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1320,"y":360,"wires":[["8fdd7877150f5c27"]]},{"id":"8fdd7877150f5c27","type":"switch","z":"032af85c90a1c4f5","name":"Motion Detector Still ON? ","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1070,"y":440,"wires":[["0ffe09c3914bab93"],["16bf9a80.ccead6"]]},{"id":"f7c35a29892a7203","type":"api-current-state","z":"032af85c90a1c4f5","name":"","server":"","version":3,"outputs":2,"halt_if":"below_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1060,"y":240,"wires":[["e433ab36.c6b358","0ffe09c3914bab93"],[]]},{"id":"3669b0496d8b225d","type":"server-state-changed","z":"032af85c90a1c4f5","name":"Add to light.mud_room_lights to entity","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"device_tracker.pixel_3_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":310,"y":360,"wires":[["f2fee74cacda5014"]]},{"id":"f2fee74cacda5014","type":"switch","z":"032af85c90a1c4f5","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":530,"y":360,"wires":[["a2d4c1a6.bb35a","0ffe09c3914bab93"],["279d7f80.57b5d"]]}]
1 Like

Hello @Mikefila , thank you so much for looking into this and helping me with fixing this issue.
Your flows have pretty much fixed the first part of the issue, now the lights will turn off after x amount of time as previously it it would not. However the switch override fuction is not working.
Let me explain.
I enter the room, the lights turn on, as soon as the lights turn on, i will hit the turn on part of the switch and step outside the room, after that, the lights will turn off after x amount of time.
So the switch override function part remains.
I am posting the script after adding the entity id’s for you. Can you please look into this last bit for me pls.

[{"id":"e433ab36.c6b358","type":"api-call-service","z":"c1201833e8bbd49f","name":"Mudroom Lights ON","server":"2736f9e1.3a6d56","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":["garage"],"deviceId":["4f9bfa253ff105c8bd4470e83c911c17"],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1160,"y":100,"wires":[[]]},{"id":"16bf9a80.ccead6","type":"api-call-service","z":"c1201833e8bbd49f","name":"Mud Room Lights OFF","server":"2736f9e1.3a6d56","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":["garage"],"deviceId":["4f9bfa253ff105c8bd4470e83c911c17"],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1160,"y":360,"wires":[[]]},{"id":"56668319.4c687c","type":"trigger-state","z":"c1201833e8bbd49f","name":"Motion Sensor","server":"2736f9e1.3a6d56","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":670,"y":160,"wires":[["f7c35a29892a7203"],["f7c35a29892a7203"]]},{"id":"279d7f80.57b5d","type":"change","z":"c1201833e8bbd49f","name":"ENABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":515,"y":220,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-on","l":false},{"id":"a2d4c1a6.bb35a","type":"change","z":"c1201833e8bbd49f","name":"DISABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":515,"y":160,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-off","l":false},{"id":"0ffe09c3914bab93","type":"stoptimer","z":"c1201833e8bbd49f","duration":"3","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":880,"y":280,"wires":[["5660b85435a6eb11"],[]]},{"id":"5660b85435a6eb11","type":"api-current-state","z":"c1201833e8bbd49f","name":"Motion Sensor Status","server":"2736f9e1.3a6d56","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1160,"y":280,"wires":[["8fdd7877150f5c27"]]},{"id":"8fdd7877150f5c27","type":"switch","z":"c1201833e8bbd49f","name":"Motion Detector Still ON? ","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":360,"wires":[["0ffe09c3914bab93"],["16bf9a80.ccead6"]]},{"id":"f7c35a29892a7203","type":"api-current-state","z":"c1201833e8bbd49f","name":"","server":"2736f9e1.3a6d56","version":3,"outputs":2,"halt_if":"below_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":900,"y":160,"wires":[["e433ab36.c6b358","0ffe09c3914bab93"],[]]},{"id":"3669b0496d8b225d","type":"server-state-changed","z":"c1201833e8bbd49f","name":"Mud Room Lights","server":"2736f9e1.3a6d56","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.mud_room_lights","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":90,"y":280,"wires":[["f2fee74cacda5014"]]},{"id":"f2fee74cacda5014","type":"switch","z":"c1201833e8bbd49f","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":370,"y":280,"wires":[["a2d4c1a6.bb35a","0ffe09c3914bab93"],["279d7f80.57b5d"]]},{"id":"2736f9e1.3a6d56","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

The light and the switch are one in the same? When the motion sensor triggers it turns on the switch. I don’t know that there is a way to differentiate whether it was physically pressed or from ha without seeing the debug message.

I need the message, go into the debug node and choose complete message object. Then post the output from the trigger node when physically switched and when triggered by motion.

Good Morning,
You have made an interesting observation, and to be honest this has been bugging me as well.
I never understood what the light node meant. Cos all the lights are being turned on by the switches, atleast that is true in my case.
Few of the switches in my house do not show up as switches in node-red but they only show under lights.
These are the same Inovelli or Z-wave switches all over the house. Most light switches will show as switches, but few will show only under lights, when i choose switches under devices in the node red configuration those entities will not show up. Hence i have to use lights.

Debug does not show up in my node-red sidebar, even after i have installed debugger.

In order to set this up - you would need to use data.new_state.context.user_id - when setting the debug node to complete message - expanding the data/new_state/context sections will show user_id.

If the switch is manually turned on it should return “null”

1 Like

Put the light in an event state, don’t define anything else connect it to a debug node

image

Set the debug to:

image

Then choose copy value and post it.

image

First trigger the light with motion, then turn on the switch, post both message.

Triggered with motion.

{"payload":"on","data":{"entity_id":"light.mud_room_lights","old_state":{"entity_id":"light.mud_room_lights","state":"off","attributes":{"supported_color_modes":["brightness"],"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T04:53:08.257196+00:00","last_updated":"2022-02-25T04:53:08.257196+00:00","context":{"id":"85e8d468889771c16055c21b71d478c4","parent_id":null,"user_id":"60c5174b56444dd58a4157e7991a26ee"},"original_state":"off"},"new_state":{"entity_id":"light.mud_room_lights","state":"on","attributes":{"supported_color_modes":["brightness"],"color_mode":"brightness","brightness":52,"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T05:22:57.681344+00:00","last_updated":"2022-02-25T05:22:57.681344+00:00","context":{"id":"bc102a4d75c70071832620cb7d70a750","parent_id":null,"user_id":"60c5174b56444dd58a4157e7991a26ee"},"original_state":"on","timeSinceChangedMs":14}},"topic":"light.mud_room_lights","_msgid":"9255663d8fe5ee5c"}

Triggered with switch.

{"payload":"on","data":{"entity_id":"light.mud_room_lights","old_state":{"entity_id":"light.mud_room_lights","state":"off","attributes":{"supported_color_modes":["brightness"],"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T05:25:58.104320+00:00","last_updated":"2022-02-25T05:25:58.104320+00:00","context":{"id":"5c703d8ab380dc116e32b1dad85d1cfd","parent_id":null,"user_id":null},"original_state":"off"},"new_state":{"entity_id":"light.mud_room_lights","state":"on","attributes":{"supported_color_modes":["brightness"],"color_mode":"brightness","brightness":52,"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T05:26:01.148825+00:00","last_updated":"2022-02-25T05:26:01.148825+00:00","context":{"id":"9e7fde1b9123b3e0769d725ca07f43cf","parent_id":null,"user_id":null},"original_state":"on","timeSinceChangedMs":10}},"topic":"light.mud_room_lights","_msgid":"e854c4ad6d3f40aa"}

@kagetaro99 hit the nail on the head the message is indeed null. There are 2 nodes that you need to complete the entity ID, they are labeled. I added a check so that the motion sensor dosn’t keep telling the switch to turn on if it is on already.

updated:

[{"id":"e433ab36.c6b358","type":"api-call-service","z":"f80b6c338afd5483","name":"Mudroom Lights ON","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1840,"y":3800,"wires":[[]]},{"id":"16bf9a80.ccead6","type":"api-call-service","z":"f80b6c338afd5483","name":"Mud Room Lights OFF","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1840,"y":3960,"wires":[[]]},{"id":"56668319.4c687c","type":"trigger-state","z":"f80b6c338afd5483","name":"Motion Sensor","server":"","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":990,"y":3800,"wires":[["f7c35a29892a7203"],["f7c35a29892a7203"]]},{"id":"279d7f80.57b5d","type":"change","z":"f80b6c338afd5483","name":"ENABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":725,"y":3900,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-on","l":false},{"id":"a2d4c1a6.bb35a","type":"change","z":"f80b6c338afd5483","name":"DISABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":835,"y":3800,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-off","l":false},{"id":"0ffe09c3914bab93","type":"stoptimer","z":"f80b6c338afd5483","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":1570,"y":3880,"wires":[["5660b85435a6eb11"],[]]},{"id":"5660b85435a6eb11","type":"api-current-state","z":"f80b6c338afd5483","name":"Motion Sensor Status","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1840,"y":3880,"wires":[["8fdd7877150f5c27"]]},{"id":"8fdd7877150f5c27","type":"switch","z":"f80b6c338afd5483","name":"Motion Detector Still ON? ","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1590,"y":3960,"wires":[["0ffe09c3914bab93"],["16bf9a80.ccead6"]]},{"id":"f7c35a29892a7203","type":"api-current-state","z":"f80b6c338afd5483","name":"","server":"","version":3,"outputs":2,"halt_if":"below_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1220,"y":3800,"wires":[["0ffe09c3914bab93","5a895141ced15188"],[]]},{"id":"3669b0496d8b225d","type":"server-state-changed","z":"f80b6c338afd5483","name":"Add to light.mud_room_lights to entity","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"device_tracker.pixel_3_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":330,"y":3900,"wires":[["f2fee74cacda5014"]]},{"id":"f2fee74cacda5014","type":"switch","z":"f80b6c338afd5483","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":550,"y":3900,"wires":[["d30edbd5fda2de50"],["279d7f80.57b5d"]]},{"id":"d30edbd5fda2de50","type":"switch","z":"f80b6c338afd5483","name":"","property":"data.new_state.context.user_id","propertyType":"msg","rules":[{"t":"null"}],"checkall":"true","repair":false,"outputs":1,"x":710,"y":3800,"wires":[["a2d4c1a6.bb35a","fbcb3688cfd3569d"]]},{"id":"5a895141ced15188","type":"api-current-state","z":"f80b6c338afd5483","name":"Add to light.mud_room_lights to entity","server":"","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1550,"y":3800,"wires":[["e433ab36.c6b358"],[]]},{"id":"fbcb3688cfd3569d","type":"change","z":"f80b6c338afd5483","name":"stop timer if active","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":3880,"wires":[["0ffe09c3914bab93"]]}]

@Mikefila thank you for showing paitence and helping me out through this.
I have tried the updated script, and yet the response is the same.
Lights turn on with motion and will turn off after x amount of time, but switch override does not work.
I will manually hit the switch button to on, and still the lights will turn off after x amount of time.

As suggested by @kagetaro99 the node config as is as per ur script, or i need to change some value?

@kagetaro99 I understood ur msg late, here is the debug log with motion and with switch.

with motion

{"payload":"on","data":{"entity_id":"light.mud_room_lights","old_state":{"entity_id":"light.mud_room_lights","state":"off","attributes":{"supported_color_modes":["brightness"],"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T07:15:28.521696+00:00","last_updated":"2022-02-25T07:15:28.521696+00:00","context":{"id":"724506d5082998175688d188251e2c4e","parent_id":null,"user_id":"60c5174b56444dd58a4157e7991a26ee"},"original_state":"off"},"new_state":{"entity_id":"light.mud_room_lights","state":"on","attributes":{"supported_color_modes":["brightness"],"color_mode":"brightness","brightness":52,"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T07:32:51.331210+00:00","last_updated":"2022-02-25T07:32:51.331210+00:00","context":{"id":"ac74087b00c99c436cf8465fc21d0ad4","parent_id":null,"user_id":"60c5174b56444dd58a4157e7991a26ee"},"original_state":"on","timeSinceChangedMs":11}},"topic":"light.mud_room_lights","_msgid":"e820887158dceb2e"}

With switch on

{"payload":"on","data":{"entity_id":"light.mud_room_lights","old_state":{"entity_id":"light.mud_room_lights","state":"off","attributes":{"supported_color_modes":["brightness"],"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T07:34:06.737488+00:00","last_updated":"2022-02-25T07:34:06.737488+00:00","context":{"id":"fe339f3cd72c81a0407d144d95ce81ca","parent_id":null,"user_id":null},"original_state":"off"},"new_state":{"entity_id":"light.mud_room_lights","state":"on","attributes":{"supported_color_modes":["brightness"],"color_mode":"brightness","brightness":52,"friendly_name":"Mud Room Lights","supported_features":32},"last_changed":"2022-02-25T07:34:07.752755+00:00","last_updated":"2022-02-25T07:34:07.752755+00:00","context":{"id":"86912ffcc313e4a0db01f5da41dceff3","parent_id":null,"user_id":null},"original_state":"on","timeSinceChangedMs":15}},"topic":"light.mud_room_lights","_msgid":"47a885b3ebcd499e"}

Pls note i have output the log after adding the node data.new_state.context.user_id

@Mikefila
So with the new iteration, the lights will turn on motion but will not turn off with switch override. :frowning:

[{"id":"e433ab36.c6b358","type":"api-call-service","z":"f80b6c338afd5483","name":"Mudroom Lights ON","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1840,"y":3800,"wires":[[]]},{"id":"16bf9a80.ccead6","type":"api-call-service","z":"f80b6c338afd5483","name":"Mud Room Lights OFF","server":"","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.mud_room_lights"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":1840,"y":3960,"wires":[[]]},{"id":"56668319.4c687c","type":"trigger-state","z":"f80b6c338afd5483","name":"Motion Sensor","server":"","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":1,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":true,"x":990,"y":3800,"wires":[["f7c35a29892a7203"],["f7c35a29892a7203"]]},{"id":"279d7f80.57b5d","type":"change","z":"f80b6c338afd5483","name":"ENABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"enable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":725,"y":3900,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-on","l":false},{"id":"a2d4c1a6.bb35a","type":"change","z":"f80b6c338afd5483","name":"DISABLE","rules":[{"t":"set","p":"payload","pt":"msg","to":"disable","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":835,"y":3800,"wires":[["56668319.4c687c"]],"icon":"font-awesome/fa-toggle-off","l":false},{"id":"0ffe09c3914bab93","type":"stoptimer","z":"f80b6c338afd5483","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":1570,"y":3880,"wires":[["5660b85435a6eb11"],[]]},{"id":"5660b85435a6eb11","type":"api-current-state","z":"f80b6c338afd5483","name":"Motion Sensor Status","server":"","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.lumi_lumi_sensor_motion_aq2_d930f806_ias_zone","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":1840,"y":3880,"wires":[["8fdd7877150f5c27"]]},{"id":"8fdd7877150f5c27","type":"switch","z":"f80b6c338afd5483","name":"Motion Detector Still ON? ","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1590,"y":3960,"wires":[["0ffe09c3914bab93"],["16bf9a80.ccead6"]]},{"id":"f7c35a29892a7203","type":"api-current-state","z":"f80b6c338afd5483","name":"","server":"","version":3,"outputs":2,"halt_if":"below_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1220,"y":3800,"wires":[["0ffe09c3914bab93","5a895141ced15188"],[]]},{"id":"3669b0496d8b225d","type":"server-state-changed","z":"f80b6c338afd5483","name":"Add to light.mud_room_lights to entity","server":"","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"device_tracker.pixel_3_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":330,"y":3900,"wires":[["f2fee74cacda5014"]]},{"id":"f2fee74cacda5014","type":"switch","z":"f80b6c338afd5483","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":550,"y":3900,"wires":[["d30edbd5fda2de50"],["279d7f80.57b5d"]]},{"id":"d30edbd5fda2de50","type":"switch","z":"f80b6c338afd5483","name":"","property":"data.new_state.context.user_id","propertyType":"msg","rules":[{"t":"null"}],"checkall":"true","repair":false,"outputs":1,"x":710,"y":3800,"wires":[["a2d4c1a6.bb35a","fbcb3688cfd3569d"]]},{"id":"5a895141ced15188","type":"api-current-state","z":"f80b6c338afd5483","name":"Add to light.mud_room_lights to entity","server":"","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1550,"y":3800,"wires":[["e433ab36.c6b358"],[]]},{"id":"fbcb3688cfd3569d","type":"change","z":"f80b6c338afd5483","name":"stop timer if active","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":3880,"wires":[["0ffe09c3914bab93"]]}]


I feel as though this is being way over engineered - why not create an input_boolean

Then create a flow to have motion control the light turning on/off with the input_boolean located right before the call_service node for the light to turn off

then create another flow to have the input_boolean turn on when the switch is hit

you can set the input_boolean to turn off when the light is turned off - resetting it if you will

Do you mind putting something up quickly and share the code… please.