What goes in, isnt what comes out?

#1

Hello, first time node-red user here. I was wondering if someone out there is expert enough to help me understand why the msg.payload is changing on me.

I’m trying to set my Nest thermometer with https://github.com/hjespers/node-red-contrib-nest

I’ve got everything registered and it is sending data to my thermostat just fine, but only on the initial pass. Every 5 minutes I check the electricity price, if it’s < 2, then turn the AC super cold. If it’s > 2, leave the AC hot.

if (currentrate < 2) {
    msg.payload = {target_temperature_f:68};
} else {
    msg.payload = {target_temperature_f:82};
}

This runs and a debug output shows this:
7/2/2018, 11:35:17 AM node: Before Nest Set Temp
msg : Object
object
topic: “”
payload: object
target_temperature_f: 83
_msgid: “ac67c98.f99e838”

So far so good, this passes to the Nest-thermostat-temperature-node and the thermostat sets the temp…but only the first time. 5 minute loops run but whatever value goes into the Nest-thermostat-temperature-node, stays that way forever. Here is the debug output immediately after the Nest-thermostat-temperature-node:
7/2/2018, 11:35:18 AM node: After Nest Set Temp
msg : Object
object
topic: “”
payload: “{“target_temperature_f”:83}”
_msgid: “529d603e.82c2e”

I was expecting the output from the Nest-node to be the same as the input from the Nest-node. The Nest-node appears to be changing something.

For reference, from the nest-node:
Nest thermostat temperature node. Sets the target temperature in the config or by passing in a message with msg.payload.target_temperature_c or msg.payload.target_temperature_f set to a numerical value. Identify the structure by configuring the ID field in the config dialog window or my passing in a message with msg.payload.structure_id set to a string containing the nest structure id.

Am I setting msg.payload.target_temperature_f properly? It does work the first loop, so I thought the syntax I’m using in my above function was good…

#2

So one is setting msg.payload to an object

payload: object
target_temperature_f: 83

the other is setting msg.payload to a string (note the quotes)

payload: “{“target_temperature_f”:83}”

#3

Yes, and that is what I don't understand. Here's a simple flow I created to troubleshoot:

The "set to 73" function:
msg.payload = {target_temperature_f:73};
return msg;

Then the Nest-set-temperature-node seems to do something because the "after" debug shows a different payload with the quotes you mentioned.

#4

So the node shouldn’t really be altering the format of the message like that. I would open an issue on the nodes github page.

But the reformatting is unlikely to be the cause of the issue if it works first time, but without seeing your actual flow, its difficult to suggest where you might be going wrong

#5

I was looking into writing this in javascript instead of node-red and noticed from nest.com that that syntax for target_temperature looks familiar:

Change the target temperature on a thermostat
After you change the temperature scale to degrees Fahrenheit, you can set the target temperature. Use the same process as previous examples, and specify the field/value to update, and change the root path. Note that “strings” and numbers are formatted differently.

curl --location-trusted -X PUT
-H “Content-Type: application/json”
-H “Authorization: Bearer YOUR_TOKEN_HERE”
-d “{“target_temperature_f”: 70}”
https://developer-api.nest.com/devices/thermostats/device_id

Notice this line:
-d “{“target_temperature_f”: 70}” \

Perhaps the Nest-thermostat-temperature-node is modifying the msg format to be Nest compatible?

If so, is there a way in node-red that I can reset this object to null?
7/2/2018, 11:35:18 AM node: After Nest Set Temp
msg : Object
object
topic: “”
payload: “{“target_temperature_f”:83}”
_msgid: “529d603e.82c2e”

#6

Thanks for the earlier replies. I was experiencing unpredictable issues with node-red, perhaps due to the custom modules, or my inexperience. Sometimes I would have to restart the node-red process to get a debug node to work. I ended up creating a bash script that does what I need. It took a little more work but for my scenario and expertise level, it seems to be a better fit.