Creating Timer loops for intervals longer than 24 hours

Simple method for how to Trigger an Output or Action at a specific time of day, at intervals longer than 24 hours.

Usage examples:

  • Water a tree from 2am to 4am, once every 3 days.
  • Check the water level in a tank at 8am once a week.

Currently, most of the Timer Functions in Mycodo are setup for time intervals that are 24 hours or less.

By using the Trigger: Duration Function in combination with a Trigger: Daily Time Point Function, it is possible to trigger an Output or Action at intervals greater than 24 hours, and at a specific time of day.

First you need to setup the Trigger: Daily Time Point Function and select what Action or Output you want to Trigger, and what time of day you want it to happen. Then you must click SAVE on both the Action and the Function itself before proceeding to the next step.

This next part is the important part, you will also need to make this Function self-deactivating by choosing Action “Controller: Deactivate” as the last Action in the setup, and then choosing itself as the Function to deactivate. Click on the SAVE button for this last Action and exit the Function setup.

This way, whenever the function is activated, it will run the Output or Action at the specified time of day, and then when complete, the Function will deactivate itself so that it does not repeat every 24 hours.

Next, you will need to setup the Trigger: Duration Function. This is the timer that will be set to activate the Timer: Daily Time Point Function at intervals longer than 24 hours.

You will need to convert days into seconds for the Period value. As an example, in the screenshot I have the Period set to 259200 seconds, which is 3 days.
In the Action settings, choose “Controller: Activate”, and then select the Trigger: Daily Time Point Function we just setup previously. Click both the save on the Action and the Function itself and then exit the Function setup.

Leave the Trigger: Daily Time Point Function deactivated, and only activate the Trigger: Duration Function

This now creates a loop…
Every 3 days (259200 seconds) the Trigger: Duration Function will activate the Trigger: Daily Time Point Function.
The Trigger: Daily Time Point Function will then run the Output or Action at the specific programmed time of day, and when finished, it will deactivate itself.
Then in 3 days it will be re-activated again by the Trigger: Duration Function.

It is important to understand that if for any reason the Pi loses power, or is rebooted, or the Mycodo backend is restarted, the Trigger: Duration will lose track of where it is in that 259200 second countdown, and the counter will be restarted from 0! Likewise if you deactivate the Timer: Duration Function and then re-activate it, that counter gets reset to 0! To avoid any problems, you should keep the Pi on a UPS and avoid rebooting or restarting the backend.

This is currently the method I am using to automatically water my fruit trees every 3 days, using Mycodo to control a WiFI relay I created using an ESP32 and a 4 channel relay board to control my irrigation zone valves.

The gold bars show Zone 3 being activated for 2 hours, starting at 2am and ending at 4am, every 3 days.

The Control Box. An ESP32 running Tasmota controls a 4-channel relay board, and a 5th single relay which activates the 24VAC transformer only when the valves need to be activated (this reduces heat buildup inside the box by not having the transformer on all the time). The ESP32 receives all of it’s commands over WiFi via mqtt from a raspberry pi 2 running Mycodo which is inside the house.

3 Likes