Monitor entitiy attributes change in Node Red

Hello folks. Currently, I am running event poll which, polls the status of my entity every second and I break down the msg to extract the attributes of my alarm entity. The process is very inefficient. I was wondering if there is a way that the status of my alarm is sent as a message when the attributes, NOT the status changes. Event pallet only monitors the status change. Is there a way to monitor the attributes changes?

image

Make homeassistant do it. Create a template sensor

Then just use a state change or trigger node

Nice, I don’t know how to work with templates. But try to create it tomorrow and see how it works for me.

If you uncheck Output only on state change the event state node will trigger anytime the state or any attributes of the entity are updated.

9 Likes

That’s is so helpful thank you so much

I’m also about the same issue, that I was able to do like so.
Can anyone help me with replacing the circled part with one Function nod?

[{"id":"ffb08fd6.0b4dc","type":"server-state-changed","z":"45465411.cc0a6c","name":"Climate is heating?","server":"72b04927.1f5688","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"climate.thermostat","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":110,"y":340,"wires":[["2eb22370.c8995c"]]},{"id":"8f460835.65f018","type":"api-call-service","z":"45465411.cc0a6c","name":"","server":"72b04927.1f5688","version":1,"debugenabled":false,"service_domain":"fan","service":"turn_on","entityId":"fan.second_bedroom_fan","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":640,"y":280,"wires":[[]]},{"id":"7c4e3419.f4c90c","type":"api-call-service","z":"45465411.cc0a6c","name":"","server":"72b04927.1f5688","version":1,"debugenabled":false,"service_domain":"fan","service":"turn_off","entityId":"fan.second_bedroom_fan","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":820,"y":400,"wires":[[]]},{"id":"2eb22370.c8995c","type":"switch","z":"45465411.cc0a6c","name":"","property":"data.new_state.attributes.hvac_action","propertyType":"msg","rules":[{"t":"eq","v":"heating","vt":"str"},{"t":"eq","v":"idle","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":340,"wires":[["c9c1c605.1f3b58","229eac34.017734"],["4b4c4d59.346b24"]]},{"id":"c9c1c605.1f3b58","type":"switch","z":"45465411.cc0a6c","name":"","property":"data.new_state.attributes.hvac_action","propertyType":"msg","rules":[{"t":"neq","v":"data.old_state.attributes.hvac_action","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":280,"wires":[["8f460835.65f018"]]},{"id":"4b4c4d59.346b24","type":"switch","z":"45465411.cc0a6c","name":"","property":"data.new_state.attributes.hvac_action","propertyType":"msg","rules":[{"t":"neq","v":"data.old_state.attributes.hvac_action","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":400,"wires":[["a0cd550d.4744f8"]]},{"id":"a0cd550d.4744f8","type":"trigger","z":"45465411.cc0a6c","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"10","extend":false,"units":"min","reset":"stop","bytopic":"all","name":"","x":630,"y":400,"wires":[["7c4e3419.f4c90c"]],"icon":"node-red/timer.svg"},{"id":"229eac34.017734","type":"change","z":"45465411.cc0a6c","name":"stop timer","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":340,"wires":[["a0cd550d.4744f8"]]},{"id":"72b04927.1f5688","type":"server","z":"","name":"Home Assistant","addon":true}]

Hello What is it that you are trying to achieve here?

I’m tracking if climate is heating or not, to turn ceiling fan on or off. Problem was that climate’s state is always says “Heat”, but when it’s heating attributes.hvac_action becomes “heating”, when it’s not heating, just waiting, attributes.hvac_action is “idle”. And I’m interested if the same can be done with Function node.

Here i use a get template to get the attributes

image
which outputs as a payload

then i use a function to store it in a global variable so i can use it later
i also set a flag to say ive set it otherwise i got stuck in a loop, i dont want to keep setting it
image

then i can use it as a decision output of 1 or 0 (different variable i know, just an example)
image
on this particular one, im resetting it to 0 after i pass the action

but on this i just use it as a switch
image

Just a quick general question. What if the benefit of assigning a global variable if it is already all assigned to the global homeassistant variable. I can see there are all states and attributes:

2 Likes

Wow did not know you can access state through the global variables. That is really cool.

I realize this is old but it helped me in the thinking and got to what I felt was easiest path.
My alternative solution was to use a state node with a property condition of cooling,

I then just then did a check if switch was on, if not then turn on, if the state is not cooling then turn off

6 Likes

Was just checking if some one done it any better way…maybe u safe one node by this:

It check the change…because it is triggered even if no change was done on the one attribute…

I have tried to use function and just right a Java Script to manage my condition.