Filter a command out of an event in Node-RED

Hi there, people!

I am trying to use the data coming from an event made by Zigbee Home Automation (ZHA). It’s a simple Ikea On/Off Switch that sends an event with some ids and a command to turn on or off. I would like to use that command to actually turn on or off something. But I never worked with events before and don’t know exactly how to do it.

So I am asking for your help. What should I use in order to separate the messages based on the id and then send the command.

Thank you so much!
ygreq

zha

Use the “filter” node

I actually tried. But I have about 3 automations in my portfolio so not that good with functions yet. Care to share a solution? What should I type there? I would like to understand that node.

In the meantime I managed to figure out how to filter the messages by using a couple of split and route nodes

Now I gotta find a way to use those 2 messages together (id and command) so I don’t send a command from a different switch.

This is the flow:

Don’t want to write it for you, but here is my similar set up for my Deconz events:

image

Here is my switch and along side is an event

You should be able to follow the same logic on yours to cause another event on your NodeRed.

2 Likes

I think I got it. For example for the value for buttonevent you would set the property to msg.payload.state.buttonevent, right?

Yes, try it out…

1 Like

If you hover the mouse over the item you want to use, you can copy the ‘path’ directly there (and also the value) saves a lot of mistypings.

Where exactly should I hover, fribse?

In the debug window you can get both the value and path:
image

2 Likes

Do t forget to add msg. before the path.
By some reason it only gives you “payload.origin”

1 Like

That is true, but you can see that the Switch node Property field already has msg. as a prefix; as do most nodes I’ve interacted with.

Definitely worth verifying!

1 Like

I usually use function nodes, that is why we have different views :slight_smile:

1 Like

Good point!

No one was talking about function nodes, so maybe your caveat should have mentioned “function nodes”.

Yup but function nodes are so obvious to me that I keep forgetting that other nodes exist.
Most of my more complex sequences are call service, state, and function nodes

1 Like

I know this is old but my god you just saved me, spent hours trying to figure out how to pull out a value for filter and the hover (actually clicking copy path) got me easily. Thanks!!!

1 Like