Jump to content

If either/or, then do…but just ONCE!?


Go to solution Solved by paulbates,

Recommended Posts

Posted
eisy, IoX firmware & UI v5.8.0, Java 8 update 401 (today), MacOS 14.2.1

Regarding the attached program snippet, from a pure logic point of view, I’m thinking that 

  • if either one of the two “If” conditions is false, then the whole “If” condition is false, and therefore the “Then” step should NOT execute;
  • if either one of the two “If” conditions is true, then the whole “If” condition is true (either/or), and therefore the “Then” step should execute.  

Once.  NOT twice.  Either the “If” condition is true, or else it’s not true; it’s binary, there’s no in-between!  If either condition is true, then the condition itself is true…but only once; if neither condition is true, then the condition is false (once).

Curiously, if I right-click on the program and choose “Run (If),” then I only get one notification, as expected.

Am I missing something here?  Why does the “Then” condition trigger twice, but only when auto-executed?

Why Two Alerts?.jpg

  • Solution
Posted (edited)

The reason it's happening is that you want to know if either is triggering, and they both are at slightly different times. 

Assuming they're both triggering within 5 minutes of each other, I would do it with a timer and a second program

Program freeze warning 1

If 
    Your first weather condition
     Or Your second weather conditon
Then
     Run program freeze warning 2

else

 

Program freeze warning 2

(no if)

Then
       wait 5 minutes
       Send notification 'xxx'
       Resource 'Freeze warning message'

else
 

When the second conditions triggers, the second program will restart because it's waiting, and you'll get only one message. Start with 5 minutes and then try reducing the wait time so there's not as much wait, but the program continues to run only once

 

Edited by paulbates
Posted

@GHenry FYI for future programming help please try to share the program in text format. Right click on the program and select "Copy to Clipboard" (be sure you use the COPY command...should be the last option). Then paste it as text in the forum post.

This allows anybody offering support to edit the program without having to type so much of it in (as @paulbates did above). It also makes the program searchable in the forum should you have a reason to trigger your memory and find it down the road or perhaps help others that might have a similar issue.

 

40 minutes ago, GHenry said:

Why does the “Then” condition trigger twice, but only when auto-executed?

Lucky you only get it twice. It will trigger anytime either of your IF statements is true. So if you are having temperature changes right around your target you could get multiple alerts.

Somebody recently had this question about another temperature or warning alert. I believe the answer there was to set a variable so the program only triggered once.

You could set a temp variable and that is then triggered by another program to send the alert. 

With that you could set a min/max temp to alter the variable so you might not get multiple alerts of the same temperature change.

 

Posted

Interesting, thank you!  Both emails are sent at the same time, down to the second, so I wouldn't have thought of that.

But since I operate my own mail server, I can see in the logs that in fact the two emails are sent exactly 0.3 seconds apart:

05:56:18.268 2 SMTPI-001601([192.168.1.1]) [8211038] received encrypted, 849 bytes
05:56:18.568 2 SMTPI-001602([192.168.1.1]) [8211033] received encrypted, 849 bytes

I guess waiting one second would do it.  Thanks again!

Posted
2 minutes ago, Geddy said:

FYI for future programming help please try to share the program in text format. Right click on the program and select "Copy to Clipboard" (be sure you use the COPY command...should be the last option). Then paste it as text in the forum post.

That's a good suggestion, thanks!

  • Like 1
Posted
5 minutes ago, GHenry said:

I guess waiting one second would do it.  Thanks again!

You're welcome.

Even in today's world, 1 second sounds skinny to me... lots of links in the chain / moving parts from the weather service, email, and the ISY itself. Time and use may prove this out either way.

Posted

How often does the forecast node change values?

Even with a 5 minute wait, you're still going to continue to get emails every time the value changes. (albeit maybe 5 minutes apart).

25, 24.5, 23, 22, etc.

You probably need to set another variable that indicates notification sent (which should also disable further notifications) and then reset it once it's above freezing so it sends again next time below your threshold.

  • Like 1
Posted (edited)

Thinking about the two programs some more; if the weather conditions keeps changes in less than 5 minutes, it will continually restart the 2nd program so you will never get the notification (until/if it stops changing).  That does eliminate getting the messages twice though!  But you probably want the message when it first hits the threshold though....

Edit: Based on OpenWeatherMap info, data shouldn't change in less than 10 minutes.

Short Poll

  • How often to poll the OpenWeatherMap weather service. Note that the data is only updated every 10 minutes. Setting this to less may result in exceeding the free service rate limit.

Edited by gzahar
Posted
6 minutes ago, gzahar said:

How often does the forecast node change values?

Even with a 5 minute wait, you're still going to continue to get emails every time the value changes. (albeit maybe 5 minutes apart).

25, 24.5, 23, 22, etc.

You probably need to set another variable that indicates notification sent (which should also disable further notifications) and then reset it once it's above freezing so it sends again next time below your threshold.

Your more thorough insight demonstrates that I'm not an elegant programmer.  The node usually updates only every 6 hours, but special weather situations might cause it more often.  And "Thinking about the two programs some more" is what I failed to do!  Thanks for following through.

Posted
1 hour ago, GHenry said:

Your more thorough insight demonstrates that I'm not an elegant programmer.  The node usually updates only every 6 hours, but special weather situations might cause it more often.  And "Thinking about the two programs some more" is what I failed to do!  Thanks for following through.

This may be a good two program solution (continually setting a state variable to the same value will not trigger a program execution):

Program freeze warning 1

If 
    Your first weather condition
     Or Your second weather condition
Then
     Set "freeze warning state variable" to 1

Else
     Set "freeze warning state variable" to 0

Program freeze warning 2

If 
    "Freeze warning state variable" =1
Then
       Send notification 'xxx'
       Resource 'Freeze warning message'

Else (optional)
       Send notification 'yyy'
       Resource 'Freeze warning over message'

  • Like 1
Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.4k
×
×
  • Create New...