Timer Q - Run once per day for X Hours (when connected)

I have a “Controlled Supply” (aka Cheap) power circuit that is off for most of the time but is energised by the power company, and it is:

  • energised at least once per day for up to 8 hours (normally overnight), but
  • could be energised all weekend or other days when when the power demand on the grid is low.

Of this circuit, I run my pool pump connected to a “smart” power switch. I’d like to migrate from my own separate custom code (AHK script that is working well for years) to an openhab timer but I’m not sure of the syntax.

The simple, requirement is to “Run for a max of X Hours per 24 hours”. With my AHK Script I currently:

  • Poll the Switch to see if it is On-Line
  • If On-Line check if the last start time was at least 24-Hrs ago
  • If “Yes” then Run for X Hours then turn off
  • Repeat

This solves this issue that I don’t know when the circuit become energised. I could easily set a timer that Starts at 12:01am and runs for X hours but they may not energise the circuit till 12:05 and I’d miss it.

Grateful for any suggestions!

My first idea is something using Jython. @5iver and @rlkoshak are two of our programmer users.

Another logic idea could be:
if OnLine after 1am turn ON for X hours.

I recommend everyone use Jython :slightly_smiling_face:, but I don’t see this as being a necessity here.

A lot depends on the hardware. What type of smart power switch is the pump hooked up to? Is it connected to OH, and if so, do you have it included in persistence? When the power comes on, does this switch resume the state it was in before the power goes out?

1 Like

I would certainly separate out “cheap power” detection from pump control. Pump logic can then trigger from a change in “cheap power”.

How sophisticated does it need to be?
If no cheap power comes that day - do you still want a minimum pump run? (i.e. a “must run by” latest time or periiod)
If cheap power is turned off during run, do want to suspend or abort?

1 Like

In Australia, Controlled Load circuit are literally On/Off and under the control of the power company. For most of they day there is no power supplied. At some point (at their control) they provide supply and they guarantee at “least” 8 hours per day on these circuit . Some times they can run for days. My pump is connected to a “smart” wifi power switch that OH has control of on this circuit. As a result, the “smart” wifi power switch is off line most of the time and comes online when power to the circuit is provided.

When the power is turned ON, the “smart” power switch connects to the network (and hence to OpenHAB) + I have persistence running for OH.

The simplest OH logic I can think of for a “timer” is

  • at 1am turn on for X Hours

… but if the power does not come on till 1.05am can I still run it for X hours?

So how about…

If smart_power_point = Online & Time is after 1am … Turn ON, and then turn OFF after X hours ?

If the switch is ON when the power goes out, is it ON when the power is restored? ON and online mean different things here.

Is the 1am start time a new requirement?

Sure. Take simple steps

it’s 1am
cheap power comes on
if pump is not already running, start it up and schedule an off-time

I have and hence could use Wemo and/or TP-Link branded Wifi Smart Plugs. When the power circuit is dark they are (as expected) uncountable.

But I think I’m over-engineering it. I checked the logs and the Power always comes ON around 10:30ish PM and is OFF 6:30ish AM on this circuit (and can be longer eg on all weekend). So all I think I need to do is have simple ON/OFF rules as follows:

rule "Pool Cleaner On"
	Time cron "0 0 0 1/1 * ? *" // Turn ON at Midnight

rule "Pool Cleaner Off"
	Time cron "0 0 3 1/1 * ? *"
	Pool_Cleaner.sendCommand(OFF)  // Turn OFF at 3:00am

rule "Pool Pump On"
	Time cron "0 0 0 1/1 * ? *" // Turn ON at Midnight

rule "Pool Pump Off"
	Time cron "0 0 6 1/1 * ? *"
	Pool_Pump.sendCommand(OFF)  // Turn OFF at 6:00am

Thanks for the conversation as it helps one think through the design!!

the easiest (apart from pure cron jobs) for me would be:
Use the network binding to check if your wifi switch is online and trigger an item switch with it (I’d suggest an expire binding switch so it’ll revert to OFF automatically) “Cheap_Power”
Then you can set a rule that starts the pump if Cheap_Power changed from OFF to ON.
In case you want to be fancy, record the run time of the pump and only switch it on as long it is less than the planned duration.

Also, I’m no cron expert but I think you should write * instead of 1/1 if you want it to run each day.