trying to fix relay_controller state problem

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-14 01:21:44 +02:00
parent 09d2db4821
commit e763c6ff66
1 changed files with 11 additions and 11 deletions

22
main.py
View File

@ -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__":