From 76c0ecac05fee2a362f92b619795450077049983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Wed, 23 May 2018 13:06:41 +0200 Subject: [PATCH] Send relay status to domoticz on MQTT connection (#872) --- code/espurna/domoticz.ino | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 6ffa0d61..d2622eca 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -43,7 +43,13 @@ void _domoticzMqtt(unsigned int type, const char * topic, const char * payload) String dczTopicOut = getSetting("dczTopicOut", DOMOTICZ_OUT_TOPIC); if (type == MQTT_CONNECT_EVENT) { + + // Subscribe to domoticz action topics mqttSubscribeRaw(dczTopicOut.c_str()); + + // Send relays state on connection + domoticzSendRelays(); + } if (type == MQTT_MESSAGE_EVENT) { @@ -138,6 +144,12 @@ void domoticzSendRelay(unsigned char relayID) { domoticzSend(buffer, relayStatus(relayID) ? "1" : "0"); } +void domoticzSendRelays() { + for (uint8_t relayID=0; relayID < relayCount(); relayID++) { + domoticzSendRelay(relayID); + } +} + unsigned int domoticzIdx(unsigned char relayID) { char buffer[15]; snprintf_P(buffer, sizeof(buffer), PSTR("dczRelayIdx%u"), relayID);