Conditional Controller mixing up outputs

Hey kyle, im sorry i come to ya so often, but im having an odd issue,
since i was unable to get my graphs back up i decided to do a fresh reinstall of mycodo,
after doing so i had to reinput the code i was using for my conditional controller, so i copied over the code from this page. ( Automated Hydroponic System Build – Projects | Kyle Gabriel )

My issue is, i turned this on last night to start regulating solely my pH, and not effect the EC, however when i checked this morning, it instead has not lowered my pH but rather raised it, significantly. im wondering what i did wrong in my code?


### Edit below to set desired ranges for pH and electrical conductivity ###
# Desired range for electrical conductivity
range_ec_high = 1300
range_ec_low = 1000
# Desired range for pH
range_ph_high = 6.2
range_ph_low = 5.5
# pH range that will immediately cause a pH correction
range_ph_high_danger = 7.0
range_ph_low_danger = 5.0
### Edit below to set the IDs for Conditions and Actions ###
condition_id_measurement_ph_id = "{7f25c6e6}"  # Condition: measurement, last, pH Input
condition_id_measurement_ec_id = "{cb1d3093}"  # Condition: measurement, last, EC Input
action_id_pump_1_acid = "{d8185ef5}"  # Action: Pump 1 (Acid)
action_id_pump_2_base = "{46189e81}"  # Action: Pump 2 (Base)
#action_id_pump_3_nutrient_a = "{PUMP_3_ID}"  # Action: Pump 3 (Nutrient A)
#action_id_pump_4_nutrient_b = "{PUMP_4_ID}"  # Action: Pump 4 (Nutrient B)
#action_id_email_notification = "{EMAIL_ID}"  # Action: Email Notification
### DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ###
import time
if 'notify_ec' not in self.variables:  # Initiate EC notification timer
    self.variables['notify_ec'] = 0
if 'notify_ph' not in self.variables:  # Initiate pH notification timer
    self.variables['notify_ph'] = 0
if 'notify_none' not in self.variables:  # Initiate None measurement notification timer
    self.variables['notify_none'] = 0
measure_ec = self.condition(condition_id_measurement_ec_id)
measure_ph = self.condition(condition_id_measurement_ph_id)
self.logger.debug("Conditional check. EC: {}, pH: {}".format(measure_ec, measure_ph))
if None in [measure_ec, measure_ph]:
    if measure_ec is None:
        self.message += "\nWarning: No EC Measurement! Check sensor!"
    if measure_ph is None:
        self.message += "\nWarning: No pH Measurement! Check sensor!"
    if self.variables['notify_none'] < time.time():  # Only notify every 12 hours
        self.variables['notify_none'] = time.time() + 43200  # 12 hours
        self.run_action(action_id_email_notification, message=self.message)  # Email alert
    return
# First check if pH is dangerously low or high, and adjust if it is
if measure_ph < range_ph_low_danger:  # pH dangerously low, add base (pH up)
    msg = "pH is dangerously low: {}. Should be > {}. Dispensing 1 ml base".format(measure_ph, range_ph_low_danger)
    self.logger.debug(msg)
    self.message += msg
    self.run_action(action_id_pump_2_base)  # Dispense 1 ml base (pH up)
    if self.variables['notify_ph'] < time.time():  # Only notify every 12 hours
        self.variables['notify_ph'] = time.time() + 43200  # 12 hours
        self.run_action(action_id_email_notification, message=self.message)  # Email alert
elif measure_ph > range_ph_high_danger:  # pH dangerously high, add acid (pH down)
    msg = "pH is dangerously high: {}. Should be < {}. Dispensing 1 ml acid".format(measure_ph, range_ph_high_danger)
    self.logger.debug(msg)
    self.message += msg
    self.run_action(action_id_pump_1_acid)  # Dispense 1 ml acid (pH down)
    if self.variables['notify_ph'] < time.time():  # Only notify every 12 hours
        self.variables['notify_ph'] = time.time() + 43200  # 12 hours
        #self.run_action(action_id_email_notification, #message=self.message)  # Email alert
# If pH isn't dangerously low or high, check if EC #is within range
#elif measure_ec < range_ec_low:  # EC too low, #add nutrient
#    self.logger.debug("EC: {}. Should be > {}. #Dosing 3 ml Nut A, 3 ml Nut B".format(measure_ec, #range_ec_low))
#   self.run_action(action_id_pump_3_nutrient_a)  # Dispense 3 ml nutrient A
#    self.run_action(action_id_pump_4_nutrient_b)  # Dispense 3 ml nutrient B
#elif measure_ec > range_ec_high:  # EC too #high, #add nutrient
#    msg = "EC: {}. Should be < {}. Need to #add #water to dilute!".format(measure_ec, #range_ec_high)
#    self.logger.debug(msg)
#    if self.variables['notify_ec'] < #time.time():  # Only notify every 12 hours
#        self.variables['notify_ec'] = #time.time() + 43200  # 12 hours
#        self.message += msg
#        #self.run_action(action_id_email_notification, #message=self.message)  # Email alert
# If EC is in range, make sure pH is within range
#elif measure_ph < range_ph_low:  # pH too low, #add base (pH up)
#    self.logger.debug("pH is {}. Should be > {}. #Dispensing 1 ml base".format(measure_ph, #range_ph_low))
#    self.run_action(action_id_pump_2_base)  # #Dispense 1 ml base (pH up)
#elif measure_ph > range_ph_high:  # pH too high, #add acid (pH down)
#    self.logger.debug("pH is {}. Should be < {}. #Dispensing 1 ml acid".format(measure_ph, #range_ph_high))
#    self.run_action(action_id_pump_1_acid)  # #Dispense 1 ml acid (pH down)

You either mixed up your acid/base solutions, the pumps that dispense the solutions, or the condition IDs for those pumps. Really the only explanation for what you’re observing.

crap its been a long week kyle

1 Like

hey kyle, so i thought i got it working but somehow im still screwing up, as in now it wont even activate, im stuck dosing on the pumps manually, can u take a glance, see what i screwed up? the inputs are rhe same as previously posted


# Desired range for electrical conductivity
range_ec_high = 1300
range_ec_low = 1000

# Desired range for pH
range_ph_high = 6.3
range_ph_low = 6.0

# pH range that will immediately cause a pH correction
range_ph_high_danger = 6.8
range_ph_low_danger = 5.0

### Edit below to set the IDs for Conditions and Actions ###

condition_id_measurement_ph_id = "{7f25c6e6}"    # Condition: measurement, last, pH Input
# deleted Condition: measurement, last, EC Input
action_id_pump_1_acid = "{46189e81}"  # Action: Pump 1 (Acid)
action_id_pump_2_base = "{d8185ef5}"  # Action: Pump 2 (Base)
#####action_id_pump_3_nutrient_a = "{PUMP_3_ID}"  # Action: Pump 3 (Nutrient A)
#####action_id_pump_4_nutrient_b = "{PUMP_4_ID}"  # Action: Pump 4 (Nutrient B)
#####action_id_email_notification = "{EMAIL_ID}"  # Action: Email Notification

### DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ###

import time

#if 'notify_ec' not in self.variables:  # Initiate EC notification timer
    self.variables['notify_ec'] = 0
if 'notify_ph' not in self.variables:  # Initiate pH notification timer
    self.variables['notify_ph'] = 0
if 'notify_none' not in self.variables:  # Initiate None measurement notification timer
    self.variables['notify_none'] = 0

#measure_ec = #self.condition(condition_id_measurement_ec_id)
measure_ph = self.condition(condition_id_measurement_ph_id)
self.logger.debug("Conditional check. EC: {}, pH: {}".format(measure_ec, measure_ph))

if None in [measure_ec, measure_ph]:
    #if measure_ec is None:
        #self.message += "\nWarning: No EC #Measurement! Check sensor!"
    if measure_ph is None:
        self.message += "\nWarning: No pH Measurement! Check sensor!"
    if self.variables['notify_none'] < time.time():  # Only notify every 12 hours
        self.variables['notify_none'] = time.time() + 43200  # 12 hours
        self.run_action(action_id_email_notification, message=self.message)  # Email alert
    return

# First check if pH is dangerously low or high, and adjust if it is
if measure_ph < range_ph_low_danger:  # pH dangerously low, add base (pH up)
    msg = "pH is dangerously low: {}. Should be > {}. Dispensing 1 ml base".format(measure_ph, range_ph_low_danger)
    self.logger.debug(msg)
    self.message += msg
    self.run_action(action_id_pump_2_base)  # Dispense 1 ml base (pH up)
    if self.variables['notify_ph'] < time.time():  # Only notify every 12 hours
        self.variables['notify_ph'] = time.time() + 43200  # 12 hours
        self.run_action(action_id_email_notification, message=self.message)  # Email alert
elif measure_ph > range_ph_high_danger:  # pH dangerously high, add acid (pH down)
    msg = "pH is dangerously high: {}. Should be < {}. Dispensing 1 ml acid".format(measure_ph, range_ph_high_danger)
    self.logger.debug(msg)
    self.message += msg
    self.run_action(action_id_pump_1_acid)  # Dispense 1 ml acid (pH down)
    if self.variables['notify_ph'] < time.time():  # Only notify every 12 hours
        self.variables['notify_ph'] = time.time() + 43200  # 12 hours
        self.run_action(action_id_email_notification, message=self.message)  # Email alert

# If pH isn't dangerously low or high, check if EC is within range
# If EC is in range, make sure pH is within range
elif measure_ph < range_ph_low:  # pH too low, add base (pH up)
    self.logger.debug("pH is {}. Should be > {}. Dispensing 1 ml base".format(measure_ph, range_ph_low))
    self.run_action(action_id_pump_2_base)  # Dispense 1 ml base (pH up)
elif measure_ph > range_ph_high:  # pH too high, add acid (pH down)
    self.logger.debug("pH is {}. Should be < {}. Dispensing 1 ml acid".format(measure_ph, range_ph_high))
    self.run_action(action_id_pump_1_acid)  # Dispense 1 ml acid (pH down)

Im sorry for deleting the last two posts and adding needless responses, i didnt know itd do that injust wanted to keep trying things, but unfortunately im not too good at this, can you help me? if you dont mind reviewing the code and seeing where i screwed up. same inputs as above


# Desired range for electrical conductivity
range_ec_high = 1300
range_ec_low = 1000

# Desired range for pH
range_ph_high = 6.2
range_ph_low = 5.5

# pH range that will immediately cause a pH correction
range_ph_high_danger = 7.0
range_ph_low_danger = 5.0

### Edit below to set the IDs for Conditions and Actions ###

condition_id_measurement_ph_id = "{7f25c6e6}" 
# Condition: measurement, last, pH Input
# condition_id_measurement_ec_id = 
# Condition: measurement, last, EC Input
action_id_pump_1_acid = "{46189e81}"  
# Action: Pump 1 (Acid)
action_id_pump_2_base = "{d8185ef5}"  
# Action: Pump 2 (Base)
#action_id_pump_3_nutrient_a = “”
# Action: Pump 3 (Nutrient A)
#action_id_pump_4_nutrient_b = “”
# Action: Pump 4 (Nutrient B)
#action_id_email_notification = ""  
# Action: Email Notification

### DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ###

import time

if 'notify_ec' not in self.variables:  # Initiate EC notification timer
    self.variables['notify_ec'] = 0
if 'notify_ph' not in self.variables:  # Initiate pH notification timer
    self.variables['notify_ph'] = 0
if 'notify_none' not in self.variables:  # Initiate None measurement notification timer
    self.variables['notify_none'] = 0

#measure_ec = #self.condition(condition_id_measurement_ec_id)
measure_ph = self.condition(condition_id_measurement_ph_id)
self.logger.debug("Conditional check. , pH: {}".format(measure_ph))

if None in [measure_ph]:
    if measure_ph is None:
        self.message += "\nWarning: No pH Measurement! Check sensor!"
    if self.variables['notify_none'] < time.time():  # Only notify every 12 hours
        self.variables['notify_none'] = time.time() + 43200  # 12 hours
        self.run_action(action_id_email_notification, message=self.message)  # Email alert
    return

# First check if pH is dangerously low or high, and adjust if it is
if measure_ph < range_ph_low_danger:  # pH dangerously low, add base (pH up)
    msg = "pH is dangerously low: {}. Should be > {}. Dispensing 1 ml base".format(measure_ph, range_ph_low_danger)
    self.logger.debug(msg)
    self.message += msg
    self.run_action(action_id_pump_2_base)  # Dispense 1 ml base (pH up)
    if self.variables['notify_ph'] < time.time():  # Only notify every 12 hours
        self.variables['notify_ph'] = time.time() + 43200  # 12 hours        self.run_action(action_id_email_notification, message=self.message)  # Email alert
elif measure_ph > range_ph_high_danger:  # pH dangerously high, add acid (pH down)
    msg = "pH is dangerously high: {}. Should be < {}. Dispensing 1 ml acid".format(measure_ph, range_ph_high_danger)
    self.logger.debug(msg)
    self.message += msg
    self.run_action(action_id_pump_1_acid)  # Dispense 1 ml acid (pH down)
    if self.variables['notify_ph'] < time.time():  # Only notify every 12 hours
        self.variables['notify_ph'] = time.time() + 43200  # 12 hours
      elif measure_ph < range_ph_low:  # pH too low, add base (pH up)
    self.logger.debug("pH is {}. Should be > {}. Dispensing 1 ml base".format(measure_ph, range_ph_low))
    self.run_action(action_id_pump_2_base)  # Dispense 1 ml base (pH up)
elif measure_ph > range_ph_high:  # pH too high, add acid (pH down)
    self.logger.debug("pH is {}. Should be < {}. Dispensing 1 ml acid".format(measure_ph, range_ph_high))
    self.run_action(action_id_pump_1_acid)  # Dispense 1 ml acid (pH down)

This is indented when it shouldn’t be.