Fix domoticz topic edge case

This commit is contained in:
Theo Arends 2023-12-25 14:18:59 +01:00
parent d39896f6a2
commit 77a58a3642
2 changed files with 29 additions and 9 deletions

View File

@ -15,7 +15,7 @@ All notable changes to this project will be documented in this file.
### Changed
- Support syslog updates every sleep or every second if `#define SYSLOG_UPDATE_SECOND` (#20260)
- Moved Berry animate to its own `berry_animate` lib
- Moved Berry animate to its own `berry_animate` lib (#20309)
### Fixed
- Matter Contact sensor was not triggering any update (#20232)

View File

@ -18,10 +18,29 @@
*/
#ifdef USE_DOMOTICZ
/*********************************************************************************************\
* Domoticz support
*
* Adds commands:
* DzIdx<number> <idx> - Set power number to Domoticz Idx allowing Domoticz to control Tasmota power
* DzKeyIdx<number> <idx> - Set button number to Domoticz Idx allowing Tasmota button as input to Domoticz
* DzSwitchId<number> <idx> - Set switch number to Domoticz Idx allowing Tasmota switch as input to Domoticz
* DzSensorIdx<type> <idx> - Set sensor type to Domoticz Idx
* DzUpdateTimer 0 - Send power state at teleperiod to Domoticz (default)
* DzUpdateTimer <seconds> - Send power state at <seconds> interval to Domoticz
* DzSend1 <idx>,<values> - {\"idx\":<idx>,\"nvalue\":0,\"svalue\":\"<values>\",\"Battery\":xx,\"RSSI\":yy}
* Example: rule1 on power1#state do dzsend1 9001,%value% endon
* DzSend1 418,%var1%;%var2% or DzSend1 418,%var1%:%var2% - Notice colon as substitute to semi-colon
* DzSend2 <idx>,<values> - USE_SHUTTER only - {\"idx\":<idx>,\"nvalue\":<position>,\"svalue\":\"<values>\",\"Battery\":xx,\"RSSI\":yy}
* DzSend3 <idx>,<values> - {\"idx\":<idx>,\"nvalue\":<values>,\"Battery\":xx,\"RSSI\":yy}
* DzSend4 <idx>,<state> - {\"command\":\"switchlight\",\"idx\":<idx>,\"switchcmd\":\"<state>\"}
* DzSend5 <idx>,<state> - {\"command\":\"switchscene\",\"idx\":<idx>,\"switchcmd\":\"<state>\"}
\*********************************************************************************************/
#define XDRV_07 7
//#define D_PRFX_DOMOTICZ "Domoticz"
//#define USE_DOMOTICZ_DEBUG // Enable additional debug logging
#define D_PRFX_DOMOTICZ "Dz"
#define D_CMND_IDX "Idx"
#define D_CMND_KEYIDX "KeyIdx"
@ -218,16 +237,17 @@ bool DomoticzMqttData(void) {
return true; // No valid data
}
// char dom_data[XdrvMailbox.data_len +1];
// strcpy(dom_data, XdrvMailbox.data);
// AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ "Topic '%s', Data '%s'"), XdrvMailbox.topic, RemoveControlCharacter(dom_data));
#ifdef USE_DOMOTICZ_DEBUG
char dom_data[XdrvMailbox.data_len +1];
strcpy(dom_data, XdrvMailbox.data);
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ "%s = %s"), XdrvMailbox.topic, RemoveControlCharacter(dom_data));
#endif // USE_DOMOTICZ_DEBUG
// Quick check if this is mine using topic domoticz/out/{$idx}
if (strlen(XdrvMailbox.topic) > strlen(DOMOTICZ_OUT_TOPIC)) {
char* topic_index = &XdrvMailbox.topic[strlen(DOMOTICZ_OUT_TOPIC) +1];
int32_t top_index = atoi(topic_index); // 0 if no number (in case of domoticz/out/floor/room)
if (top_index > 0) {
if (DomoticzIdx2Relay(top_index) < 0) {
if (strchr(topic_index, '/') == nullptr) { // Skip if topic ...floor/room
if (DomoticzIdx2Relay(atoi(topic_index)) < 0) {
return true; // Idx not mine
}
}
@ -248,7 +268,7 @@ bool DomoticzMqttData(void) {
return true; // Nvalue out of boundaries
}
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ "Topic %s, idx %d, nvalue %d"), XdrvMailbox.topic, Settings->domoticz_relay_idx[relay_index], nvalue);
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR(D_LOG_DOMOTICZ "%s, idx %d, nvalue %d"), XdrvMailbox.topic, Settings->domoticz_relay_idx[relay_index], nvalue);
bool iscolordimmer = (strcmp_P(domoticz.getStr(PSTR("dtype")), PSTR("Color Switch")) == 0);
bool isShutter = (strcmp_P(domoticz.getStr(PSTR("dtype")), PSTR("Light/Switch")) == 0) && (strncmp_P(domoticz.getStr(PSTR("switchType")),PSTR("Blinds"), 6) == 0);