Saving msg.payload from previous node to a Helper

I’m using the speedtest integration and want to perform some calculations on the output. The integration does a check every hour and I’m using the Event: State node each time it fires off to capture the values in the payload. I’m trying to capture that in an input_number variable using another “Call Service” node (see Image). This just gives me an API error in Node-Red.

I’ve also “Change” node to dump the value in directly into the HA global variable (global.homeassistant.homeAssistant.states["input_number.speedtest_ping"].state), but that doesn’t seem to work either. Looking at the values in of hte helpers in the Dev Tools indicates no change (they remain 0).

This should be pretty trivial and I’m just learning how to capture payload data; it can’t be rocket surgery, but I can’t seem to crack this nut.

Something is not right, I am not able to pass the value through using the message. I was able using jsonata.

{"value":$entities('sensor.steam_return').state }

Why not just store them in NodeRed?
https://nodered.org/docs/user-guide/context

Event State Node → Call Service Node : pass value in msg.payload

In the call service node, data entry (JSONata) try

{“value”: payload}

This creates an object with “value” equal to the value in msg.payload, which works for me. The ‘test’ option in the JSONata edit page is a powerful tool - your code appears to be returning the string {{payload}}, not the value in msg.payload.

Also worth noting that the Call Service node tries to pick up and merge anything appropriate from msg.payload (including “data”). I have tested this with just a simple inject msg.payload = 1234, however the entity state note returns a lot of stuff. I suggest turning off everything from the output of that node except msg.payload = state value, or use an intermediary change node to ‘clean’ msg.payload back to a simple object with just payload in it to ensure that the Call Service does not inadvertently pick up something unwanted from msg.payload.

The HA global variable in Node-RED is a most useful object as it holds practically everything you could ask for, however I believe this to be ‘read only’ in that it is state information pulled from HA by the Node-RED HA companion. Data is not updated the other way, hence the need to use the Call Service node (or the API calls exposed by HA).

1 Like

@Biscuit Perfect. Thanks. That worked exactly as I wanted it to.