Node Red: get data attributes?

I am new to Node Red. I can pull the state of an entity, but I still don’t know how to pull different attributes. For example, my debug node shows the TV’s source attribute


is set to “CC”. What do I need in my flow to react based on whether media_player.lg_tv’s “source” is “CC”? How do I pass that data around, read it, and then react to it?

You need to use the switch node.

I suggest reading the docs in order to see how it all works :slight_smile:

https://nodered.org/docs/

1 Like

You probably have to listen to the msg.data.source
You can always copy the correct path with the little button i highlighted in the image below
image

You can then employ this in a switch node like Codec303 advised or even use a function node or any other node that lets you specify a specific message.

Apparently that was all I had to do. Switch node with data.attributes.source in the property field, with msg as the dropdown.

2 Likes

Yeah. That full path is
msg.data.attributes.source

You don’t have to use a switch node, you can access that full path from function nodes,

1 Like

Is there much of a difference between a switch node and function node, given that all I’m doing is passing a value?

A function node allows you to do anything you want with the data. A switch node literally just passes the data based on the switch settings.

You can use function nodes to add information to the message object or create the notification message all in one node without having to create an entire long flow just to pass a notification to a service (telegram for instance)

Can you give an example of using a function node to get MQTT attributes.
Thanks for your help!

Can you give me a screenshot of your function?
Thanks!

Can I get a screen shot of using data.attributes.source ?
Thanks

Post a dubug of your complete message and tell us what part you want to access instead.

1 Like

I would like to get the temperature attributes.

Thanks!

msg.payload[“fet temperature”]

I think…

Right click on it and copy the path.

Where do I put the path?
Thanks!

Depends on what you are going to do with it.

You ask a generic question and you get the generic answer.
If you have a specific question, then post that instead.

1 Like

I want the attributes element “fet temperature F” to be output on the first output of the switch node.
Where do I put the path of that element in the switch node?

I think you have misunderstood what the switch node does.
It’s still not clear what you are trying to do.

Incase you need it again… You can get an attribute right from the Event State node without using a switch node or doing extra steps and you can compare it as well.

Got this from Current State node - attributes - #15 by sender so all credit goes to Sender

2 Likes