Conditional Function help

Hello,
I am hoping someone can help with this small problem. I can not get it to use the “humidifier_state” to perform an action.
Code…

humidity_high = 80 # percent
humidity_low = 70 # percent
humidity_value_present = self.condition("{052895a3}") # Sensor
dehumidifier_state = self.condition("{2b76c532}") # GPIO Pin 27 as input

if humidity_value_present > humidity_high and dehumidifier_state == "(0)":
    self.run_action("{fc032cfe}")  # Action: dehumidifier_button = on

elif humidity_value_present < humidity_low and dehumidifier_state == "(1)":
    self.run_action("{fc032cfe}")  # Action: dehumidifier_button = off

And a pic of conditional controller setup. Thank You, in advance

It is not clear what you are attempting to do and assuming could lead to wasted effort. Can you explain more?

I am wanting to turn on the Dehumidifier when the Humidity gets to a High Value (humidity_high) and off when humidity is (humidity_low). I want to verify the dehumidifier is off before activating the ON Button (which is connected to output relay from mycodo and is a "Soft Button). My input to verify if the Dehumidifier is on is a LOW or HIGH voltage from Dehumidifier to GPIO 27. Of course the input voltage to the GPIO will be 0 for off, 3.3v for on.
I hope this is helps. Thank You for you time!!

I still don’t understand the purpose of the input, but there are two things immediately wrong here:

  1. You should have two Actions, one to turn the Output on and another to turn the Output off.
  2. You should simply test whether dehumidifier_state is true, no equality check necessary (e.g. “if dehumidifier_state”, “if not dehumidifier_state”).

When in doubt, print a variable to the daemon log to see what it is, e.g.:

self.logger.info(f'{type(dehumidifier_state)}, {dehumidifier_state}')

Thank You! I can now see the input “dehumidifier_state” is in fact changing state, obviously I am not a programmer. The purpose of the input dehumidifier_state is a check to determine if it is already running, it has a soft off on button(momentary push) hence i activate the output for only 0.5s to mimic a human push. That is also why 1 output is needed. (on,off). I hope this makes sense now. I changed some code, maybe better?

humidity_high = 80 # percent
humidity_low = 70 # percent
humidity_value_present = self.condition("{126ec6d3}") # Sensor
dehumidifier_state = self.condition("{346ffdcb}") # GPIO Pin 27 as input

if humidity_value_present > humidity_high and dehumidifier_state == "(LOW)":
    self.run_action("{3e8c69da}")  # Action: dehumidifier_button on

if humidity_value_present < humidity_low and dehumidifier_state == "(HIGH)":
    self.run_action("{3e8c69da}")  # Action: dehumidifier_button off

self.logger.info(f'{type(dehumidifier_state)}, {dehumidifier_state}')

Okay, I understand now. Try this:

humidity_high = 80 # percent
humidity_low = 70 # percent
humidity_value_present = self.condition("{126ec6d3}") # Sensor
dehumidifier_state = self.condition("{346ffdcb}") # GPIO Pin 27 as input

if humidity_value_present > humidity_high and not dehumidifier_state:
    self.run_action("{3e8c69da}")  # Action: dehumidifier_button on

if humidity_value_present < humidity_low and dehumidifier_state:
    self.run_action("{3e8c69da}")  # Action: dehumidifier_button off

WOW!! Just a minor change has made the difference, seems to be working now, some fine adjustments maybe necessary. THANK YOU SO MUCH. FYI this episode has prompted me to start learning Python. To better use the pi with MyCodo. Thank You Again!! Can you tell me why it needed the “not” after the and?

You’re welcome.

An IF statement needs to be True for the code below it to be executed. When using an IF with “and”, both conditions must be true for the code to execute. Since the state of the GPIO can either be HIGH (True) or LOW (False), we have only 4 possible condition configurations, with only one set of conditions actually executing the code:

True and False = False
False and True = False
True and True = True
False and False = False

For any object that you can test the truthness of, you can test by simply using IF:

if my_var:
    pass

if not my_var:
    pass

If my_var is True, only the first statement will be true. However, if my_var is False, then the first statement will not execute, but the second will. This is because “not my_var” is equivalent to “not False”, and the opposite of False is True.

So, “if not False” is actually “if True”, and the code will execute, since only True conditions allow code to run.

That is why I am going to learn more about coding python. Again Thank You.