How can i save multiple WLED Presets in Previous State in 1 automation and then restore

so i have 1 automation that i testing with a pumpkin head i have LED

so i have a preset… and when the automation runs it saves the preset and the state if its on or off… runs for 20 seconds running a different preset… and then restores the previous state whatever that previous preset… and if its on or off… as its easier to do preset then the limited options in the wled node…

problem is its ok for 1… but i cant seem to figure out how to make it work for say 20 wleds to save each preset then restore the previous preset…

now i also noticed if i duplicate my automation to do just do 2 different ones… because i guess i have msg.preset for both automations it buggers things up… i guess the preset is global in the flow

now back in 90s when i programmed in gwbasic etc i used dim shares to save multiple settings… and i guess you might use that function node now a days…

but i have no idea… i though putting all the wled’s in 1 group for preset, and online state but that didnt work

what would be the easiest so your not multiplying the automation 100 times as this specific automation is for when an incomming call comes in i want it to set all the 20 say wleds to “incoming call” preset like i already have… and then after 20 seconds it restores the previous state for all 20 wleds…

for now i only can do 1…

here is my code

[{"id":"e934eb2147ee44c0","type":"link in","z":"b511d8822e5a6efc","name":"LED Strips In","links":["4b56e51bf617e996"],"x":65,"y":640,"wires":[["11179c754de12c35","b474bf4c7827cc40"]]},{"id":"3982ce50fa4a96ad","type":"api-call-service","z":"b511d8822e5a6efc","name":"Wled - Incoming Call","server":"915baa48.9b1898","version":7,"debugenabled":false,"action":"select.select_option","floorId":[],"areaId":[],"deviceId":[],"entityId":["select.pumpkin_head_1_preset"],"labelId":[],"data":"{\t    \"option\": \"Incoming Call\"\t\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":true,"domain":"select","service":"select_option","x":450,"y":640,"wires":[["ac80364ff12b5cd2"]]},{"id":"11179c754de12c35","type":"api-current-state","z":"b511d8822e5a6efc","name":"Light current state","server":"915baa48.9b1898","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.pumpkin_head_1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"light_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":220,"y":620,"wires":[["3982ce50fa4a96ad","15a7e824e1049a28"]]},{"id":"264c3a4121991d4e","type":"inject","z":"b511d8822e5a6efc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":780,"wires":[["11179c754de12c35","b474bf4c7827cc40"]]},{"id":"d76e8f95bb91fdec","type":"switch","z":"b511d8822e5a6efc","name":"previously on or off?","property":"light_data.state","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":800,"wires":[["56ed747605874a61"],["c06fdc411f0b89aa"]]},{"id":"ac80364ff12b5cd2","type":"delay","z":"b511d8822e5a6efc","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":410,"y":700,"wires":[["5dea7a3f185b67af"]]},{"id":"5dea7a3f185b67af","type":"change","z":"b511d8822e5a6efc","name":"switch flow. back to msg.","rules":[{"t":"set","p":"palette","pt":"msg","to":"palette","tot":"flow"},{"t":"set","p":"light_data","pt":"msg","to":"light_data","tot":"flow"},{"t":"set","p":"preset","pt":"msg","to":"preset","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":760,"wires":[["d76e8f95bb91fdec"]]},{"id":"b474bf4c7827cc40","type":"api-current-state","z":"b511d8822e5a6efc","name":"Light Preset","server":"915baa48.9b1898","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"select.pumpkin_head_1_preset","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"preset","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","x":220,"y":680,"wires":[["3982ce50fa4a96ad","0ee60871fc9b3929"]]},{"id":"0ee60871fc9b3929","type":"change","z":"b511d8822e5a6efc","name":"save preset to flow.","rules":[{"t":"set","p":"preset","pt":"flow","to":"preset","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":540,"wires":[[]]},{"id":"15a7e824e1049a28","type":"change","z":"b511d8822e5a6efc","name":"save light data to flow.","rules":[{"t":"set","p":"light_data","pt":"flow","to":"light_data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":580,"wires":[[]]},{"id":"56ed747605874a61","type":"api-call-service","z":"b511d8822e5a6efc","name":"Previous Preset","server":"915baa48.9b1898","version":7,"debugenabled":false,"action":"select.select_option","floorId":[],"areaId":[],"deviceId":[],"entityId":["select.pumpkin_head_1_preset"],"labelId":[],"data":"{\t   \"option\": msg.preset\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"select","service":"select_option","output_location":"","output_location_type":"none","x":740,"y":780,"wires":[["4e02023ab606d8e2"]]},{"id":"077885883d099ff1","type":"comment","z":"b511d8822e5a6efc","name":"Incoming Calls Notification LED Pumpkin","info":"","x":160,"y":500,"wires":[]},{"id":"c06fdc411f0b89aa","type":"api-call-service","z":"b511d8822e5a6efc","name":"Turn Off Lights","server":"915baa48.9b1898","version":7,"debugenabled":false,"action":"light.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["light.pumpkin_head_1"],"labelId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"light","service":"turn_off","output_location":"","output_location_type":"none","x":740,"y":840,"wires":[[]]},{"id":"4e02023ab606d8e2","type":"debug","z":"b511d8822e5a6efc","name":"debug 29","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"preset","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":720,"wires":[]},{"id":"915baa48.9b1898","type":"server","name":"Home Assistant","version":6,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":["y","yes","true","on","home","open"],"connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"f577c238b6e1b4de","type":"global-config","env":[],"modules":{"node-red-contrib-home-assistant-websocket":"0.80.1"}}]

im hoping there is a simple like

array(x)=x+1 and it just does like
preset(x) onoff_state(x)
so it would count the number of wleds in the group say and then
be like
(pumpkin)wled name, chase2 preset, on state
(happy_halloween)wled name , off state
(bedroom_strip)wled name, chase 3 preset, on state
(rack_strip)wled name, twinkles preset, on state

so then when automation runs
(pumpkin)wled name, incoming call preset, on state
(happy_halloween)wled name , incoming call preset,on state
(bedroom_strip)wled name, incoming call preset, on state
(rack_strip)wled name, incoming callpreset, on state

then when 20 seconds is done restore all the presets and on off state to previous without having to duplicate the same automation 4 times in this example and times more for any other event… id like 1 automation to do all in a group style so i can just edit the yaml to add more wleds etc

so then be like
preset(1), onoff_state(1)
preset(2), onoff_state(2)

in a like do loop
do
x=x+1
loop while x< (number of wleds in group)

sorry if i confusing i have dyselxia and in my head i explaing things right… so i hope i explain it ok

Maybe using a scene in your automation will help you.

Also your code is unreadable this way.
Please use the code marker in the editor

i looked at the scene stuff but i didnt see a way to Save Current Settings of All Presets and State… and then run a specific Preset on all of them… then Restore all the previous settings

and ok i use the 3 quotes but if not good enough
but there is no suck icon called code marker
jsut the “```” dots

[{"id":"e934eb2147ee44c0","type":"link in","z":"b511d8822e5a6efc","name":"LED Strips In","links":["4b56e51bf617e996"],"x":65,"y":640,"wires":[["11179c754de12c35","b474bf4c7827cc40"]]},{"id":"3982ce50fa4a96ad","type":"api-call-service","z":"b511d8822e5a6efc","name":"Wled - Incoming Call","server":"915baa48.9b1898","version":7,"debugenabled":false,"action":"select.select_option","floorId":[],"areaId":[],"deviceId":[],"entityId":["select.pumpkin_head_1_preset"],"labelId":[],"data":"{\t    \"option\": \"Incoming Call\"\t\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":true,"domain":"select","service":"select_option","x":450,"y":640,"wires":[["ac80364ff12b5cd2"]]},{"id":"11179c754de12c35","type":"api-current-state","z":"b511d8822e5a6efc","name":"Light current state","server":"915baa48.9b1898","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.pumpkin_head_1","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"light_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":220,"y":620,"wires":[["3982ce50fa4a96ad","15a7e824e1049a28"]]},{"id":"264c3a4121991d4e","type":"inject","z":"b511d8822e5a6efc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":780,"wires":[["11179c754de12c35","b474bf4c7827cc40"]]},{"id":"d76e8f95bb91fdec","type":"switch","z":"b511d8822e5a6efc","name":"previously on or off?","property":"light_data.state","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":800,"wires":[["56ed747605874a61"],["c06fdc411f0b89aa"]]},{"id":"ac80364ff12b5cd2","type":"delay","z":"b511d8822e5a6efc","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":410,"y":700,"wires":[["5dea7a3f185b67af"]]},{"id":"5dea7a3f185b67af","type":"change","z":"b511d8822e5a6efc","name":"switch flow. back to msg.","rules":[{"t":"set","p":"palette","pt":"msg","to":"palette","tot":"flow"},{"t":"set","p":"light_data","pt":"msg","to":"light_data","tot":"flow"},{"t":"set","p":"preset","pt":"msg","to":"preset","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":760,"wires":[["d76e8f95bb91fdec"]]},{"id":"b474bf4c7827cc40","type":"api-current-state","z":"b511d8822e5a6efc","name":"Light Preset","server":"915baa48.9b1898","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"select.pumpkin_head_1_preset","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"preset","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","x":220,"y":680,"wires":[["3982ce50fa4a96ad","0ee60871fc9b3929"]]},{"id":"0ee60871fc9b3929","type":"change","z":"b511d8822e5a6efc","name":"save preset to flow.","rules":[{"t":"set","p":"preset","pt":"flow","to":"preset","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":540,"wires":[[]]},{"id":"15a7e824e1049a28","type":"change","z":"b511d8822e5a6efc","name":"save light data to flow.","rules":[{"t":"set","p":"light_data","pt":"flow","to":"light_data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":580,"wires":[[]]},{"id":"56ed747605874a61","type":"api-call-service","z":"b511d8822e5a6efc","name":"Previous Preset","server":"915baa48.9b1898","version":7,"debugenabled":false,"action":"select.select_option","floorId":[],"areaId":[],"deviceId":[],"entityId":["select.pumpkin_head_1_preset"],"labelId":[],"data":"{\t   \"option\": msg.preset\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"select","service":"select_option","output_location":"","output_location_type":"none","x":740,"y":780,"wires":[["4e02023ab606d8e2"]]},{"id":"077885883d099ff1","type":"comment","z":"b511d8822e5a6efc","name":"Incoming Calls Notification LED Pumpkin","info":"","x":160,"y":500,"wires":[]},{"id":"c06fdc411f0b89aa","type":"api-call-service","z":"b511d8822e5a6efc","name":"Turn Off Lights","server":"915baa48.9b1898","version":7,"debugenabled":false,"action":"light.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["light.pumpkin_head_1"],"labelId":[],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":false,"domain":"light","service":"turn_off","output_location":"","output_location_type":"none","x":740,"y":840,"wires":[[]]},{"id":"4e02023ab606d8e2","type":"debug","z":"b511d8822e5a6efc","name":"debug 29","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"preset","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":720,"wires":[]},{"id":"915baa48.9b1898","type":"server","name":"Home Assistant","version":6,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":["y","yes","true","on","home","open"],"connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"f577c238b6e1b4de","type":"global-config","env":[],"modules":{"node-red-contrib-home-assistant-websocket":"0.80.1"}}]

so if the current settings are

(pumpkin)wled name, chase2 preset, on state
(happy_halloween)wled name , off state
(bedroom_strip)wled name, chase 3 preset, on state
(rack_strip)wled name, twinkles preset, on state

then when an incoming call comes in then automation would set

(pumpkin)wled name, incoming call preset, on state
(happy_halloween)wled name , incoming call preset,on state
(bedroom_strip)wled name, incoming call preset, on state
(rack_strip)wled name, incoming callpreset, on state

then after 20 seconds it restores all the values to the previously saved settings

so what i wanted was 1 automation like what i copy and pasted… to handle the 20 wleds i have and not create 20x the same automation to save previous state and restore

What you paste as code isn’t code but it looks more like a json string

In your automation select scene as an action
Config the action with all the states you want to preserve and giv the scene a name.
At the end just apply the create scene again

In developer tool you can try things out and if you switch to yaml mode then example data can be inserted.

ya thats what i ment… the json from node red… thats json code i ment
i didnt mean the x+x code thats from 30 years ago what i was explaining

the node red json is my automation

and i dont see in the HA scene how to configure it

and i dont see a scene node in Node red to configre

you dont happen to have a example at all

ill try to play with the scene again

This was designed to capture the state of entities to restore it later, have you tried it? I use it for one wled, but it can handle more:

action: scene.create
data:
  snapshot_entities:
    - light.ambilight_jasper
    - light.wled_woonkamer

I did have some weird thing that restore would not always work if you set individual lights. I had to turn the lights off before I restored for that. But for normal presets I did not have these things.

@Edwin_D no i havent cuz most of my automations are inside node red i created the automation i posted… and works fine for 1… but when you multiple it it you gotta keep renaming all the msg and you gotta re create it for each like…

i had looked at scene in HA but it doesnt let you save all you can do is set a state…

i take it that code you add that to Script then? ill play with that and try … as my incoming call automation is done in Node red… but ill try

Yes, you can create a script for it. It will create a scene on the fly that you can activate to restore the entire state of the entities.

ok ill try that now and see how that goes

@Edwin_D
so i find there is a glitch in that so i did
creates the scene script

sequence:
  - action: scene.create
    metadata: {}
    data:
      snapshot_entities:
        - select.pumpkin_head_1_preset
        - select.happy_halloween_preset
        - light.pumpkin_head_1
        - light.happy_halloween_main
      scene_id: current_wled_state
alias: wled current state
description: ""

and then i set it to incomming call preset for the 2 for now

and the restore script

sequence:
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.current_wled_state
alias: restore current state wled
description: ""

i found glitch if it runs again it will keep the incoming call preset i have… i noticed when it restores… it doesnt Set the “Preset” in the wled the name under devices it leaves it blank… so when it restores i guess its glittchs as it cant restore “unknown” preset

so i tested more it will restore then wont restore… but that seems to be easier then what i trying to do… but ya bit glitchy

Have you tried turning it off before restore? That worked for me in the few instances it did nor restore properly.

Scenes are a generic feature that should work on all entities. If it does not work as expected you could try to post an issue in Github for the wled integration.

ah ok ill try

ya what i have is so
is testing my pumpkin head i made
so the current setting is this

then node red sets the incoming preset

current preset

then my node red runs for 20 seconds and sets the pumpkin to incoming call

and then it runs that restore script above and it glitchs as you see blank preset

@Edwin_D i made a report on the core page on github…so we shall see… but ya this works easier then me trying to figure it all out in node red lol

1 Like