Actually that’s not quite what I said.
You are obviously still learning the basics of nodeRED; and I guess (like me) you are impatient to get the answer to the immediate problem, and so skipping over things that don’t seem to be the answer. I know also from my own experience that it takes a while before things “fall into place” and I see the bigger pattern. Don’t worry, we are all still learning.
There is a lot of very useful information in the Debug panel which you are not seeing. In particular it shows that there is no “state” variable in the msg object; and so your change node is unable to change the value of non-existant msg.state.
As an example, lets take a look at
which simply returns the current status of a power switch with energy monitoring. I have loaded the current state of the entity (on or off) into msg.payload, and the entire entity into msg.data.
In the debug panel we get a debug node:
You can see that the msg object contains msg._msgid, msg.payload (showing that the switch is currently “on”) and msg.data - which is the first level of data - but that is not particularly helpful.
… but expanding all the arrowheads on the left shows that there is a lot more information contained in the msg object
Lets say I am interested in the voltage. Its value is the number (because of no quotes (") around the number) 249.8; but the value named voltage is located in attributes, which is contained in data within msg. Thus the variable is named msg.data.attributes.voltage
As a shortcut, when you hover the mouse cursor over the debug window the three buttons will appear, and clicking the “copy path” button saves the variable name which you can easily paste into your code.
And the point of this tutorial ? In your flow, I think if you expand the debug 1 node you will find state under msg.slots. Use the actual variable name in your change node.