Need Help with IF Then

Hi, I am not a programmer by any means and I just started using Node Red for simple projects regarding amateur radio. I´m using an OWM to get local weather to my location and it is working fine but I want to take it a step further.

I want to create a function that IF the description of the weather contains certain words (thunderstorms, lighting, heavy rain) it triggers a text message and it turns off a webswitch I control with a separate flow, plus turns red a led in the dashboard (whic otherwise is green) for visual help.

This is the flow I am using: OpenWeatherMap Weather Dashboard with Icons - Portrait

https://flows.nodered.org/flow/e8176d72ac8af8fbb9fde4adb4008317

Anyone up to the task?

How about you have a look at this flow.

It is not exactly what you want with how it is done, but it does do what you want.

Rather than using an IF command, I used a switch node.

Have a look.

[{"id":"245e5db1.d0feea","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"thunderstorms","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":260,"wires":[["cefa1eeb.51646"]]},{"id":"8f471843.fe865","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"lighting","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":300,"wires":[["cefa1eeb.51646"]]},{"id":"dce8eaf3.4573d","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"heavy rain","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":340,"wires":[["cefa1eeb.51646"]]},{"id":"61a76b87.b6e94c","type":"inject","z":"b9924a74.4d98f8","name":"","topic":"","payload":"anything else","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":380,"wires":[["cefa1eeb.51646"]]},{"id":"cefa1eeb.51646","type":"switch","z":"b9924a74.4d98f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"thunderstorms","vt":"str"},{"t":"cont","v":"lighting","vt":"str"},{"t":"cont","v":"heavy rain","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":370,"y":300,"wires":[["a91b5133.f8ace8"],["a91b5133.f8ace8"],["a91b5133.f8ace8"],["7909e18.4ab142"]]},{"id":"a91b5133.f8ace8","type":"debug","z":"b9924a74.4d98f8","name":"Bad weather","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":560,"y":270,"wires":[]},{"id":"7909e18.4ab142","type":"debug","z":"b9924a74.4d98f8","name":"Good weather","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":570,"y":330,"wires":[]}]

The two output nodes are for good weather and bad weather.
So depending on what you send in to the node depends on which debug node get the message.

You can then use those outputs to start the next stage of things happening.
Also, you could put a change node on each output that simply changes the msg.payload to either bad or good for easier processing at the next stage. But really it isn't needed unless you really want to use the Original messages.

1 Like

Did that solve the problem?

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