String compare with state home assistant


Can someone help me see why the case that compares these strings does not work for me?

Thank you

Your arrowed debug is showing what is in msg.payload not msg.payload.Modo_Operativo

Add node.warn(msg.payload) and node.warn(msg.payload.Modo_Operativo) to your function you will see why this is happening.

Thank you very much for the help

I have tried what you tell me and now I get this error,
I have to install a module or have I put something wrong?


Thank you

Firstly, I dont know why you are setting var Modo to the result of node.warn. node.warn is a debugging function.


Do you see how msg.payload.Modo_Operativo is reported as being undefined?
Do you see how msg.payload is reported as being "Modo_Auto"?

Use msg.payload instead of msg.payload.Modo_Operativo in your function...


Please paste function code as text NOT as an image.
And always format code between 3 backticks
like this


Ok, that part already works for me !!!

Now I need to collect the value and match it to the variable depending on each case

You cannot use the payload from completely different message.

Either store the value that comes out of the other HA node in flow/global context then you can access it later on in the function node using flow.get


Use a join node to join the 2 messages from the 2 HA nodes.

some reading to help you...

See this article in the cookbook for an example of how to join messages into one object.

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.



I have tried this function, but I guess I am missing something. It keeps appearing to me undefined.

thank you so much for help me

You need to grab the stored context value from flow


var value = flow.get("xxx")

Where xxx is your flow variable name.

I recommend you read the docs (linked above) particularly about function nodes.

Also, I recommend watching 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 a lot !!

With this advice I have already solved it.

I will follow your advice and watch the tutorial videos

Thank you so much for everything !!