Delay conditioning script

Posted on
Mon Nov 25, 2019 5:26 am
Eagleye offline
Posts: 82
Joined: Jan 14, 2019

Delay conditioning script

I have a sprinkler system operated by a series of solenoid valves that are controlled by z-wave devices. The water supply comes from an unground tank that uses a pump, which has a z-wave device connected behind the power switch and measures the power usage. When water level in the tank becomes low, it automatically switches to mains water.

I want to created a trigger that sends an email notification when the sprinkler is turned on & the current power load for the pump is zero watts (Not operating), which means that the sprinkler system is using mains water.

The problem I'm facing is that there is a slight delay (Approximately 10 seconds from when the sprinkler is turned on and the pumps Starts to displays power usage.

I want to know if it is possible to write a scrip in the condition section that creates a pause (~10secs) before checking the condition.

Posted on
Mon Nov 25, 2019 7:30 am
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Delay conditioning script

All of the following assumes that you've tried the "Delay By" setting on the Trigger's Actions tab and that isn't doing what you want. It seems like that *should* work--trigger fires when sprinklers are turned on, delay by 10 seconds, then test the pump power level.

But your question about conditions is an interesting question that probably warrants Matt or Jay to chime in. For giggles, I tried a short condition script:

Code: Select all
import time

time.sleep(9)
return True

That does seem to work. Assuming that condition scripts are run as embedded scripts, you'll not want to go beyond 9 seconds--Indigo will terminate embedded scripts automatically if they don't execute within 10 seconds. Then you'll need to have an trigger action script to do the evaluation.

Trigger: Sprinkler becomes on
Condition: above script
Action: Execute an external Python script to test the power usage of the pump.

I think that'll get at what you want. But the built-in "Delay By" would be my first choice.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Nov 25, 2019 11:34 am
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Delay conditioning script

Yes, condition scripts have the same time delay as embedded scripts (can't go over 10 seconds).

The delay would work only if the action was a script that executed the conditional logic. I think this is the safest way to do it. No condition, but the action on the trigger is delayed by however long you need and the action type is a script that executes your conditional logic, and if it passes then you can execute your actions (or an action group if you have several actions).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Nov 25, 2019 4:17 pm
Eagleye offline
Posts: 82
Joined: Jan 14, 2019

Re: Delay conditioning script

Thanks Guys,

I'm not quite there, I have attached a series of screen shots of the trigger event to help clarify the challenge I'm facing.

Trigger: Drip system state becomes On
Condition: If water pump current load is less than 10 watts. this is where the delay needs to occur to give the pump time to start & change the current load to ~700watts (if it does not change, it can only be presumed that the pump did not start)
Action: Send email notification

I'm concerned that the "Delay by" function in the Action section will only delay sending the email, not the Condition.
Attachments
Screen Shot 2019-11-26 at 8.52.06 am.png
Trigger
Screen Shot 2019-11-26 at 8.52.06 am.png (76.86 KiB) Viewed 5624 times
Screen Shot 2019-11-26 at 8.52.23 am.png
Conditions
Screen Shot 2019-11-26 at 8.52.23 am.png (122.63 KiB) Viewed 5624 times
Screen Shot 2019-11-26 at 8.52.44 am.png
Actions
Screen Shot 2019-11-26 at 8.52.44 am.png (135.26 KiB) Viewed 5624 times

Posted on
Mon Nov 25, 2019 5:39 pm
jay (support) offline
Site Admin
User avatar
Posts: 18200
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Delay conditioning script

Correct - the delay would just delay the Send Mail action.

What you want to do is use a Execute Script action which sends the email only if the condition is met. That way, the determination is part of the action and happens after the delay.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Nov 26, 2019 3:34 pm
Eagleye offline
Posts: 82
Joined: Jan 14, 2019

Re: Delay conditioning script

Thanks Jay, Can anyone assist me with the script?

Posted on
Tue Nov 26, 2019 9:01 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Delay conditioning script

If I understand, you want the trigger to fire the script, wait 10 seconds and then check the pump energy usage to determine whether to fire off an email. This should be pretty close. Note that you should run it as a linked script and not as an embedded script. You'll have to adjust a few things to fit your install.

Code: Select all
import time


time.sleep(10)  # in seconds
pump_energy = indigo.devices[12345678].energyCurLevel  # replace id number with yours

if pump_energy < 10:
    email_body = """The irrigation system is currently on, but the tank pump may not be operating.\n
    Please check the water pressure in the laundry to confirm that the water supply is coming from
    the tank and not the mains.
    """
    indigo.server.sendEmailTo('name@apple.com', subject=u"TANK PUMP MAY NOT BE WORKING", body=email_body)  # replace email address with yours

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Nov 27, 2019 3:27 pm
Eagleye offline
Posts: 82
Joined: Jan 14, 2019

Re: Delay conditioning script

Thanks Dave, When you say linked script, what does that mean?

Posted on
Wed Nov 27, 2019 3:33 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Delay conditioning script

Eagleye wrote:
Thanks Dave, When you say linked script, what does that mean?


Linked == External

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

Posted on
Wed Nov 27, 2019 3:45 pm
DaveL17 offline
User avatar
Posts: 6744
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Delay conditioning script

Right. As opposed to embedded.

Screen Shot 2019-11-27 at 3.43.57 PM.png
Screen Shot 2019-11-27 at 3.43.57 PM.png (22.89 KiB) Viewed 5490 times

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests