From c2482e9913babf59996f118218416fd8ab5830b4 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 1 Nov 2020 13:26:35 +0100 Subject: [PATCH] Add command ``SwitchText`` Add command ``SwitchText`` to change JSON switch names by barbudor (#9691) --- CHANGELOG.md | 5 +++-- RELEASENOTES.md | 1 + tasmota/i18n.h | 1 + tasmota/support_command.ino | 18 ++++++++++++++++-- tasmota/support_tasmota.ino | 10 +++++++++- tasmota/tasmota.h | 1 + tasmota/xdrv_10_rules.ino | 2 +- 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd0c5dfb..46721cc27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,9 +9,10 @@ All notable changes to this project will be documented in this file. - Support for EZO O2 sensors by Christopher Tremblay (#9619) - Support for EZO PRS sensors by Christopher Tremblay (#9659) - Zigbee reduce battery drain (#9642) -- Zigbee added ``ZbMap`` command to describe Zigbee topology (#9651) -- Command ``Gpios 255`` to show all possible GPIO configurations +- Zigbee command ``ZbMap`` to describe Zigbee topology (#9651) - Zigbee command ``ZbOccupancy`` to configure the time-out for PIR +- Command ``Gpios 255`` to show all possible GPIO configurations +- Command ``SwitchText`` to change JSON switch names by barbudor (#9691) ### Changed - PlatformIO library structure redesigned for compilation speed by Jason2866 diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 3b118f86f..bd99d1ca7 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -64,6 +64,7 @@ The attached binaries can also be downloaded from http://ota.tasmota.com/tasmota - Command ``SwitchMode 15`` sending only MQTT message on switch change (#9593) - Command ``ShutterChange`` to increment change position (#9594) - Command ``SetOption113 1`` to set dimmer low on rotary dial after power off +- Command ``SwitchText`` to change JSON switch names by barbudor (#9691) - Zigbee command ``ZbData`` for better support of device specific data - Zigbee command ``ZbOccupancy`` to configure the time-out for PIR - Optional support for Mitsubishi Electric HVAC by David Gwynne (#9237) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index d19bf3144..1ac392eae 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -264,6 +264,7 @@ #define D_CMND_PWMRANGE "PWMRange" #define D_CMND_BUTTONDEBOUNCE "ButtonDebounce" #define D_CMND_SWITCHDEBOUNCE "SwitchDebounce" +#define D_CMND_SWITCHTEXT "SwitchText" #define D_CMND_SLEEP "Sleep" #define D_CMND_UPLOAD "Upload" #define D_CMND_UPGRADE "Upgrade" diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index dce94cc36..c4deba6ce 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -27,7 +27,7 @@ const char kTasmotaCommands[] PROGMEM = "|" // No prefix D_CMND_SERIALDELIMITER "|" D_CMND_IPADDRESS "|" D_CMND_NTPSERVER "|" D_CMND_AP "|" D_CMND_SSID "|" D_CMND_PASSWORD "|" D_CMND_HOSTNAME "|" D_CMND_WIFICONFIG "|" D_CMND_DEVICENAME "|" D_CMND_FRIENDLYNAME "|" D_CMND_SWITCHMODE "|" D_CMND_INTERLOCK "|" D_CMND_TELEPERIOD "|" D_CMND_RESET "|" D_CMND_TIME "|" D_CMND_TIMEZONE "|" D_CMND_TIMESTD "|" D_CMND_TIMEDST "|" D_CMND_ALTITUDE "|" D_CMND_LEDPOWER "|" D_CMND_LEDSTATE "|" D_CMND_LEDMASK "|" D_CMND_LEDPWM_ON "|" D_CMND_LEDPWM_OFF "|" D_CMND_LEDPWM_MODE "|" - D_CMND_WIFIPOWER "|" D_CMND_TEMPOFFSET "|" D_CMND_HUMOFFSET "|" D_CMND_SPEEDUNIT "|" D_CMND_GLOBAL_TEMP "|" D_CMND_GLOBAL_HUM "|" D_CMND_WIFI "|" + D_CMND_WIFIPOWER "|" D_CMND_TEMPOFFSET "|" D_CMND_HUMOFFSET "|" D_CMND_SPEEDUNIT "|" D_CMND_GLOBAL_TEMP "|" D_CMND_GLOBAL_HUM "|" D_CMND_WIFI "|" D_CMND_SWITCHTEXT "|" #ifdef USE_I2C D_CMND_I2CSCAN "|" D_CMND_I2CDRIVER "|" #endif @@ -54,7 +54,7 @@ void (* const TasmotaCommand[])(void) PROGMEM = { &CmndSerialDelimiter, &CmndIpAddress, &CmndNtpServer, &CmndAp, &CmndSsid, &CmndPassword, &CmndHostname, &CmndWifiConfig, &CmndDevicename, &CmndFriendlyname, &CmndSwitchMode, &CmndInterlock, &CmndTeleperiod, &CmndReset, &CmndTime, &CmndTimezone, &CmndTimeStd, &CmndTimeDst, &CmndAltitude, &CmndLedPower, &CmndLedState, &CmndLedMask, &CmndLedPwmOn, &CmndLedPwmOff, &CmndLedPwmMode, - &CmndWifiPower, &CmndTempOffset, &CmndHumOffset, &CmndSpeedUnit, &CmndGlobalTemp, &CmndGlobalHum, &CmndWifi, + &CmndWifiPower, &CmndTempOffset, &CmndHumOffset, &CmndSpeedUnit, &CmndGlobalTemp, &CmndGlobalHum, &CmndWifi, &CmndSwitchText, #ifdef USE_I2C &CmndI2cScan, CmndI2cDriver, #endif @@ -1611,6 +1611,20 @@ void CmndFriendlyname(void) } } +void CmndSwitchText(void) { + if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_SWITCHES)) { + if (!XdrvMailbox.usridx && !XdrvMailbox.data_len) { + ResponseCmndAll(SET_SWITCH_TXT1, MAX_SWITCHES); + } else { + if (XdrvMailbox.data_len > 0) { + RemoveSpace(XdrvMailbox.data); + SettingsUpdateText(SET_SWITCH_TXT1 + XdrvMailbox.index -1, ('"' == XdrvMailbox.data[0]) ? "" : XdrvMailbox.data); + } + ResponseCmndIdxChar(SettingsText(SET_SWITCH_TXT1 + XdrvMailbox.index -1)); + } + } +} + void CmndSwitchMode(void) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_SWITCHES)) { diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index ec4881d20..14d68b57b 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -739,6 +739,14 @@ void TempHumDewShow(bool json, bool pass_on, const char *types, float f_temperat } } +String GetSwitchText(uint32_t i) { + String switch_text = SettingsText(SET_SWITCH_TXT1 + i); + if ('\0' == switch_text[0]) { + switch_text = D_JSON_SWITCH + String(i +1); + } + return switch_text; +} + bool MqttShowSensor(void) { ResponseAppendTime(); @@ -750,7 +758,7 @@ bool MqttShowSensor(void) #else if (PinUsed(GPIO_SWT1, i)) { #endif // USE_TM1638 - ResponseAppend_P(PSTR(",\"" D_JSON_SWITCH "%d\":\"%s\""), i +1, GetStateText(SwitchState(i))); + ResponseAppend_P(PSTR(",\"%s\":\"%s\""), GetSwitchText(i).c_str(), GetStateText(SwitchState(i))); } } XsnsCall(FUNC_JSON_APPEND); diff --git a/tasmota/tasmota.h b/tasmota/tasmota.h index 442bf93aa..9484b8f2a 100644 --- a/tasmota/tasmota.h +++ b/tasmota/tasmota.h @@ -306,6 +306,7 @@ enum SettingsTextIndex { SET_OTAURL, #else // ESP32 SET_ADC_PARAM1, SET_ADC_PARAM2, SET_ADC_PARAM3, SET_ADC_PARAM4, SET_ADC_PARAM5, SET_ADC_PARAM6, SET_ADC_PARAM7, SET_ADC_PARAM8, // MAX_ADCS #endif + SET_SWITCH_TXT1, SET_SWITCH_TXT2, SET_SWITCH_TXT3, SET_SWITCH_TXT4, SET_SWITCH_TXT5, SET_SWITCH_TXT6, SET_SWITCH_TXT7, SET_SWITCH_TXT8, // MAX_SWITCHES SET_MAX }; enum DevGroupMessageType { DGR_MSGTYP_FULL_STATUS, DGR_MSGTYP_PARTIAL_UPDATE, DGR_MSGTYP_UPDATE, DGR_MSGTYP_UPDATE_MORE_TO_COME, DGR_MSGTYP_UPDATE_DIRECT, DGR_MSGTYPE_UPDATE_COMMAND, DGR_MSGTYPFLAG_WITH_LOCAL = 128 }; diff --git a/tasmota/xdrv_10_rules.ino b/tasmota/xdrv_10_rules.ino index c320adc14..528eb752b 100644 --- a/tasmota/xdrv_10_rules.ino +++ b/tasmota/xdrv_10_rules.ino @@ -854,7 +854,7 @@ void RulesEvery50ms(void) #else if (PinUsed(GPIO_SWT1, i)) { #endif // USE_TM1638 - snprintf_P(json_event, sizeof(json_event), PSTR("{\"" D_JSON_SWITCH "%d\":{\"Boot\":%d}}"), i +1, (SwitchState(i))); + snprintf_P(json_event, sizeof(json_event), PSTR("{\"%s\":{\"Boot\":%d}}"), GetSwitchText(i).c_str(), (SwitchState(i))); RulesProcessEvent(json_event); } }