Another way to arrange this flow?

Hi all,

This flow is working, but it feels like there's a simpler way of doing it with nodes (i.e. not a function).

I've singled out the payload as the rbe node does not work otherwise, as the payload is constantly changing due to other values such as link value, battery. etc.

Any suggestions?

[{"id":"d91206ee.43a908","type":"comment","z":"bd52b987.d668e8","name":"true = leak, false = ok","info":"","x":790,"y":4140,"wires":[]},{"id":"93e5dfee.18da9","type":"switch","z":"bd52b987.d668e8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":770,"y":4190,"wires":[["d4262d3d.cf7c9"],["88e53516.9ca5d8"]]},{"id":"d4262d3d.cf7c9","type":"moment","z":"bd52b987.d668e8","name":"Timestamp & true","topic":"","input":"payload.fake","inputType":"msg","inTz":"Europe/London","adjAmount":0,"adjType":"days","adjDir":"add","format":"dddd DD/MM/YY HH:mm  -  [Water leak detected in garage]","locale":"en_GB","output":"","outputType":"msg","outTz":"Europe/London","x":1010,"y":4180,"wires":[["1f585a9a.c7d095"]]},{"id":"27a264c1.9bc91c","type":"comment","z":"bd52b987.d668e8","name":"rate limiter","info":"","x":620,"y":4140,"wires":[]},{"id":"245595b0.7ef59a","type":"rbe","z":"bd52b987.d668e8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":620,"y":4190,"wires":[["93e5dfee.18da9"]]},{"id":"88e53516.9ca5d8","type":"moment","z":"bd52b987.d668e8","name":"Timestamp & false","topic":"","input":"payload.fake","inputType":"msg","inTz":"Europe/London","adjAmount":0,"adjType":"days","adjDir":"add","format":"dddd DD/MM/YY HH:mm  -  [Garage is dry - no water detected]","locale":"en_GB","output":"","outputType":"msg","outTz":"Europe/London","x":1010,"y":4220,"wires":[["1f585a9a.c7d095"]]},{"id":"ede08082.b30c","type":"comment","z":"bd52b987.d668e8","name":"Add timestamp and message","info":"","x":1020,"y":4140,"wires":[]},{"id":"b90cafb8.59447","type":"change","z":"bd52b987.d668e8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.water_leak","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":4190,"wires":[["245595b0.7ef59a"]]},{"id":"79fff1d5.d4027","type":"inject","z":"bd52b987.d668e8","name":"Test water sensor - FALSE","topic":"zigbee2mqtt/test","payload":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":false}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":4170,"wires":[["b90cafb8.59447"]]},{"id":"1f585a9a.c7d095","type":"debug","z":"bd52b987.d668e8","name":"Debug - notification","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1250,"y":4190,"wires":[]},{"id":"166f441f.6ac55c","type":"inject","z":"bd52b987.d668e8","name":"Test water sensor - TRUE","topic":"zigbee2mqtt/test","payload":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":true}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":4210,"wires":[["b90cafb8.59447"]]},{"id":"76d4dde5.0e69c4","type":"comment","z":"bd52b987.d668e8","name":"Single out payload","info":"","x":440,"y":4140,"wires":[]},{"id":"b83ea8b4.c7ea58","type":"comment","z":"bd52b987.d668e8","name":"Xiaomi water leak sensor","info":"","x":180,"y":4130,"wires":[]}]

Something like this.

[{"id":"c249e4e7.510f8","type":"inject","z":"8d22ae29.7df6d","name":"Test water sensor - FALSE","props":[{"p":"payload","v":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":false}","vt":"json"},{"p":"topic","v":"zigbee2mqtt/test","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"zigbee2mqtt/test","payload":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":false}","payloadType":"json","x":230,"y":2680,"wires":[["e4392b1.a536158"]]},{"id":"e4392b1.a536158","type":"rbe","z":"8d22ae29.7df6d","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":350,"y":2760,"wires":[["67933290.40744c"]]},{"id":"d1a9ee04.6fd39","type":"inject","z":"8d22ae29.7df6d","name":"Test water sensor - TRUE","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"zigbee2mqtt/test","payload":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":true}","payloadType":"json","x":210,"y":2800,"wires":[["e4392b1.a536158"]]},{"id":"67933290.40744c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.water_leak = true ? (\t   $moment().tz(\"London/Euroupe\").format(\"dddd DD/MM/YY HH:mm\") & \" Water leak detected garage\"\t) : (\t   $moment().tz(\"London/Euroupe\").format(\"dddd DD/MM/YY HH:mm\") & \" Garage is dry - no water detected\"\t) ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":2760,"wires":[["f77fee11.5d549"]]},{"id":"f77fee11.5d549","type":"debug","z":"8d22ae29.7df6d","name":"Debug - notification","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":2760,"wires":[]},{"id":"fe74c0b7.3a41a8","type":"comment","z":"8d22ae29.7df6d","name":"Xiaomi water leak sensor","info":"","x":120,"y":2710,"wires":[]},{"id":"8a0228b8.4ae95","type":"comment","z":"8d22ae29.7df6d","name":"rate limiter","info":"","x":330,"y":2720,"wires":[]},{"id":"d254f344.52bd58","type":"comment","z":"8d22ae29.7df6d","name":"Single out payload","info":"","x":560,"y":2720,"wires":[]}]
1 Like

Thank you, I’ll try when I get home again :+1:

Hmm that does not work for me, I get an error:
Invalid JSONata expression: Attempted to invoke a non-function

Plus as the real incoming sensor payload is constantly changing (due to other values such as link value, battery. etc.), the rbe node would not work there.

But I like the look of the J expression, I suppose if going down that route I may as well use a function node. I'm just trying to keep it as simple as possible for 'future me'.

What is your node-red version? you would need version 1.1 or higher
Or
here is same thing without using $moment()

[{"id":"c249e4e7.510f8","type":"inject","z":"8d22ae29.7df6d","name":"Test water sensor - FALSE","props":[{"p":"payload","v":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":false}","vt":"json"},{"p":"topic","v":"zigbee2mqtt/test","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"zigbee2mqtt/test","payload":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":false}","payloadType":"json","x":230,"y":2680,"wires":[["e4392b1.a536158"]]},{"id":"e4392b1.a536158","type":"rbe","z":"8d22ae29.7df6d","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload.water_leak","x":350,"y":2760,"wires":[["67933290.40744c"]]},{"id":"d1a9ee04.6fd39","type":"inject","z":"8d22ae29.7df6d","name":"Test water sensor - TRUE","props":[{"p":"payload","v":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":true}","vt":"json"},{"p":"topic","v":"zigbee2mqtt/test","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"zigbee2mqtt/test","payload":"{\"battery\":100,\"battery_low\":false,\"linkquality\":94,\"tamper\":false,\"voltage\":3025,\"water_leak\":true}","payloadType":"json","x":210,"y":2800,"wires":[["e4392b1.a536158"]]},{"id":"67933290.40744c","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.water_leak = true ? (\t   $fromMillis($millis(),\"[F] [M01]/[D01]/[Y0001] [H01]:[m01]\") & \" Water leak detected garage\"\t) : (\t   $fromMillis($millis(),\"[F] [M01]/[D01]/[Y0001] [H01]:[m01]\") & \" Garage is dry - no water detected\"\t) ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":2760,"wires":[["f77fee11.5d549"]]},{"id":"f77fee11.5d549","type":"debug","z":"8d22ae29.7df6d","name":"Debug - notification","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":810,"y":2760,"wires":[]}]

p.s. Added msg.payload.water_leak in rbe so only monitoring water_leak for change.

Ah yes I'm still on 1.03, I need to update at some point..

That works great now, thank you :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.