From e763c6ff66096ee4c60b88b2c34ffacfcfa0aa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Thu, 14 Jul 2022 01:21:44 +0200 Subject: [PATCH] trying to fix relay_controller state problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 687ea67..34ce2e7 100644 --- a/main.py +++ b/main.py @@ -24,13 +24,13 @@ def error_print(message: str): print('[ERROR]['+current_time+'] '+message) #relay -def relay_controller(pin: int, state): +def relay_controller(pin: int, state: str): print(state) - if state == True: + if state == "True": relay = gpiozero.OutputDevice(pin, active_high=True, initial_value=False) relay.on() debug_print("Set relay-pin "+str(pin)+" to state True") - elif state == False: + elif state == "False": relay = gpiozero.OutputDevice(pin, active_high=True, initial_value=False) relay.off() debug_print("Set relay-pin "+str(pin)+" to state False") @@ -92,24 +92,24 @@ def mqtt_on_message(client, userdata, msg): if topic == "strawberry-pi-greenhouse/relay/channel/1": if payload == "on": - relay_controller(channel_1, True) + relay_controller(channel_1, "True") elif payload == "off": - relay_controller(channel_1, False) + relay_controller(channel_1, "False") elif topic == "strawberry-pi-greenhouse/relay/channel/2": if payload == "on": - relay_controller(channel_2, True) + relay_controller(channel_2, "True") elif payload == "off": - relay_controller(channel_2, False) + relay_controller(channel_2, "False") elif topic == "strawberry-pi-greenhouse/relay/channel/3": if payload == "on": - relay_controller(channel_3, True) + relay_controller(channel_3, "True") elif payload == "off": - relay_controller(channel_3, False) + relay_controller(channel_3, "False") elif topic == "strawberry-pi-greenhouse/relay/channel/4": if payload == "on": - relay_controller(channel_4, True) + relay_controller(channel_4, "True") elif payload == "off": - relay_controller(channel_4, False) + relay_controller(channel_4, "False") if __name__ == "__main__":