lowpowermode missing in SYStoMQTT JSON - HA Logs a warning
I'm a first time user, so still learning
Describe the bug
OMG sends out MQTT autodiscovery messages that Home Assistant uses to build devices and entities, one such entity is sensor.sys_low_power_mode.
homeassistant/sensor/78218491ABB4-lowpowermode/config {
"stat_t":"home/OpenMQTTGateway_ESP32_LORA/SYStoMQTT",
"name":"SYS: Low Power Mode",
"uniq_id":"78218491ABB4-lowpowermode",
"val_tpl":"{{ value_json.lowpowermode }}",
"device":{"identifiers":["78218491ABB4"],
"name":"OpenMQTTGateway_ESP32_LORA",
"model":"[\"LORA\"]","manufacturer":"OMG_community",
"sw_version":"v0.9.16"}}
Periodically, the system sends out an mqtt SYStoMQTT update, however it does not contain the lowpowermode,
home/OpenMQTTGateway_ESP32_LORA/SYStoMQTT {"uptime":606,"version":"v0.9.16","freemem":257360,"mqttport":"1883","mqttsecure":false,"freestack":4632,"rssi":-70,"SSID":"myWiFi","BSSID":"C4:C4:C4:C4:C4:C4","ip":"192.168.3.45","mac":"78:78:78:78:78:78","modules":["LORA"]}
and subsequently HA logs a warning
2022-09-05 17:20:48.955 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'lowpowermode' when rendering '{{ value_json.lowpowermode }}'
Expected behavior A clear and concise description of what you expected to happen. Make lowpowermode available during status updates.
Screenshots If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
- OpenMQTTGateway version used: tagged v0.9.16. Visual Studio Code/platform.io compiled from source.
- default_envs = ttgo-lora32-v1-915
Additional context Add any other context about the problem here.
If I'm looking at the right place, in main.ino:
void stateMeasures() {
....
SYSdata["BSSID"] = BSSID;
SYSdata["ip"] = ip2CharArray(WiFi.localIP());
String mac = WiFi.macAddress();
SYSdata["mac"] = (char*)mac.c_str();
# endif
# endif
# ifdef ZgatewayBT
# ifdef ESP32
SYSdata["lowpowermode"] = (int)lowpowermode;
SYSdata["btqblck"] = btQueueBlocked;
SYSdata["btqsum"] = btQueueLengthSum;
SYSdata["btqsnd"] = btQueueLengthCount;
SYSdata["btqavg"] = (btQueueLengthCount > 0 ? btQueueLengthSum / (float)btQueueLengthCount : 0);
# endif
SYSdata["interval"] = BLEinterval;
SYSdata["scanbcnct"] = BLEscanBeforeConnect;
SYSdata["scnct"] = scanCount;
# endif
....
This is the only place lowpowermode exists in this routine and seems it is only sent if its ZgatewayBT that's using ESP32.
My gateway is ZgatewayLORA which also uses an ESP32.
Whereas in the file ZmqttDiscovery.ino
The auto-discovery message for the lowpowermode sensor is created when ifdef ESP32 and appears to be independent of ZgatewayXXX.
It seems the stateMeasures() is missing a separate ifdef ESP32 for lowpowermode for other gateway types.