Node-red HA Call Service node - How to only send a message when it is passed a non null payload

Hi,

I have a Node-Red flow with an exec node running a Python script that tests if my bins need to go out and if they do, it returns a string.

I’m passing the exec stdout to a HA Call Service notify node and using this to send a message telling me which bin needs to go out.

It all works after a lot of banging my head against several walls, except if no bins go out and the Python script returns nothing. I still get an HA notification with a title and no message.

How do I test if the exec node is not returing anything and conditionally send the notification? I’m new to Node red and have read as many posts and blogs as I can find but can’t work out how to do this.

Basically: If exec node returns nothing and payload: “”. Stop the Flow.

Many thanks.

Use the switch node from the palette, before the call to the Home Assistant service.

Add a second rule. Set the first rule to route to output 1 if msg.payload is not empty. Set the second rule to “otherwise”.

Wire output 1 to the Home Assistant call. DO NOT wire the second output anywhere. The flow will simply end if msg.payload is empty.

1 Like

Hello again!

I’ve just tried that and it hasn’t stopped the messages being sent.

So Python script stdout > Switch > HA Call Service

Property is msg.payload
is not null → 1
otherwise → 2

And “is not null” connected to call service. “Otherwise” to nothing.

my debug stdout is showing the msg.payload: “”

msg.payload will never be null unless you personally have set it to null. It can be empty, in standard nodered flows, but null is something very different to empty. Empty - is “” null, is basically that it doesn’t exist at all. Which it does, because the Exec node will output something even if it is just an empty string. (Which you can see in the debug node, is exactly what it did output)

Fab,

thank you. Changed it to “is not empty” and it no longer sends.

Off to learn some more about null and empty.

Thank you once again.

1 Like

null = not set.
Typically if I am doing work in a function node and I don’t want the flow to continue if my if statements suggest they shouldn’t - say if I am parsing the XML feed from the Met Office warnings and there is no warning - then I will simply do this:

msg = null;

Because the msg object is now null, the flow will end when it leaves the function node.

1 Like

As an aside. Did you see that SBC are introducing ical next year for their bin collection?

Hedley

1 Like

Sadly Home Assistant does not currently provide a way to subscribe to an ical. Though You we can probably create a Google calendar and subscribe that to the remote ical.

Edit: Where did you find out that they are going to provide an ical ?

Hi,

On the website it says:

“Regrettably we are unable to provide collection calendar downloads at this time. We are working on a new system which will give access to calendars, but unfortunately we have experienced unexpected delays. We anticipate the new system will go live in January. We apologise for any inconvenience caused by the delay in publishing next year’s calendars. This page will continue to be available to look up the next collection dates during this period.”

I contacted them asking what they are implementing and how and they came back and said it was ical.

1 Like