added relay_controller to mqtt_on_message if

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-14 01:14:27 +02:00
parent 264b35ed0b
commit a162bbf897
1 changed files with 13 additions and 8 deletions

21
main.py
View File

@ -82,26 +82,31 @@ def mqtt_on_message(client, userdata, msg):
topic = str(msg.topic)
payload = str(msg.payload.decode("utf-8"))
channel_1 = 4
channel_2 = 17
channel_3 = 27
channel_4 = 11
if topic == "strawberry-pi-greenhouse/relay/channel/1":
if payload == "on":
relay_ch_1.on()
relay_controller(channel_1, True)
elif payload == "off":
relay_ch_1.off()
relay_controller(channel_1, False)
elif topic == "strawberry-pi-greenhouse/relay/channel/2":
if payload == "on":
relay_ch_2.on()
relay_controller(channel_2, True)
elif payload == "off":
relay_ch_2.off()
relay_controller(channel_2, False)
elif topic == "strawberry-pi-greenhouse/relay/channel/3":
if payload == "on":
relay_ch_3.on()
relay_controller(channel_3, True)
elif payload == "off":
relay_ch_3.off()
relay_controller(channel_3, False)
elif topic == "strawberry-pi-greenhouse/relay/channel/4":
if payload == "on":
relay_ch_4.on()
relay_controller(channel_4, True)
elif payload == "off":
relay_ch_4.off()
relay_controller(channel_4, False)
if __name__ == "__main__":