Extract an attribute

What I am trying to do is have a button increment the temp setting on my thermostat. I can’t code but am a good googler.
First thing to do is extract the current setting
debug node, get path.

data.attributes.temperature

so with my lack of programming it seems I should be able to use a switch node.

Tried that every way I could think of with no luck.

I did solve by overall problem using this code in a call service node.

{ "temperature": $entities("climate.my_ecobee_3").attributes.temperature - 0.5 }

That worked but I can’t seem to extract that information. I realize i have my automation working but I still don’t understand why I can’t seem to extract that value.

If some one can help me do it preferably without coding but a code snippet is okay also, if that is the only way to do it.

Thanks

Craig

Those formulas work in the HA nodes, but not in many other nodes.
You need to access the global variables instead.
Find the Context Data in the upper right bar (it might be in the down arrow icon!).
Click the refresh icon to the right of Global and you should get the variables available to NodeRed.
Use a line like the below to extract those variables.

global.get('homeassistant').homeAssistant.states["update.home_assistant_supervisor_update"].attributes.latest_version

If you want to just work with nodes and avoid the coding, then use a function node and add this to set message values.

msg.younameit = global.get('homeassistant').homeAssistant.states["update.home_assistant_supervisor_update"].attributes.latest_version;
msg.somethingelse = 
global.get('homeassistant').homeAssistant.states["climate.my_ecobee_3"].attributes.temperature;
return msg;

This will give you msg.younameit and msg.somethingelse to work with.

Much appreciated had a little trouble figuring it out and was getting no output at first…Pro Tip: make sure you activate the debug node…lol

Again thank you for taking time to help me.

Craig

And also set the output of the debug to “complete msg object” at all times.
It will save you a lot of trouble once you hit a node that returns more info in attributes other than payload.

1 Like

I had that trouble with this node and figured that out. I did get it working the other way but wanted to learn. Maybe when I retire I will try to learn some scripting. In the mean time I will learn a bit here and a bit there.

Craig

The script language inside the function node is javascript, so use that to find examples in google.

Okay I have modified it so my output is the temperature -.5 degrees this gives me a correct numerical message output.

so using a call service node and googling I found an example of how to insert a variable in the node

{"temperature": {{payload}}} (I also tried changing payload to temperature as that is the path debug gives me)

This gives me an error

{ domain: "climate", service: "set_temperature", data: object }
2022-10-31, 4:52:18 p.m.node: Thermostatmsg : string[21]
"Expected ":", got "}""
2022-10-31, 4:52:18 p.m.node: debug 2

I am trying to learn this because it seems like extracting a variable and inserting it could be useful.

off to google some more

thanks

Craig 

just noticed something odd I get that error but it does change the temp by .5 degrees but not in the right direction IE it is currently set for 22.5 my function node spits out 22 then the service node errors but my thermostat changes to 23

{{ }} is yaml style.
Just do {“temperature”:msg.payload}

still no go I tried msg.temperature also same error.

2022-10-31, 5:08:59 p.m.[node: Thermostat](http://10.0.0.134:8123/api/hassio_ingress/Ha8et6Tv4G1jCb3FD4yIT0UA283uRDRNxjpNsigy-Pk/#)

msg : string[96]

"Call-service error. must contain at least one of temperature, target_temp_high, target_temp_low."

feel like we are making progress

Can you take a screenshot of the node or export it here, so I can see how it is set up.
In order to use that format the Data field must be set to J:

[{"id":"fe829358d7a6560f","type":"debug","z":"a9564c40a7132d9d","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":840,"y":620,"wires":[]},{"id":"3aa814f5c460663c","type":"inject","z":"a9564c40a7132d9d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":360,"wires":[["b8510cf92a6f1495"]]},{"id":"b8510cf92a6f1495","type":"api-current-state","z":"a9564c40a7132d9d","name":"","server":"1f07ad34.678b53","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"climate.my_ecobee_3","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":270,"y":480,"wires":[["f681d35ca2e0a06c"]]},{"id":"f681d35ca2e0a06c","type":"function","z":"a9564c40a7132d9d","name":"Current Setpoint","func":"msg.temperature = global.get('homeassistant').homeAssistant.states[\"climate.my_ecobee_3\"].attributes.temperature -.5;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":360,"wires":[["c02ccc49716afe1a"]]},{"id":"740788b4b634e09b","type":"api-call-service","z":"a9564c40a7132d9d","name":"Thermostat","server":"1f07ad34.678b53","version":3,"debugenabled":true,"service_domain":"climate","service":"set_temperature","entityId":"climate.my_ecobee_3","data":"{“temperature”:msg.payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":850,"y":340,"wires":[["fe829358d7a6560f"]]},{"id":"c02ccc49716afe1a","type":"change","z":"a9564c40a7132d9d","name":"","rules":[{"t":"move","p":"temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":500,"wires":[["740788b4b634e09b"]]},{"id":"1f07ad34.678b53","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

here is everything

Went back to playing with this and finally got it. Thank you Wally
json {"temperature":{{payload}} }
J: {"temperature":payload}

Either one works
Nice to scratch that itch.

Craig