Page 1 of 1

Delay conditioning script

PostPosted: Mon Nov 25, 2019 5:26 am
by Eagleye
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.

Re: Delay conditioning script

PostPosted: Mon Nov 25, 2019 7:30 am
by DaveL17
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.

Re: Delay conditioning script

PostPosted: Mon Nov 25, 2019 11:34 am
by jay (support)
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).

Re: Delay conditioning script

PostPosted: Mon Nov 25, 2019 4:17 pm
by Eagleye
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.

Re: Delay conditioning script

PostPosted: Mon Nov 25, 2019 5:39 pm
by jay (support)
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.

Re: Delay conditioning script

PostPosted: Tue Nov 26, 2019 3:34 pm
by Eagleye
Thanks Jay, Can anyone assist me with the script?

Re: Delay conditioning script

PostPosted: Tue Nov 26, 2019 9:01 pm
by DaveL17
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

Re: Delay conditioning script

PostPosted: Wed Nov 27, 2019 3:27 pm
by Eagleye
Thanks Dave, When you say linked script, what does that mean?

Re: Delay conditioning script

PostPosted: Wed Nov 27, 2019 3:33 pm
by FlyingDiver
Eagleye wrote:
Thanks Dave, When you say linked script, what does that mean?


Linked == External

Re: Delay conditioning script

PostPosted: Wed Nov 27, 2019 3:45 pm
by DaveL17
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 5585 times