From a162bbf897b1133243cdb3c5f8d7a0f247f71f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Thu, 14 Jul 2022 01:14:27 +0200 Subject: [PATCH] added relay_controller to mqtt_on_message if MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index ed50bc6..9311190 100644 --- a/main.py +++ b/main.py @@ -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__":