Is there a better way to do this?

Maybe "better" isn't the right word... More native to NR, maybe? I'm trying to avoid dropping to code for everything, but this works...

[{"id":"449c809d.fec43","type":"hubitat hsm","z":"534682e6.98503c","name":"","server":"7b8c3c84.96b724","sendEvent":true,"x":290,"y":920,"wires":[["835c2b09.b329a8","ece7858a.4a4628"]]},{"id":"c78f8c2d.abc9a","type":"hubitat device","z":"534682e6.98503c","deviceLabel":"Garage Tablet","name":"","server":"7b8c3c84.96b724","deviceId":"176","attribute":"motion","sendEvent":true,"x":320,"y":1000,"wires":[["a07fe28e.a25e","9ec24317.a7929"]]},{"id":"835c2b09.b329a8","type":"function","z":"534682e6.98503c","name":"set global.hsm","func":"let value = msg.payload.value.toLowerCase();\nglobal.set('hsm', value);\nif (value.includes('intrusion')) {\n    return msg;\n} else {\n    return null;\n}","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is deployed.\nif (global.get('hsm') == undefined) {\n    global.set('hsm','disarmed');\n}","finalize":"","x":560,"y":920,"wires":[["f3e945fc.a19668"]]},{"id":"70a03fe5.428bb","type":"function","z":"534682e6.98503c","name":"ping on startup","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is deployed.\nnode.send({payload: \"ping\"})","finalize":"","x":110,"y":960,"wires":[["449c809d.fec43","c78f8c2d.abc9a"]]},{"id":"f3e945fc.a19668","type":"function","z":"534682e6.98503c","name":"Pass if both set","func":"if (global.get('hsm').includes('intrusion') && flow.get('motionActive')) {\n    return msg;\n} else {\n    return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":780,"y":960,"wires":[["39094ece.947d22","300f9857.58a578"]]},{"id":"a07fe28e.a25e","type":"function","z":"534682e6.98503c","name":"set flow.motionActive","func":"let active = msg.payload.value == 'active';\nflow.set('motionActive',active);\nif (active) {\n    return msg;\n} else {\n    return null;\n}","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is deployed.\nif (flow.get('motionActive') == undefined) {\n    flow.set('motionActive',false);\n}","finalize":"","x":540,"y":1000,"wires":[["f3e945fc.a19668"]]},{"id":"7b8c3c84.96b724","type":"hubitat config","name":"Hubitat","usetls":false,"host":"192.168.1.29","port":"80","appId":"270","nodeRedServer":"http://192.168.1.23","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false,"colorEnabled":false,"color":"#ace043"}]

Basically I've got my Hubitat System Monitor and a tablet running Fully Kiosk Browser for my dashboard. When the HSM is in one of its "intrusion" modes (i.e. it was armed and a door was opened) AND the tablet senses motion, I want the tablet to capture an image using its camera and send it to me. I got the image capture and sending worked out earlier so I was working on coordinating these 2 states. There's no telling which event will come first, so I'm capturing them into context vars (global for HSM and flow for the motion activity).

So, is this a good way to accomplish this? Also, is my function to send a "ping" on startup a normal way to initialize values from devices so you don't have to wait for events from them?

Thanks

From my perspective it looks like a sensible and node reddish way of doing it. I have similar flows. My only style thing (and I am no one to judge style) is to remove the logic of the internals of the intrusion string from down stream processing by adding another global (or possibly flow variable)

let value = msg.payload.value.toLowerCase();
global.set('hsm', value);

let intrusion = value.includes('intrusion')
global.set('hsmIntrusion', intrusion);
if (intrusion) return msg

1 Like

Just for info
take a look here https://reactor.toggledbits.com/mantisbt/
if you can not get account post here Multi-System Reactor | Smart Home - Community
This is a new multi system logic engine, it is very powerful and runs on any system that runs nodejs.

It is early alpha and so far systems that are integrated are
vera/openluup
hubitat
home assistant

The idea is to bring all controllers and systems under one logic engine.
more controllers and mqtt will also be integrated. It also has a built in dashboard