Hi
I’m thinking about making a flow where when a button is pushed, the light turns red.
But when the button is pushed again, I want the light to go back to the current state, whatever that was.
So I have capture the complete msg.data.attributes object in a variable in a function node, and so far so good.
But what is the syntax to paste / parse that variable in it’s entirety into a call service node to put the light back to it’s original state?
The flow so far is this:
[{"id":"ffc5c22f17e90fe4","type":"tab","label":"Flow 22","disabled":false,"info":"","env":[]},{"id":"62af3c91595b016d","type":"api-current-state","z":"ffc5c22f17e90fe4","name":"Capture current state","server":"c20c4f32.3a7de","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.tv_krok_spot_1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":840,"y":400,"wires":[["a51b73e4f42d446c","d4ef3070776959a5","2231cb5c4a0e101f"]]},{"id":"a51b73e4f42d446c","type":"debug","z":"ffc5c22f17e90fe4","name":"Capture state","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"data.attributes","targetType":"msg","statusVal":"","statusType":"auto","x":1120,"y":400,"wires":[]},{"id":"4d52ab6c12310e9a","type":"inject","z":"ffc5c22f17e90fe4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":640,"y":400,"wires":[["62af3c91595b016d"]]},{"id":"d4ef3070776959a5","type":"function","z":"ffc5c22f17e90fe4","name":"Store Current State","func":"flow.set('current_state', msg.data.attributes);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":460,"wires":[[]]},{"id":"d83f66bd8c45983b","type":"function","z":"ffc5c22f17e90fe4","name":"Return Current State","func":"var x = flow.get('current_state');\nmsg={payload:x};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":540,"wires":[["32fda9542702dea6","0809a67d83ea097d"]]},{"id":"662a36ca01b91338","type":"inject","z":"ffc5c22f17e90fe4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":640,"y":540,"wires":[["d83f66bd8c45983b"]]},{"id":"32fda9542702dea6","type":"debug","z":"ffc5c22f17e90fe4","name":"Return state","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":620,"wires":[]},{"id":"2231cb5c4a0e101f","type":"api-call-service","z":"ffc5c22f17e90fe4","d":true,"name":"Set Color to RED","server":"c20c4f32.3a7de","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.tv_krok_spot_1","data":" {\"color_name\": \"Red\"} ","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1130,"y":340,"wires":[[]]},{"id":"0809a67d83ea097d","type":"api-call-service","z":"ffc5c22f17e90fe4","name":"Set previous state","server":"c20c4f32.3a7de","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.tv_krok_spot_1","data":" {{payload}}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1130,"y":540,"wires":[[]]},{"id":"c20c4f32.3a7de","type":"server","name":"Home Assistant - Min","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]
Any ideas?
Thanks.