[NR] Garage lighting, motion and door, aggregation?

Hi,

I am working on a lighting flow for my garage … turning lights on is easy, if either the motion sensor becomes active, or the door contact becomes open, the lights go on.

The part that’s getting me is turning the lights off. I’m looking to have the lights turn off only once both the door is closed and motion is inactive. ie, if either is still in the state that would turn lights on, the lights should remain on.

I’ve been messing with boolean/gate stuff but don’t seem to be able get what I’m seeking. Wondering if I have to break down and script it, which is a whole other learning curve, but oh well.

Try asking Bing chat for a node red flow/function. Worked well for most of my more complex NR issues.

Yeah, I guess I should have thought of that :slight_smile: will give it a shot.

It went the path I was thinking and just scripted it. The script is so compact it’s a little embarrassing, but if you don’t know the language, you don’t know the language :smile:

if (msg.payload.motion_sensor === “inactive” && msg.payload.contact_sensor === “closed”) {
msg.payload = {“light”: “off”};
return msg;
}


here is my flow, either garage door, door to house or the motion switch can turn it on, all odd turn it off.

I removed the TTS reminding me I left doors open
flow:

Summary

[{“id”:“abf3adced1ccd0b0”,“type”:“mqtt out”,“z”:“435c92a78cd0624d”,“name”:“Garage Motion Switch”,“topic”:“zwave/Garage/Garage_Motion_Switch/37/0/targetValue/set”,“qos”:“2”,“retain”:“”,“respTopic”:“”,“contentType”:“”,“userProps”:“”,“correl”:“”,“expiry”:“”,“broker”:“3f792c51bc3d4765”,“x”:1640,“y”:180,“wires”:[]},{“id”:“ce266fb68dbf7f7c”,“type”:“change”,“z”:“435c92a78cd0624d”,“name”:“Turn Off”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“false”,“tot”:“bool”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:1440,“y”:220,“wires”:[[“abf3adced1ccd0b0”]]},{“id”:“1c4ab67afdd8396b”,“type”:“change”,“z”:“435c92a78cd0624d”,“name”:“Turn On”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“true”,“tot”:“bool”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:1440,“y”:160,“wires”:[[“abf3adced1ccd0b0”]]},{“id”:“374179a1098fc906”,“type”:“change”,“z”:“435c92a78cd0624d”,“name”:“STOP”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“stop”,“tot”:“str”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:1170,“y”:160,“wires”:[[“4c38b50ddf2056a6”,“1c4ab67afdd8396b”]]},{“id”:“4c38b50ddf2056a6”,“type”:“stoptimer-varidelay”,“z”:“435c92a78cd0624d”,“duration”:“2”,“durationType”:“num”,“units”:“Minute”,“payloadtype”:“num”,“payloadval”:“0”,“name”:“”,“reporting”:“last_minute_seconds”,“persist”:true,“ignoretimerpass”:false,“x”:1260,“y”:260,“wires”:[[“ce266fb68dbf7f7c”],[],[]]},{“id”:“969c8814374f4be2”,“type”:“switch”,“z”:“435c92a78cd0624d”,“name”:“T/F”,“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“true”},{“t”:“false”}],“checkall”:“true”,“repair”:false,“outputs”:2,“x”:1030,“y”:220,“wires”:[[“374179a1098fc906”],[“4c38b50ddf2056a6”]]},{“id”:“4c7e0ac11f43998c”,“type”:“rbe”,“z”:“435c92a78cd0624d”,“name”:“”,“func”:“rbe”,“gap”:“”,“start”:“”,“inout”:“out”,“septopics”:true,“property”:“payload”,“topi”:“topic”,“x”:890,“y”:220,“wires”:[[“969c8814374f4be2”]]},{“id”:“756a7f972341f7d3”,“type”:“BooleanLogicUltimate”,“z”:“435c92a78cd0624d”,“name”:“”,“payloadPropName”:“payload”,“filtertrue”:“both”,“persist”:true,“sInitializeWith”:“false”,“triggertopic”:“trigger”,“outputtriggeredby”:“all”,“inputCount”:“3”,“topic”:“result”,“restrictinputevaluation”:false,“delayEvaluation”:“”,“x”:710,“y”:220,“wires”:[[],[“4c7e0ac11f43998c”],[]]},{“id”:“daa23d0f77beee25”,“type”:“change”,“z”:“435c92a78cd0624d”,“name”:“Kon to Bool”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“msg.payload= "ON" ? true : false”,“tot”:“jsonata”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:510,“y”:80,“wires”:[[“756a7f972341f7d3”,“a124a9130759d199”]]},{“id”:“ba87fb64d3790cce”,“type”:“mqtt in”,“z”:“435c92a78cd0624d”,“name”:“Laundry Door”,“topic”:“konnectedpro1/binary_sensor/laundry_k_door/state”,“qos”:“2”,“datatype”:“auto”,“broker”:“3f792c51bc3d4765”,“nl”:false,“rap”:true,“rh”:“2”,“inputs”:0,“x”:330,“y”:80,“wires”:[[“daa23d0f77beee25”]]},{“id”:“ec9191788967b74f”,“type”:“mqtt in”,“z”:“435c92a78cd0624d”,“name”:“Garage Motion”,“topic”:“zwave/Garage/Garage_Motion_Switch/113/0/Home_Security/Motion_sensor_status”,“qos”:“2”,“datatype”:“auto”,“broker”:“3f792c51bc3d4765”,“nl”:false,“rap”:true,“rh”:“2”,“inputs”:0,“x”:200,“y”:380,“wires”:[[“d122472e55774fa3”]]},{“id”:“d122472e55774fa3”,“type”:“json”,“z”:“435c92a78cd0624d”,“name”:“”,“property”:“payload”,“action”:“”,“pretty”:false,“x”:390,“y”:380,“wires”:[[“b1abd5127cf4e86f”]]},{“id”:“b1abd5127cf4e86f”,“type”:“change”,“z”:“435c92a78cd0624d”,“name”:“Motion to Bool Zw”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“msg.payload.value = 8 ? true : false”,“tot”:“jsonata”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:550,“y”:380,“wires”:[[“756a7f972341f7d3”,“37ff5dbb607ac6dd”]]},{“id”:“68017fd33c832240”,“type”:“change”,“z”:“435c92a78cd0624d”,“name”:“Set Global”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“payload.value”,“tot”:“msg”},{“t”:“set”,“p”:“GarageDoor”,“pt”:“global”,“to”:“payload.value”,“tot”:“msg”}],“action”:“”,“property”:“”,“from”:“”,“to”:“”,“reg”:false,“x”:530,“y”:440,“wires”:[[“756a7f972341f7d3”,“2ced50b90b728f51”]]},{“id”:“e6b977708ac0d218”,“type”:“json”,“z”:“435c92a78cd0624d”,“name”:“”,“property”:“payload”,“action”:“”,“pretty”:false,“x”:390,“y”:440,“wires”:[[“68017fd33c832240”]]},{“id”:“8260db5f544cf023”,“type”:“mqtt in”,“z”:“435c92a78cd0624d”,“name”:“Garage Main Tilt”,“topic”:“zwave/Garage/Garage_Main_Tilt/48/0/Any”,“qos”:“2”,“datatype”:“auto”,“broker”:“3f792c51bc3d4765”,“nl”:false,“rap”:true,“rh”:“2”,“inputs”:0,“x”:200,“y”:440,“wires”:[[“e6b977708ac0d218”]]},{“id”:“3f792c51bc3d4765”,“type”:“mqtt-broker”,“name”:“CORE Clean1”,“broker”:“10.10.2.1”,“port”:“1883”,“clientid”:“”,“autoConnect”:true,“usetls”:false,“protocolVersion”:“5”,“keepalive”:“60”,“cleansession”:true,“birthTopic”:“”,“birthQos”:“0”,“birthPayload”:“”,“birthMsg”:{},“closeTopic”:“”,“closeQos”:“0”,“closePayload”:“”,“closeMsg”:{},“willTopic”:“”,“willQos”:“0”,“willPayload”:“”,“willMsg”:{},“userProps”:“”,“sessionExpiry”:“”}]

Thanks, I will give it a look.
Rejiggering the AI’s code for my environment hasn’t been going great so far, lol.

copy in this node. Set your globals for the devices and then change the globals to yours and run through this. Boolean do not need quotes. Strings do.

[{"id":"6ffd3385bbe2a0a0","type":"switch","z":"efcd1cf715c69f92","name":"Combined State Check","property":"$globalContext(\"tvbasement\") = false and\t$globalContext(\"bsparebathmotion\") = false and\t$globalContext(\"bsparebathmotion2\") = false and\t$globalContext(\"stairslowermotion\") = false and\t$globalContext(\"blivingmotionw\") = false and\t$globalContext(\"blivingmotione\") = false and\t$globalContext(\"officemonitorpower\") = \"OFF\"","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":2050,"y":460,"wires":[[]]}]

[EDIT]
You need to have your motion set the globals and then trigger the flow like normal. true and false.

That is sounding like you need an OR operation between the two sensors. If either or both are active, light is on, if both are inactive, light is off.

Should be able to do what you need and they have good videos and resources on how to use their nodes. One thing to keep in mind is that when you reboot, unless you are saving the state of all sensors and sending them out when NR comes online, the “buffers” of the logic gate need to fill. There is an option to pre-fill with true or false, so that might be something worth considering depending on your situation.

This is just a quick mockup that I made that shows your situation. You can inject the various states of the sensors and see what the OR output is (middle output). You likely will have to interpret the output and if true/false do different things, but that is simple enough with a switch. You also might have to pre-filter the sensor data so that it is either true or false since the logic gate works best with a binary option set.

This is one option should you not want to mess with function nodes or global variables. It is always my personal preference to use global variables and function nodes only as a last resort as they make understanding after a year and documentation harder.
image

[{"id":"c79bad094d2d7307","type":"BooleanLogicUltimate","z":"95de14ceabf28b50","name":"","payloadPropName":"payload","filtertrue":"both","persist":true,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"light","restrictinputevaluation":true,"delayEvaluation":0,"translatorConfig":"","x":990,"y":240,"wires":[[],["b95d46d47b62b8e2"],[]]},{"id":"b95d46d47b62b8e2","type":"debug","z":"95de14ceabf28b50","name":"debug 32","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1120,"y":240,"wires":[]},{"id":"46525db05bb5bba4","type":"inject","z":"95de14ceabf28b50","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"motion","payload":"true","payloadType":"bool","x":800,"y":180,"wires":[["c79bad094d2d7307"]]},{"id":"370195ae695f8ba5","type":"inject","z":"95de14ceabf28b50","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"motion","payload":"false","payloadType":"bool","x":790,"y":220,"wires":[["c79bad094d2d7307"]]},{"id":"2fdead4d68d56769","type":"inject","z":"95de14ceabf28b50","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"contact","payload":"true","payloadType":"bool","x":790,"y":260,"wires":[["c79bad094d2d7307"]]},{"id":"112b0239716a6c53","type":"inject","z":"95de14ceabf28b50","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"contact","payload":"false","payloadType":"bool","x":790,"y":300,"wires":[["c79bad094d2d7307"]]}]

Side note: I had a topic here that was similar to this kind of situation, but kind of the inverse. It dealt with determining the presence of the room using contact/motion sensors

1 Like