Comparing two MQTT Feed Status to send or not send an alert

I have two MQTT feeds coming into NodeRed and I only want to trigger an event when a certain criteria is met.

For example, one of the MQTT feeds is the status of a door sensor... 0 for open and 1 for closed.

The second MQTT feed is when a mobile phone is detected at home... home when home, and away when away.

Right now, the door status is triggering an alert, no matter if we are home or not.

I am wondering, can I add a node that will compare the mobile phone status, and when the door is triggered, and if the phone is detected as home the door alert is not forwarded on?

Appreciate any ideas.

Since two msgs will be coming in at different times, I’d suggest in each flow, store the value and then comparing it against the other stored value.

You could store the values in persistent context or in a database.

So when the door sends a msg, store it and retrieve the phones status, compare the two according to your criteria and trigger the action it requires.

Do the same when the phone notification arrives.

Thanks for the reply. Not really keen on a database, so when you say store the values in persistent context, what do you mean? Is there a node for storing values, like a variable?

Did some digging, and I should be able to get the status 'live' from Home Assistant. So I am now thinking I may be able to use one of the Home Assistant / Node Red integration nodes to trigger inside Node Red.

Haven't used Home Assistant nodes within Node Red previously, so not sure of the setup.

See Working with context : Node-RED and A guide to understanding 'Persistent Context'

Are you using HA? If so then you will have trouble getting help here with those nodes and very few here use HA. In fact many think that it just complicates things and prefer to use node-red for everything.

If you didn't know about persistent context then presumably you haven't watched this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Thanks Colin... I'd challenge you on not many people using HA and Node Red :wink:, but you are entitled to your opinion. I managed to get it working using a HA wait until node, and it works perfectly :smiley:

Glad you got it working.

There are plenty of Home Assistant users who ask for advice but as @Colin says, few of the regulars here use HA.
If we try and install a copy of someone's flow, all we get is a bunch of "Unknown" nodes and no idea what they do.

So if you'd care to stick around, there will be another HA user along shortly, maybe you can help them. :slightly_smiling_face:

ps Here's a Home Assistant flow I imported to look at someone's problem. Not much overlap between HA and Node-red.

Your position is understood, and my comments to Colin were tongue in cheek.

Was my first time using a HA node as I've tried to use MQTT as my bridge between all my platforms - HA, Node Red, and Domoticz. I'd tried a few other ways to do the job with MQTT, but on this occasion I was a bit lazy.

Have been on the forum for some years now, and remain appreciative of the community and members that have way more knowledge than me, and dont mind sharing.

1 Like

There are indeed many node-red users that use HA as their main state system.

There are not many home assistant users here, that explain their setup and how they use node-red to make it work, I think it would benefit both NR and HA if people would share/show/explain their flows in the "share your projects" section of the forum, for inspiration.

Currently we only see home-assistant users (including ones that actually think it is part of HA) with questions and they are hard to replicate if you a) don't use HA and/or b) don't use the same device/types, which makes it hard to help.

In addition, the HA nodes are not particularly standard from a node-red perspective (ie. they are not "pure functions" and try to do a lot within a single node - which is not a bad thing by itself, but do make them "odd" in the NR realm.)

That isn't what I said, I said

which is not the same at all.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.