On a side project to control a lightbulb - yeah, bit pitiful - with adjustments.
If the bulb is on, any adjustments are done, and you can see the effect.
Alas there is a problem that if the bulb is OFF
and you change the brightness (or other things) it bulb turns ON
.
That isn't too annoying, but I don't like that. To me the adjustments should only work if the bulb is ON
.
This is a bit of a flow I knocked together to accommodate this. Yes, there is an underlying problem but for now..... This is what I have:
(Foreign node required: node-red-contrib-queue-gate
)
[{"id":"b941f136.0105f","type":"q-gate","z":"26262ba1.62dcbc","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","maxQueueLength":"100","keepNewest":false,"qToggle":false,"persist":false,"x":3113,"y":3900,"wires":[["273e9670.7baf5a"]]},{"id":"2ac8ea66.531cde","type":"inject","z":"26262ba1.62dcbc","name":"Normal data","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2850,"y":3900,"wires":[["b941f136.0105f","1200f19c.e4f676"]]},{"id":"273e9670.7baf5a","type":"debug","z":"26262ba1.62dcbc","name":"OUTPUT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":3270,"y":3900,"wires":[]},{"id":"2e87680d.2873b","type":"change","z":"26262ba1.62dcbc","name":"\"Stop\"","rules":[{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2830,"y":3800,"wires":[["b941f136.0105f"]]},{"id":"f807665.0451798","type":"change","z":"26262ba1.62dcbc","name":"\"Go\"","rules":[{"t":"set","p":"payload","pt":"msg","to":"flush","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2830,"y":3840,"wires":[["b941f136.0105f","b064f285.5a01e"]]},{"id":"19b80cc9.762a03","type":"inject","z":"26262ba1.62dcbc","name":"","topic":"","payload":"On","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2830,"y":3680,"wires":[["273e9670.7baf5a","aa4418b6.73fed","b37a5fdd.fc86f"]]},{"id":"c46a811d.743cb8","type":"inject","z":"26262ba1.62dcbc","name":"","topic":"","payload":"Off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2830,"y":3640,"wires":[["273e9670.7baf5a","8e87f280.16ff58","b37a5fdd.fc86f","f1ce66f9.5cf67"]]},{"id":"1200f19c.e4f676","type":"counter","z":"26262ba1.62dcbc","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":2,"x":3120,"y":3860,"wires":[["b37a5fdd.fc86f"],[]]},{"id":"f1ce66f9.5cf67","type":"trigger","z":"26262ba1.62dcbc","op1":"1","op2":"0","op1type":"val","op2type":"val","duration":"250","extend":"false","units":"ms","reset":"","bytopic":"all","name":"","x":3130,"y":3640,"wires":[["2e87680d.2873b"]]},{"id":"8e87f280.16ff58","type":"change","z":"26262ba1.62dcbc","name":"Stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2830,"y":3720,"wires":[["b941f136.0105f"]]},{"id":"aa4418b6.73fed","type":"change","z":"26262ba1.62dcbc","name":"Go","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2830,"y":3760,"wires":[["b941f136.0105f"]]},{"id":"b37a5fdd.fc86f","type":"function","z":"26262ba1.62dcbc","name":"","func":"var counter = context.get(\"counter\") || 0;\nif (msg.payload === 0)\n{\n context.set(\"counter\",0);\n node.status({fill: \"green\",text:\"Wiped\"});\n}\nelse\nif (msg.payload == \"On\")\n{\n //\n context.set(\"SKIP\",1);\n node.status({fill: \"blue\",text:\"Open\"});\n msg.payload = \"flush\";\n return msg;\n}\nelse\nif (msg.payload == \"Off\")\n{\n node.status({fill: \"red\",text:\"Queue\"});\n context.set(\"SKIP\",0);\n return;\n}\n{\n if (context.get(\"SKIP\") == 0)\n {\n node.status({text:counter + 1});\n context.set(\"counter\",counter + 1)\n }\n}\n//return msg;","outputs":1,"noerr":0,"x":3260,"y":3810,"wires":[["a2c673cb.bdbca"]]},{"id":"a2c673cb.bdbca","type":"link out","z":"26262ba1.62dcbc","name":"","links":["44933f09.b93388"],"x":3375,"y":3810,"wires":[]},{"id":"44933f09.b93388","type":"link in","z":"26262ba1.62dcbc","name":"","links":["a2c673cb.bdbca"],"x":2735,"y":3840,"wires":[["f807665.0451798"]]},{"id":"7e19ba21.83d6b4","type":"comment","z":"26262ba1.62dcbc","name":"Press On before doing anything!","info":"","x":2870,"y":3590,"wires":[]},{"id":"b064f285.5a01e","type":"change","z":"26262ba1.62dcbc","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2980,"y":3840,"wires":[["1200f19c.e4f676"]]}]
Instructions:
Press the On
(inject) node near the top - as said in the comments node.
That is needed to set things up.
Then click the Normal data
(inject) node at the bottom.
You will see that being echoed in the OUTPUT
node.
Now, press the Off
node.
Click the Normal data
node a couple of times to simulate the values being adjusted while the bulb is off.
Then click the On
node again.
The On message is sent and then all the saved values.
It works.
But is there another way?
Without making it a Rocket science project of course.