Help with a flow - Node Red - understanding boolean and ultimate boolean node

I missed the ! in the second property. I see that now. I'll have to look more closely at this.

So if the lock just gets unlocked for some reason, do I just add it to the mix, then? in the front of the flow.

The foyer lock? If it comes unlocked, do you want it to relock?

yah

So create a foyer lock device node, attach the output to a switch node, checking for unlocked. Attach the output of the switch node to the input of your foyer door closed device. Now when the lock unlocks, the flow will get triggered and check to see if it should be unlocked

BUT, now the automation that unlocks itself will run a second time, should not be an issue, however...

ahkay ... clicking

I have a boolean flow I can post later, if your looking at boolean ideas!

1 Like

I saw that there was an unlock automation in there. I understood at least that much :grin:, but I don't think I necessarily need that part in the automation as the lock has one touch entry. (Alfred) ...
But, understanding the flow is important to me. So can you explain the logic of the node?

Love to see it. I have a more complex rule that I want to move and I have no idea where to begin with it. So understanding this logic will be beneficial. Thanks!

Can this magical boolean block do something such as "If any 2 of these 5 devices are true"?

I don't know. But I do know that there is a counter node (which I use) for exactly that purpose.

Edit - thinking about it some more, it can also be done with 3 of these boolean nodes

1 Like

@aaiyar Thank you!! Completely unrelated to this topic but my goal is to reproduce the presence governor app in Node-Red

@april.brandt I haven't seen this yet, but the cancelable part is pretty easy with the use of the stop-timer node.

My lock flows aren't nearly as complex as what you're looking to do but it does give you a good idea of how to make things cancelable. If I unlock a door it starts a timer to relock the door. When the door is locked before the timer is up, it goes to a change node to change the payload to STOP which cancels the timer. If the door opens, it also cancels the timer and then when the door closes again it restarts the timer.

1 Like

Ha! That is exactly what I use the counter node for. Would you like a copy of my sequence?

1 Like

OMG yes please!!!

1 Like

Here you go:

(there's a few extraneous nodes in there that were there for debugging - you can remove those. Also, I send present/not-present via MQTT because I also record that elsewhere. Unless you need that, you can directly change the status of a virtual presence sensor).

Presence using multiple sensors in Node-RED

[{"id":"470f26b6.c11678","type":"switch","z":"7801b673.390478","name":"not present","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"not present","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":910,"y":220,"wires":[["371c30a.7e4945"]]},{"id":"a8b6aedd.61db28","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Combined Presence","server":"662851c4.3ccad","deviceId":"2475","attribute":"presence","sendEvent":false,"x":680,"y":220,"wires":[["470f26b6.c11678"]]},{"id":"371c30a.7e4945","type":"change","z":"7801b673.390478","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":220,"wires":[["3b69a608.1cc852"]]},{"id":"d7201834.70334","type":"switch","z":"7801b673.390478","name":"Present","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"present","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":440,"y":220,"wires":[["a8b6aedd.61db28"]]},{"id":"11de496f.80a9bf","type":"switch","z":"7801b673.390478","name":"Ashok's lock code","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"Ashok Aiyar","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":352,"wires":[["a8b6aedd.61db28"]]},{"id":"3b69a608.1cc852","type":"counter","z":"7801b673.390478","name":"Present Counter","init":"0","step":"1","lower":"0","upper":"1","mode":"increment","outputs":1,"x":1300,"y":220,"wires":[["21a448a9.26b468"]]},{"id":"9b7ee094.db5d48","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Google WiFi Presence","server":"662851c4.3ccad","deviceId":"3952","attribute":"presence","sendEvent":true,"x":170,"y":232,"wires":[["d7201834.70334"]]},{"id":"7f4b6bff.929564","type":"hubitat device","z":"7801b673.390478","name":"Ashok's OwnTracks Presence","server":"662851c4.3ccad","deviceId":"4554","attribute":"presence","sendEvent":true,"x":170,"y":172,"wires":[["d7201834.70334"]]},{"id":"842c9e17.ee4f18","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Life360 Presence","server":"a22e0ea9.276dc8","deviceId":"1826","attribute":"presence","sendEvent":true,"x":180,"y":292,"wires":[["d7201834.70334"]]},{"id":"43119af.0314764","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Car Presence","server":"a22e0ea9.276dc8","deviceId":"1831","attribute":"presence","sendEvent":true,"x":200,"y":112,"wires":[["d7201834.70334"]]},{"id":"56332161.30f4d","type":"hubitat device","z":"7801b673.390478","name":"Front Door Lock","server":"a22e0ea9.276dc8","deviceId":"1219","attribute":"lastCodeName","sendEvent":true,"x":200,"y":352,"wires":[["11de496f.80a9bf"]]},{"id":"21a448a9.26b468","type":"change","z":"7801b673.390478","name":"del msg.reset","rules":[{"t":"delete","p":"reset","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1435,"y":220,"wires":[["6788bebf.037958"]],"l":false},{"id":"ea10b5d9.728558","type":"change","z":"7801b673.390478","name":"msg.reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1235,"y":160,"wires":[["3b69a608.1cc852"]],"l":false},{"id":"6788bebf.037958","type":"switch","z":"7801b673.390478","name":"=1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1550,"y":220,"wires":[["4023baec.6f3c9c"]]},{"id":"9eded407.c1aaf","type":"switch","z":"7801b673.390478","name":"+1/-2","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"-2","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":890,"y":420,"wires":[["1a32adc.fc9e152","ea10b5d9.728558","121247cb.6fae6"],["6093e85d.711e6","ea10b5d9.728558","121247cb.6fae6"]]},{"id":"4023baec.6f3c9c","type":"mqtt out","z":"7801b673.390478","name":"presence","topic":"presence","qos":"0","retain":"false","broker":"40144fb8.a1c1e","x":1700,"y":220,"wires":[]},{"id":"1a32adc.fc9e152","type":"change","z":"7801b673.390478","name":"Present","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"Present","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":400,"wires":[["95683c65.399598"]]},{"id":"121247cb.6fae6","type":"change","z":"7801b673.390478","name":"msg.reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1215,"y":660,"wires":[["27635e2a.bef5b2"]],"l":false},{"id":"6093e85d.711e6","type":"change","z":"7801b673.390478","name":"Not Present","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"Not Present","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":440,"wires":[["4dfc03c3.c6fe14"]]},{"id":"965316c7.eca588","type":"mqtt in","z":"7801b673.390478","name":"presence","topic":"presence","qos":"0","datatype":"auto","broker":"40144fb8.a1c1e","x":740,"y":420,"wires":[["9eded407.c1aaf"]]},{"id":"95683c65.399598","type":"hubitat command","z":"7801b673.390478","name":"Ashok's Combined Presence ARRIVED","server":"662851c4.3ccad","deviceId":"2475","command":"arrived","commandArgs":"","x":1620,"y":400,"wires":[[]]},{"id":"27635e2a.bef5b2","type":"counter","z":"7801b673.390478","name":"Not Present Counter","init":"0","step":"1","lower":"-2","upper":"0","mode":"decrement","outputs":1,"x":1300,"y":600,"wires":[["ea16d571.a7315"]]},{"id":"4dfc03c3.c6fe14","type":"delay","z":"7801b673.390478","name":"3 mins","pauseType":"delay","timeout":"3","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1290,"y":440,"wires":[["aa0dc948.0f63d"]]},{"id":"ea16d571.a7315","type":"change","z":"7801b673.390478","name":"del msg.reset","rules":[{"t":"delete","p":"reset","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"count","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1455,"y":600,"wires":[["63e1dfb5.e25df8"]],"l":false},{"id":"33e16ecc.be1392","type":"change","z":"7801b673.390478","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":600,"wires":[["27635e2a.bef5b2"]]},{"id":"aa0dc948.0f63d","type":"change","z":"7801b673.390478","name":"del msg.reset","rules":[{"t":"delete","p":"reset","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1395,"y":440,"wires":[["a888e775.40695"]],"l":false},{"id":"63e1dfb5.e25df8","type":"switch","z":"7801b673.390478","name":"=(-)2","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"-2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1550,"y":600,"wires":[["46f1c0a1.5d3e18"]]},{"id":"b4c940e.16d134","type":"switch","z":"7801b673.390478","name":"present","property":"payload.value","propertyType":"msg","rules":[{"t":"eq","v":"present","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":900,"y":600,"wires":[["33e16ecc.be1392"]]},{"id":"a888e775.40695","type":"hubitat command","z":"7801b673.390478","name":"Ashok's Combined Presence DEPARTED","server":"662851c4.3ccad","deviceId":"2475","command":"departed","commandArgs":"","x":1620,"y":440,"wires":[[]]},{"id":"46f1c0a1.5d3e18","type":"mqtt out","z":"7801b673.390478","name":"presence","topic":"presence","qos":"0","retain":"false","broker":"40144fb8.a1c1e","x":1700,"y":600,"wires":[]},{"id":"b656f364.60d798","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Combined Presence","server":"662851c4.3ccad","deviceId":"2475","attribute":"presence","sendEvent":false,"x":680,"y":600,"wires":[["b4c940e.16d134"]]},{"id":"214896e5.da306a","type":"switch","z":"7801b673.390478","name":"Not Present","property":"payload.value","propertyType":"msg","rules":[{"t":"regex","v":"not present","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":601,"wires":[["b656f364.60d798"]]},{"id":"32d087d9.81f5a8","type":"hubitat device","z":"7801b673.390478","name":"Ashok's OwnTracks Presence","server":"662851c4.3ccad","deviceId":"4554","attribute":"presence","sendEvent":true,"x":170,"y":572,"wires":[["214896e5.da306a"]]},{"id":"b7950610.08f2c8","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Life360 Presence","server":"a22e0ea9.276dc8","deviceId":"1826","attribute":"presence","sendEvent":true,"x":180,"y":632,"wires":[["214896e5.da306a"]]},{"id":"ce4be11d.ee587","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Car Presence","server":"a22e0ea9.276dc8","deviceId":"1831","attribute":"presence","sendEvent":true,"x":200,"y":512,"wires":[["214896e5.da306a"]]},{"id":"fe1e0d65.1212d8","type":"hubitat device","z":"7801b673.390478","name":"Ashok's Google WiFi Presence","server":"662851c4.3ccad","deviceId":"3952","attribute":"presence","sendEvent":true,"x":170,"y":692,"wires":[["214896e5.da306a"]]},{"id":"662851c4.3ccad","type":"hubitat config","z":"","name":"HubitatS","usetls":false,"host":"192.168.1.36","port":"80","appId":"4489","nodeRedServer":"http://192.168.1.4:1880","webhookPath":"/hubitat/webhook2","autoRefresh":true},{"id":"a22e0ea9.276dc8","type":"hubitat config","z":"","name":"HubitatM","usetls":false,"host":"192.168.1.46","port":"80","appId":"1522","nodeRedServer":"http://192.168.1.4:1880","webhookPath":"/hubitat/webhook","autoRefresh":true},{"id":"40144fb8.a1c1e","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":false,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","closeTopic":"","closeRetain":"false","closePayload":"","willTopic":"","willQos":"0","willRetain":"false","willPayload":""}]

1 Like

Now THAT stop timer and delay, I learned early on from @aaiyar. Sometimes I find that setting up the nodes is confusing and some of the documentation does not help me to understand what's going on. So seeing it used in a flow has been a tremendous help.

1 Like
  1. Red section - This section is your inputs, send events is on, so when any of these change state the flow gets run. the msg.topic comes from the event generation and this is important in the boolean logic.
  2. Blue section - check the inputs for what we want the inputs to be to set the output, (doors closed, locks locked, etc) then we send to the correct state (true or false) in. msg.topic is still the device name for the event generated in section 1.
  3. Aqua section - Logic happens here. what we want as states becomes a true, if it isn't in the state we want it becomes a false. The msg.topic + the true/false comes in from the set True/False blocks to the Ultimate logic block. We have it set to 4 topics since w expect 4 different event topics. The 3 outputs (and, or, Xor) are set after it evaluates all of the last known states it had come in from each event type(msg.topic). And (all are true for it to go to true), or *any are true for it to go to true, Xor(2 topics only) both topics are different. We are using only the And in this case, so all of your inputs(msg.topics) were last seen as true will set the top output of the boolean block to true. We then check in the is true switch to determine which way to go in section 4.
  4. Lime - Lock or unlock if the previous section was true or false. We do a check to see if we are already in the state (note send event is off in the device blocks) and then lock or unlock if we are not in the desired state, trying to lessen the communications load if needed.

3 Likes

I have an observation... I tried it via Virtual Devices and I'm never getting anything but false out of Ultimate:

Three debugs, just to make what's going on is clearer... in the resulting debug messages, the top two are False + false.. because I set the Front Door to Open. And thus False + false is correct. But then I changed Front Door to Closed and got the True payload, but Ultimate still sent a False. You can see the current device states on the Left.. they are all "correct"

It's due to the uninitialized state being equal to False. Every device has to be 'cycled' once with every Deploy, to set the Ultimate Boolean with the initial state. I added a 'start up initialize' injection and it works as expected now.

Once all 4 Devices are 'injected' the final output goes True. Just to be clear, it's an observation, NOT a critique. :slight_smile:

2 Likes

Can you show how you set up the inject node?
What happens if I choose to do nothing with false?

Screen Shot 2020-06-13 at 3.36.17 PM

It's not my 'idea' -- I found it in someone else's shared Flow. If I'm not mistaken, I first saw it with setting a Global Mode variable:

Screen Shot 2020-06-13 at 3.40.36 PM

1 Like

that's where I saw it too. I don't put two and two together sometimes like that would work anywhere else. That would explain why I'm not getting my lock to act, though. But still trying to understand the concept of the boolean logic. The responses have helped tremendously.
Thanks for the lesson. Got any more for me?