diff --git a/code/espurna/domoticz.ino b/code/espurna/domoticz.ino index 6534b91f..bd33db03 100644 --- a/code/espurna/domoticz.ino +++ b/code/espurna/domoticz.ino @@ -8,6 +8,8 @@ Copyright (C) 2016-2017 by Xose PĂ©rez #if ENABLE_DOMOTICZ +#include + template void domoticzSend(const char * key, T nvalue, const char * svalue) { unsigned int idx = getSetting(key).toInt(); if (idx > 0) { @@ -21,4 +23,65 @@ template void domoticzSend(const char * key, T nvalue) { domoticzSend(key, nvalue, ""); } +void relayDomoticzSend(unsigned int relayID) { + char buffer[15]; + sprintf(buffer, "dczRelayIdx%d", relayID); + domoticzSend(buffer, relayStatus(relayID) ? "1" : "0"); +} + +int relayFromIdx(unsigned int idx) { + for (int relayID=0; relayID= 0) { + unsigned long value = root["nvalue"]; + DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); + relayStatus(relayID, value == 1); + } + + } + + } + + }); +} + + #endif diff --git a/code/espurna/espurna.ino b/code/espurna/espurna.ino index 3ff54f9d..e8edfd43 100644 --- a/code/espurna/espurna.ino +++ b/code/espurna/espurna.ino @@ -244,6 +244,9 @@ void setup() { #if ENABLE_EMON powerMonitorSetup(); #endif + #if ENABLE_DOMOTICZ + domoticzSetup(); + #endif // Prepare configuration for version 2.0 hwUpwardsCompatibility(); diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index 950167c9..ae50ca20 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -306,74 +306,6 @@ void relayWS() { wsSend(output.c_str()); } -//------------------------------------------------------------------------------ -// Domoticz -//------------------------------------------------------------------------------ - -#if ENABLE_DOMOTICZ - -void relayDomoticzSend(unsigned int relayID) { - char buffer[15]; - sprintf(buffer, "dczRelayIdx%d", relayID); - domoticzSend(buffer, relayStatus(relayID) ? "1" : "0"); -} - -int relayFromIdx(unsigned int idx) { - for (int relayID=0; relayID= 0) { - unsigned long value = root["nvalue"]; - DEBUG_MSG_P(PSTR("[DOMOTICZ] Received value %d for IDX %d\n"), value, idx); - relayStatus(relayID, value == 1); - } - - } - - } - - }); -} - -#endif - //------------------------------------------------------------------------------ // MQTT //------------------------------------------------------------------------------ @@ -495,9 +427,6 @@ void relaySetup() { relaySetupAPI(); relaySetupMQTT(); - #if ENABLE_DOMOTICZ - relayDomoticzSetup(); - #endif DEBUG_MSG_P(PSTR("[RELAY] Number of relays: %d\n"), _relays.size());