Look in payload for a specific string of text

I'm an idiot,figured it out.
image

Hi guys,

I'm a home assistant user, just beginning my journey with Node red. I know home assistant node red isnt quite the same, but I think my question is relevant for both.

Quite simply, in the pictured flow, what do I need to place in between the inject node and the "Turn on light" node that will ONLY turn on the light if the payload includes "caption" : "ok" ??

This is just a simple example of a more complex flow I am doing. Im just stuck on how to parse the payload to look for specific text.

(((If you care, I am using BeSpoken to send silent command to my amazon alexa. The payload is what it returns. It only returns a "caption: ok" if the command is successful. I want to use the existence/non existence of "caption:ok" to trigger a message being sent to my smartphone)))

[{"id":"9228fdb7.e0546","type":"inject","z":"46dac922.3363f8","name":"inject","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"\"{\"message\": \"Turn off office light\", \"card\": null, \"sessionTimeout\": 0, \"streamURL\": null, \"transcript\": \"okay\", \"transcriptAudioURL\": null, \"display\": null, \"caption\": \"ok\", \"debug\": {\"deviceInteractionDuration\": 3.116769552230835}\"","payloadType":"str","x":630,"y":80,"wires":[["f4a65240.b372c","8dab3c0.f0e33c8"]]}]

Don't worry.

You aren't the only one to make mistakes. (Ask anyone here about me)

Good you sorted it out.

You may want to mark this as solved.

1 Like

Hello,

Just for future reference the way you found will work fine but something you should know when you meet a string like this again is that this is a string which contains a json.
You can feed it through the json node from the palette and you will get an actual javascript object in the msg.payload which would mean that you can work directly with it‘s properties in switch/change/function node with much more freedom than the string represents.
For example you could than use:
if msg.payload.caption == ok in a switch node as a rule instead of checking the whole string with contains.
This is especially useful if you‘d want to work with other properties of an input message down the line.
All that said your solution is a fine quick and dirty solution.

Johannes

1 Like

@JGKK
Thanks, that worked too. I may do that so that in future I can look back for on this flow as an example for futures flows. Thanks

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