/* DOMOTICZ MODULE Copyright (C) 2016-2017 by Xose PĂ©rez */ #if DOMOTICZ_SUPPORT #include bool _dczEnabled = false; //------------------------------------------------------------------------------ // Private methods //------------------------------------------------------------------------------ int _domoticzRelay(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); } } } }; //------------------------------------------------------------------------------ // Public API //------------------------------------------------------------------------------ template void domoticzSend(const char * key, T nvalue, const char * svalue) { if (!_dczEnabled) return; unsigned int idx = getSetting(key).toInt(); if (idx > 0) { char payload[128]; snprintf(payload, strlen(payload), "{\"idx\": %d, \"nvalue\": %s, \"svalue\": \"%s\"}", idx, String(nvalue).c_str(), svalue); mqttSendRaw(getSetting("dczTopicIn", DOMOTICZ_IN_TOPIC).c_str(), payload); } } template void domoticzSend(const char * key, T nvalue) { domoticzSend(key, nvalue, ""); } void domoticzSendRelay(unsigned int relayID) { if (!_dczEnabled) return; char buffer[15]; snprintf_P(buffer, strlen(buffer), PSTR("dczRelayIdx%d"), relayID); domoticzSend(buffer, relayStatus(relayID) ? "1" : "0"); } int domoticzIdx(unsigned int relayID) { char buffer[15]; snprintf_P(buffer, strlen(buffer), PSTR("dczRelayIdx%d"), relayID); return getSetting(buffer).toInt(); } void domoticzConfigure() { _dczEnabled = getSetting("dczEnabled", DOMOTICZ_ENABLED).toInt() == 1; } void domoticzSetup() { domoticzConfigure(); mqttRegister(_domoticzMqtt); } #endif