Changing conditional controller setpoints by time

Hi,

What would you suggest the best way to approach changing EC and PH setpoints based on number of days. I am interested in trying this with our lettuce plants. (eg. first 15 days 6.0 ph 1.2ec then 6.2ph for 5 days then 1.4ec for remaining time.).

I thought of using trigger: daily time point to increase a variable and check against its value.

Thanks

You will likely want to use the datetime python library to check if the current day falls between pre-set periods where you want certain conditions to be set. The following Python code (completely untested) is how I would approach it:

import datetime

conditions_range = {}
ph = {}
ec = {}

# Set date ranges
condition_range[1] = (datetime.datetime(year=2022, month=6, day=1),
                      datetime.datetime(year=2022, month=7, day=1))

condition_range[2] = (datetime.datetime(year=2022, month=7, day=2),
                      datetime.datetime(year=2022, month=8, day=1))

condition_range[3] = (datetime.datetime(year=2022, month=8, day=2),
                      datetime.datetime(year=2022, month=9, day=1))

# Set pH and EC based on ranges
ph[1] = (5.9, 6.1)
ec[1] = (1.1, 1.3)

ph[2] = (6.1, 6.3)
ec[2] = (1.1, 1.3)

ph[3] = (6.1, 6.3)
ec[3] = (1.3, 1.5)

# Find current range
range_found = False
for i in range(1, 4):
    if condition_range[i][0] < datetime.datetime.now() < condition_range[i][1]:  # If current date falls within range
        range_found = i
        break

# Check if range has been found
if not range_found:
    self.logger.error("Could not find range")
else:
    self.logger.info(f"Found Range index: {range_found}: pH: {ph[range_found]}, EC: {ec[range_found]}")
    # Code to regulate pH and EC goes here

This could also be a good use for a Date Span Function, which will execute actions when between two specific dates. You could then automatically activate a different Function for each date range.

It’s a bit of a bulky solution since you’ll need to duplicate a Conditional Function, rather than using one Conditional Function, since there’s currently no simple way to pass data to a Conditional Function.

This is also making me think about dedicated pH and/or EC Functions that allow a variable number of setpoints that can have date ranges associated.

Hi Kyle,
Thanks for those options. I was thinking of what a front end (end user) on a Pi screen in a greenhouse could look like. Maybe even to the point of being able to select crop a from custom database.
Have found changing the nutrient mix to grow, bloom and boost stages of lettuce makes a huge difference with time to harvest and quality of produce.
Thanks.

Oh, just saw your video after my reply. Very cool. Thanks

I just committed the new Function (link in How to Create a Function from a Conditional (Mycodo Video Tutorial)). I’ll also be working on making a Date Span Function as well, which should make scheduling different pH/EC setpoints a lot easier.

Hi Kyle,

Have the new function running, Everything looks ok so far, email alerts working also.

Thanks