Node REd getting thermostat attributes

Hi:

I have my thermostat set at our normal house schedules. However sometimes our schedule changes and I want to set up an automation that will check if user is family is home. If family is home it will check the current preset mode attribute of the thermostat and if not set to “home” then call service to set up the thermostat to “home” preset mode. This will cover the thermostat to be at right temperate when our schedule changes.

I know that the attribute I want to check is on
entitiy: climate.home
attribute path: data.attributes.climate_mode

So far I know for sure if family home by this:

But where I struggle is how to access that attribute of the thermostat so when that value is set to sleep or work or away then I call a service to change it to “home”. I dont have an issue calling the service. that works well. It is just accessing the data from that attribute.

Tried with function nodes and switches but still struggling to know how to get it right.

If you want to change the preset on the thermostat, in a call service node.

1 Like

If you are trying to find the state (and its attributes) of an entity, use a ‘current state’ node. Put a debug node on the end showing the complete message, you will see the attributes you are try to check.

1 Like

Sorry I misread the question, this is an example for using attributes.

Thanks with all your suggestions I was able to figure out. I am going to post the solution just in case someone needs help.

  1. What I did first was to get a current node report the state of msg.data from the climate.home and output that to a debug note as suggested.

That gave me the idea that the data I was looking for was in msg.data.attributes.climate_mode. It was also in msg.data.attributes.preset_mode.

Then I attached the output from that node to a swtich Node.

The swtich is looking for one of two outputs a string from msg.data.attributes.present_mode

then I just have to call my service from the outputs. It works like a charm. Thanks so much for the pointers.

I hope that helps someone.

8 Likes

And you can actually do that without the switch node. In your current state node against the If State element set jsonata as the evaluation type then

$entity().attributes.preset_mode = "Home"

and it will send a message via the top output, otherwise via the bottom output.

1 Like

Your write up gave me a crash course on a few topics in HA. Thank you kindly for that AND the thread to help me get this flow working!

Sorry to reply directly to an answer you gave a while back.
As far as I understand, your answer allows the current state node to filter a single attribute of the home assistant entity, or compare it to a threshold value.
Would it be possible to simply set the payload or data to just the value of a single attribute?
For example, from the above example, assign the value of “current_temperature” to the payload, so that it can be stored in a flow variable or be used for comparing it to another value retrieved from another home assistant entity ?

Or do I need a function node for that??

Away from home so can’t check directly, but you should be able to set it to the payload or any other field directly from the current state node, there is a section for output properties at the bottom of the dialogue, or use a change node.

Ok, sorry,
I spoke too soon. I have found a way using your answer
Just add the
$entity().attributes.current_temperature

to msg.payload

Sorry to bother

Hi Roger,

Sorry again.
But I can use this “magic” directly in an “event state node” and (of course) I can use it in a function-node … but is there a way to use it in a change-node?

Can I use any data found in the payload coming from an events-node , as part of the new payload in a change-node?
What is the syntax there? I have tried to copy the “path” that i found in a debug node.

If I use $entity(), what does that specifically point to (if not the payload)
Isn’t using single or double curly brackets supposed to indicate referring to a variable?
In a change node, it gets an error unless I include it into " ", but then of course it simply adds the literal string
“{{$entity().attributes” just adds this literally into the payload going out of the node.

I have tried change msg.payload to “string” and “Jexpression”

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/call-service.html#targets

Is somewhat helpful in dealing with templates.

Hi,

I have a similar situation to this thread, but want to set the data attribute of the generic thermostat in Home assistant from a function node in node red, The attribite I want to set is temperature. It looks like this inside the entity

What the function node does is set the temperature based on a schedule of preset periods. This needs to change the temperature set point of the generic thermostat and hence turn on or turn off the heater.
I have looked at the following
global.set("homeassistant.homeAssistant.states['climate.central_heating'].attributes.temperature", temp);
but this is not right
Any ideas would be a greatly appreciated

worked it out.

basically used a call service node with the following
The temp variable is determined from my function node that sets the temp based on the period of the day (Mon -Fri, Sat, and Sun)

Thanks a lot for sharing this. I have been looking for a while and was unable to understand this - with your post this solves a part of my problem.

I wonder if you can guide on how can send a command to the thermostat? I have a nest thermostat and I would like it to start the boiler only if room temperature falls below a set point (usually it runs on a schedule and does not stop even if the room temperature is reached)