Variable within range for certain amount of time?

Posted on
Sun Oct 06, 2019 8:36 am
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

Variable within range for certain amount of time?

Right now I have a variable (lets call it variable A) that is set by a schedule that checks power usage from a smart plug every 1 second.

So the values are numeric and always jumping around.

As an example, what I want to do now is say:

"If variable A is between 0 and 5 for at least 30 seconds, set variable B to OFF"
"If variable A is between 5 and 10 for at least 60 seconds, set variable B to DOOR"
"If variable A is between 10 and 1000 for at least 20 seconds, set variable B to ON"
"If variable A is 1000 or higher for at least 30 seconds, set variable B to HIGH"

I haven't been able to figure out how to do this with Indigo UI, and couldn't adapt any of my existing Python scripts to work correctly.

Thanks,

Chris

Posted on
Sun Oct 06, 2019 9:06 am
FlyingDiver offline
User avatar
Posts: 7211
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Variable within range for certain amount of time?

It can be done, but it's going to be complicated. But then again, the logic you present is very complicated.

I think you're going to need a trigger and a timer for each condition. For each one:

1. Set the trigger to fire on every change of variable A. Use conditions (different for each trigger) to only activate when it's in the range called for.
2. In the trigger fires, start the timer for that condition. STOP the other three timers (since all conditions are mutually exclusive).
3. When the timer goes off, set variable B as needed. This is a separate action triggered by the timer event.

So you're going to need 4 triggers to start 4 different timers, then four more triggers for when the timers fire.

I think that'll work.
Last edited by FlyingDiver on Sun Oct 06, 2019 9:31 am, edited 1 time in total.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sun Oct 06, 2019 9:14 am
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

Re: Variable within range for certain amount of time?

You are right, it does sound complicated , but I'll give it a go.

Thanks for the direction.

Posted on
Tue Nov 05, 2019 1:37 pm
sumocomputers offline
Posts: 267
Joined: Jun 23, 2008

Re: Variable within range for certain amount of time?

I got everything going, and it is a little complicated, but works awesome.

Thank you for the help.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests