Node-Red "State Changed" node gets non state-changed events

Am using Node RED with Home Assistant and have several flows all working well.

One issue I am having is whenever I do anything with “device_tracker” entities, I get multiple, seemingly random events of the same kind. The node I use is this one:
image
In the description, it states:

Outputs ‘state_changed’ event types sent from Home Assistant

But I find that it’s getting ALL events - not just ones where the state actually changes. This is bad for the device_tracker entities, because they will send the same state… for example, I will get random “home” events even though I was and still am, home. I think it has to do with the phone “checking in”, which triggers an event even though the state of the entity has not changed.

My solution to this has been to do something like:
image
where in the switch node I have:
image

Which works…

I should point out, that in node-red-contrib-home-assistant ver 0.3, I have tried using the new “Trigger: State” node:
image

But it has the same issue… I know I can put “conditions” on the trigger like:
image

But then I only get a trigger on that specific change. I was hoping to get a true “only pass the event if the state actually changed” node, then depending on the new state, take actions. Am I missing something basic here?

I am having the same issue as you. I am trying to “catch” my Kiwkset lock changing state between locked and unlock. I want to turn on the foyer lights if the lock is “unlocked” but I traced it down to the fact that the events: state node is injecting both the prior state and current state msg which causes the switch node to process both.

So the light turns on both on locked and unlocked since both msg’s are sent.

I think this would be a good use scenario for the RBE Node - RBE Node Info because it only allows payloads to pass if the payload is different. I’m currently using it in a similar scenario as you describe here and so far it’s working well.

What happens if/when you restart node-red or re-deploy that flow? Does it remember the last message before the restart/redeploy?

The advantage of checking “old_state” against “state” is you need no memory.

I ended up using the RBE node. That was exactly what I was needing. When state changed, it sent only the new state per say.

1 Like