Troubles with logic

Hey everyone, First I would like to thank everyone here as this is a great and helpful community!
I'm not a programmer but I work in the automation industry. So I understand most programming with working with logic. And Automation logic doesn't cross over that much with programming applications.
So please forgive me on my lack of experience!

Here is what I'm wanting the end goal to be.
Node-Red connects to my Dashboard's API to collect a JSON file once every minute.
The JSON is parsed and we look at the city names.
If there is a City name that is equal to Chicago-IL then we send an email or SMS email to my phone.

The Issue.
If there is an entry of Chicago-IL, I get an email or SMS text every minute until Chicago-IL is no longer in the JSON file.

What I've tried.
Being a automation engineer, I've tried what I know and that is basic logic. The only issue is, in this programming, I've not been able to get the logic to work.
Here is a basic rundown of what my planed logic would look like:

If JSON file contains Chicago-IL and Bool equals False, then send email and set Bool to True
If JSON file does not contain Chicago-IL then set Bool to False

The idea of this would be that if the Chicago-IL entry pops up, the email would send and the Bool variable would get set to true. This way when the code runs again. I don't get another email until the Chicago-IL entry is gone at which the Bool variable would reset.

Where I run into issues with this logic, is each time the code was triggered, the Bool would reset and I would receive the email again and again.

Is there a way to get a Bool variable to retain it's true setting?
Do you have a better recommendation on how to pull this off?

Thank you in advance!

At the point where you have checked for the city then pass on a message with true or false (or whatever you fancy) in the payload. Then send that through an RBE node. That will only pass on the first occurrence each time it changes state. Then use a Switch to test for the city present state and then on to send the email.

1 Like

What does the json look like ?

Perhaps it is easier to just add a delay node and set it to rate limit, ie once per - your auto inject timer.

That works! Thanks @Colin

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