Have Objects in msg, need to take actions based on one of the payload codes

You can use an Inject node configured to inject on startup, with no repeat and feed it into the node copy msg.payload -> flow.switch1.

Hmmm, does not work quite right...I have copied the message payload from the UI switch to a file so it gets stored. This seems to work...will keep experimenting with different scenarios.

mem

What was wrong with my suggestion?

I am not seeing the last state "holding" upon node red redeploy. I am injecting into switch with the options shown below:

I see, you want it to be retained over a node-red restart or deploy. The way to do that, I think, is to put your flow.switch1 in persistent context storage so it will not be cleared on startup. I think you might have to complement the value before feeding it to the switch as the flow variable contains the opposite state to that which the switch is in (except for the short time between clicking the switch and the 433 signal coming in.
You don't need a complex flow like you had before to complement a bool, you can do it in a Change node like this.

image

Sounds reasonable, by your statement "Persistent context storage" I am assuming that you mean that I choose "file" in the copy msg.payload change node that is on the output of the switch...correct?

persist

Yes, assuming you have set that up as the persistent context store, which presumably you did using these docs.

I believe I have it properly set up for both as I have a state-trail contrib graph that is storing data:

filestore

Colin, I think I may have found a NR bug. Given your attention to these forums, I am assuming you either work with them or at least have influence so I am sharing here.

When setting the flow.xxx within the change node if I use an underscore _ within the flow name. Things stop working for instance...flow.switch1 works, flow.switch_1 does not. When an underscore is in the name, the change node proceeding the UI switch node returns "undefined" in the debug node. Let me know if you wish to verify or investigate further.

Can you create a simple flow demonstrating the problem? Perhaps an inject and change nodes to set it then another to pick it up and feed to a debug node.

I am not a developer, just an enthusiast hoping to feed something back to the community.

Edit: Or maybe just for a start post the flow showing the problem and I will see if I can see any obvious issues. It is not impossible that there is a bug i node-red but when I find such a situation I always start by assuming that I have done something silly and just can't see it. Often it is a simple typo and the the brain sees what is supposed to be there, not what is actually there.

I am working on verifying my assumption, but there appears to be something else going on.

No matter what I do for the reset switch state inject...I only get "undefined" from the output of that inject node. I have tried what you state above and other changes but to no avail. This is the setup in the reset UI switch inject node:
reset2

The switch state is being captured from the UI switch as a Boolean and stored in file storage as I have verified below.

pistoredstate

I am then trying to recall it as I show in my proceeding post, and pass it back to the UI switch

restorestate

Any ideas??

Have you selected the correct context storage in the dropdown on the right hand side of the inject node field?

image

Yes sir...as shown in my 1st screen shot, and just re-verified across the initial save and the inject.

Your first screenshot does not show the right hand side.

Sorry...But yes, I have verified the following:

  1. Node info from UI switch is storing the variable as msg.payload = flow.switch1, file storage is chosen

  2. Verified that the data is getting stored in file storage on the Pi:
    pistoredstate

  3. Verified that the inject node to reset the UI switch is msg.payload = flow.switch1

  4. Verified that the inject node to reset the UI switch is set to inject once after 0.1 seconds without repeat

  5. Debug from the reset inject returns msg.payload : undefined

Post the flow then please.

Here it is:

[{"id":"1aa05fe4.fc2e4","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"d4419881.37de38","type":"switch","z":"1aa05fe4.fc2e4","name":"","property":"payload.code","propertyType":"msg","rules":[{"t":"eq","v":"450513","vt":"str"},{"t":"eq","v":"8529fb","vt":"str"},{"t":"eq","v":"2529fb","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":290,"y":80,"wires":[["6a6ea4f6.b1023c","e1c84fd9.20dec"],[],[]],"outputLabels":["relay 1","relay 2","relay 3"]},{"id":"119433bf.d992fc","type":"rtl_433","z":"1aa05fe4.fc2e4","name":"","device":"","frequency":"","protocols":"","x":110,"y":80,"wires":[["f7278b.44e58878","d4419881.37de38"]]},{"id":"f7278b.44e58878","type":"debug","z":"1aa05fe4.fc2e4","name":"From rtl_433","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":130,"y":140,"wires":[]},{"id":"6a6ea4f6.b1023c","type":"debug","z":"1aa05fe4.fc2e4","name":"from switch node","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":60,"wires":[]},{"id":"e1c84fd9.20dec","type":"change","z":"1aa05fe4.fc2e4","name":"remove flow.switch1 --> reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"switch1","tot":"flow"},{"t":"set","p":"switch1","pt":"flow","to":"$not(payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":180,"wires":[["5b0903bc.72595c","9da700be.8c266"]]},{"id":"5b0903bc.72595c","type":"ui_switch","z":"1aa05fe4.fc2e4","name":"","label":"switch1","tooltip":"","group":"84e8fd97.49786","order":4,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"switch","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":960,"y":180,"wires":[["a6f06a74.4ef098","5fe2c07a.c2b88","c403d6fd.c18bf8"]]},{"id":"c403d6fd.c18bf8","type":"change","z":"1aa05fe4.fc2e4","name":"copy msg.payload --> flow.switch1","rules":[{"t":"set","p":"#:(file)::switch1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":220,"wires":[[]]},{"id":"a6f06a74.4ef098","type":"debug","z":"1aa05fe4.fc2e4","name":"Out of switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":80,"wires":[]},{"id":"5fe2c07a.c2b88","type":"exec","z":"1aa05fe4.fc2e4","command":"python3 send.py -p 367 -t 1 13148322","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Relay #1 Send Code","x":1220,"y":151,"wires":[[],[],[]]},{"id":"cf6ed66d.289318","type":"inject","z":"1aa05fe4.fc2e4","name":"Reset switch state on boot","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":".1","topic":"","payload":"switch1","payloadType":"flow","x":720,"y":120,"wires":[["2a4ea41f.e0824c","5b0903bc.72595c"]]},{"id":"9da700be.8c266","type":"debug","z":"1aa05fe4.fc2e4","name":"switch4 reset","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":260,"wires":[]},{"id":"2a4ea41f.e0824c","type":"debug","z":"1aa05fe4.fc2e4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":60,"wires":[]},{"id":"84e8fd97.49786","type":"ui_group","name":"433 testing","tab":"fc908814.9be048","order":1,"disp":true,"width":"6","collapse":false},{"id":"fc908814.9be048","type":"ui_tab","name":"433 testing","icon":"dashboard","order":21,"disabled":false,"hidden":false}]

Even though you said you had checked it, you have MemoryOnly selected in the dropdown in the Inject node.

Colin, the Icon does not change regardless of the choice. I was curious also so verified that the data IS getting written to file as shown here:

pistoredstate

The above image is a screen shot of the json file which is written to a folder on the Pi at: /home/pi/.node-red/context/