Hello,
I'm quite confident programmer, but as well quite new to node-red so I can solve my issue in other programming languages, but in nodered i need bit of help.
I have let's say two different MQTT topics, which I need to have synced when CMND is received (they are 2way switches with tasmota - it's not really important).
I have something like
home/switch1/state/POWER ON
home/switch2/state/POWER ON
when one switch receives CMND like this
home/switch1/cmnd/POWER OFF
I do need to sync 2nd topic with command option as well
home/switch2/cmnd/POWER OFF
So I've done this flow, which is doing exactly what I want:
[{"id":"de00f0ac.25ef","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"9f39a99.521b058","type":"mqtt in","z":"de00f0ac.25ef","name":"Hall Stairs","topic":"home/hallfloor/light/stat/POWER2","qos":"0","datatype":"utf8","broker":"e1def315.bf1db","x":120,"y":80,"wires":[["24d6ec68.e0a4d4","ea60d3cf.40c1f"]]},{"id":"39f7f1dc.cfe82e","type":"mqtt in","z":"de00f0ac.25ef","name":"Stairs (slave)","topic":"home/staircase/light/stat/POWER","qos":"0","datatype":"utf8","broker":"e1def315.bf1db","x":110,"y":120,"wires":[["ea60d3cf.40c1f","24d6ec68.e0a4d4"]]},{"id":"2923a833.269348","type":"change","z":"de00f0ac.25ef","name":"store","rules":[{"t":"set","p":"state-hall-pwr2","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":80,"wires":[[]]},{"id":"24d6ec68.e0a4d4","type":"switch","z":"de00f0ac.25ef","name":"state","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"state-hall-pwr2","vt":"flow"},{"t":"neq","v":"state-hall-pwr2","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":80,"wires":[["2923a833.269348"],["2923a833.269348","dc735068.855ce"]]},{"id":"ea60d3cf.40c1f","type":"switch","z":"de00f0ac.25ef","name":"state","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"state-stairs","vt":"flow"},{"t":"neq","v":"state-stairs","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":120,"wires":[["2231f9a.286b906"],["2231f9a.286b906","c7485e32.69b55"]]},{"id":"2231f9a.286b906","type":"change","z":"de00f0ac.25ef","name":"store","rules":[{"t":"set","p":"state-stairs","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":120,"wires":[[]]},{"id":"dc735068.855ce","type":"mqtt out","z":"de00f0ac.25ef","name":"CMND","topic":"home/hallfloor/light/cmnd/POWER2","qos":"","retain":"","broker":"e1def315.bf1db","x":530,"y":60,"wires":[]},{"id":"c7485e32.69b55","type":"mqtt out","z":"de00f0ac.25ef","name":"CMND","topic":"home/staircase/light/cmnd/POWER","qos":"","retain":"","broker":"e1def315.bf1db","x":530,"y":100,"wires":[]},{"id":"e1def315.bf1db","type":"mqtt-broker","z":"","name":"MQTT","broker":"10.10.1.10","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
But sometimes what is happening is rapid switching between on/off . It's not very often, but sometimes it for some not really clear reason does this. Eventho mqtt does not received CMND on and on other topic CMND off at same time.
Maybe there is sometimes some lag or smthing which causes it sometimes, dunno.
What I need to make sure somehow is, this flow will happen only once per like 3seconds or I do need to figure out some kind of safety check so one state will not override received CMND. Basically at any given time i need to have both mqtt topic synced ON or OFF.
In 99% of the time this flow works as I need to, so debugging is quite hard why it is sometimes starts rapid switching.
Any idea would be really appreciated.
Thanks