# Trouble filtering key/value from MQTT message

**URL:** <https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201>\
**Category:** General\
**Created:** [21 January 2026 08:56 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201 "2026-01-21T08:56:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mprice58](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mprice58/32/105470_2.png) [@mprice58](https://discourse.nodered.org/u/mprice58)\
**Post date:** [21 January 2026 08:56 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/1 "2026-01-21T08:56:05Z")

</div>

I have a RF433 fan that I am trying to integrate with Home Assistant using a modified Sonoff RF-Bridge with Tasmota and Portisch firmware.

I want to be able to detect when a button on the remote is pressed to be able to modify the state of the device within Home Assistant to keep the fan and HA device state in sync.

Each button on the remote generates a different 24 character code for the payload.RfRaw.Data key value in the incomming MQTT message. This can be clearly seen when I set up a debug trace capturing the whole message:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/190c5f3898c4a563a3ad3916bb9be88a125bb72c.png)

I have written a simple function to filter the message based on the the Data value.

```js
var rfdata = msg.payload.RfRaw.Data.toString().trim();
var rfdataType = typeof rfdata; // Get the type of rfdata

node.log("Received rfdata: " + rfdata + " (Type: " + rfdataType + ")"); // Log the received rfdata and its type

if (rfdata.toUpperCase() === "AAA4232E00F902CC63560155") {
    return msg; 
} else {
    node.status({
        fill: "red", 
        shape: "ring", 
        text: "No match: " + rfdata + " (Type: " + rfdataType + ")"
    });
    return null; // Stop flow if no match
}

```

The node displays "No match: AAA4232E00F902CC63560155"

I have tried a similar approach using a switch node in place of a function with the same outcome.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/8/b81e3196945242006156e3e0379e3742cca628ca.png)

I have tried checking the data type of the value, it is a string value

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [21 January 2026 09:03 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/2 "2026-01-21T09:03:33Z")

</div>

Hi and welcome to the forum.

For the first couple of days you are limited to how many posts you can do.

Not that it matters, please edit the post (if you want) and where the code from the `function` node is, before you post it, click up the top on the `</>` button and paste the code where it says.

Now, to the question:  
I'm not sure I understand the question and what you want to do.

Ok, you are (or seem to be) filtering the message/s and if the value matches, it is passed.

Yes, you get a visual indication if it doesn't match.  
But honestly a `switch` node could do what you want.

Just edit the part of the message you want to check, and paste the original case of the message  
(`AAA4232E00F902CC63560155`)  
Then only if that part matches is the message passed on.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 January 2026 09:16 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/3 "2026-01-21T09:16:11Z")

</div>

The string in your image does not match the string you are looking for.  
Add a debug node prior to the function and confirm the actual string you want.

As @Trying_to_learn says a function node is overkill just to match 1 string

---

<div class="post-metadata">

**Author:** ![ThingsTinkerer](https://avatars.discourse-cdn.com/v4/letter/t/91b2a8/32.png) [@ThingsTinkerer](https://discourse.nodered.org/u/ThingsTinkerer)\
**Post date:** [21 January 2026 16:08 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/4 "2026-01-21T16:08:58Z")

</div>

Hi, and welcome to forum! The answer is most likely posted by the other above.

Please compare the string in the msg with the string you filter on:

- "AAA4232 **E** 00F **9** 02 **CC** 63560155"
- "AAA4232 **D** 00F **F** 02 **D0** 63560155"

Other than that, there are so many things to say. First off, once you got the message into node red (and out of the mqtt node), this is a pure javascript issue. Which is good cause that is usually easier than mqtt problems 😃 And whenever I see `var` I shiver, so all I can say is let/const is the preferred standard.

I wouldn't necessarily say to drop function node, but can certainly make the logic much simpler:

```javascript
if(msg.payload?.RfRaw?.Data == "AAA4232D00FF02D063560155") {
  // match
  return msg;
}
// no match
return;

```

---

<div class="post-metadata">

**Author:** ![mprice58](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mprice58/32/105470_2.png) [@mprice58](https://discourse.nodered.org/u/mprice58)\
**Post date:** [22 January 2026 08:42 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/5 "2026-01-22T08:42:53Z")

</div>

Thanks for pointing out my error. I did originally check that the values were the same, in fact comparison value in the script was cut and paste from the debug log. It appears that the real issue is that the value is changing. It appears that my assumption that each button on the remote generates a unique 24 character code was incorrect so I need to go back to the drawing board and work out a way to determine when each remote button is pressed.  
It is probably beyond the scope of this discussion board but it appears that if the Tasmota/Portisch RF-Bridge is placed in capture mode RFRAW 177 it does generate a unique long data string (\>24 char) for each button however as soon as I issue an MQTT command via HA to activate one of the available functions on the fan via the RF-Bridge the capture mode changes to RFRAW 1.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 January 2026 16:21 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/6 "2026-01-22T16:21:35Z")

</div>

It is easier to capture the raw data as a button, in learning mode. Then it will store it under the key you specify - when the event arrives you only need to check for the key it detects as the raw data will never be the same.

ie. first send `rfraw 1`, followed by: `rfkey1 2` - then press the button from your remote - you will hear a beep, then it learned the command and stored it under key 1. Then you can send `rfkey1 6` which will send the learned command. (and this in turn can also be send over MQTT)

Where `2` is learning mode and `6` is sending the learned command. There are 16 keys available to learn.

---

<div class="post-metadata">

**Author:** ![mprice58](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mprice58/32/105470_2.png) [@mprice58](https://discourse.nodered.org/u/mprice58)\
**Post date:** [23 January 2026 08:54 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/7 "2026-01-23T08:54:08Z")

</div>

Thanks bakman2, unfortunately this method wont work for me as I have 4 fans with 5 buttons each and I am planning to integrate other devices in future.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [23 January 2026 09:22 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/8 "2026-01-23T09:22:13Z")

</div>

But you would have .... filter/`SWITCH` nodes for each of the different fans / buttons.

Then each one would have it's own _output_ which you then parse.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 April 2026 09:22 UTC](https://discourse.nodered.org/t/trouble-filtering-key-value-from-mqtt-message/100201/9 "2026-04-23T09:22:23Z")

</div>

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