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!!
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}')
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?
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.