Buttons and output state

Good evening
I have 9 similar flows for lamps. Each has one UI button and one or more Sonoff buttons.
This works fine. I have add a alarm button who sets all outputs on.
I would memorize the Powerstatus for the 9 outputs before i switch this outputs on.
When i press the alarm button a second time i like to restore the previous settings.
What s a good way to go? Global variable? Array?
Thanks.

What status do you need to remember - is it just on/off or colour and brightness data?

1 Like

Just on /off

My smart devices accept commands "ON", "OFF" and "TOGGLE" so if I wanted to connect them via a dashboard button it could send "TOGGLE", while a PIR sensor would send "ON".
No need to retain the status in NR.

I guess that's dependent on the firmware though.

You can certainly use context storage, though I would try and avoid global variables.
Something like this should work:

[{"id":"69b2dac3e1917348","type":"inject","z":"87ea245182d582ac","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"device1","payload":"ON","payloadType":"str","x":210,"y":300,"wires":[["0d150b7a0d3c1f05"]]},{"id":"f5949197d3fc1659","type":"inject","z":"87ea245182d582ac","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"device1","payload":"OFF","payloadType":"str","x":210,"y":340,"wires":[["0d150b7a0d3c1f05"]]},{"id":"7a71b71604290094","type":"inject","z":"87ea245182d582ac","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"device2","payload":"ON","payloadType":"str","x":210,"y":380,"wires":[["0d150b7a0d3c1f05"]]},{"id":"cfc0099bb19f1ed9","type":"inject","z":"87ea245182d582ac","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"device2","payload":"OFF","payloadType":"str","x":210,"y":420,"wires":[["0d150b7a0d3c1f05"]]},{"id":"e314011742ca2e41","type":"inject","z":"87ea245182d582ac","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"device3","payload":"ON","payloadType":"str","x":210,"y":460,"wires":[["0d150b7a0d3c1f05"]]},{"id":"25de037f09739fd3","type":"inject","z":"87ea245182d582ac","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"device3","payload":"OFF","payloadType":"str","x":210,"y":500,"wires":[["0d150b7a0d3c1f05"]]},{"id":"0d150b7a0d3c1f05","type":"function","z":"87ea245182d582ac","name":"function 2","func":"var status = flow.get('deviceStatus') || {}\nstatus[msg.topic] = msg.payload\nflow.set('deviceStatus', (status))\nmsg.payload = flow.get('deviceStatus')\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":380,"wires":[["73ea2720e7d62d56"]]},{"id":"73ea2720e7d62d56","type":"debug","z":"87ea245182d582ac","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":380,"wires":[]}]

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