Skip to content

Commit

Permalink
Send relay status to domoticz on MQTT connection (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoseperez committed May 23, 2018
1 parent e44f96b commit 76c0eca
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions code/espurna/domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 76c0eca

Please sign in to comment.