Skip to content

Commit

Permalink
v2.2.3, more HA auto discovery tweaks/fixes
Browse files Browse the repository at this point in the history
- fixed (too) low memory allocation for JSON used by auto discovery in HA
  bug was introduced in v222 tweaking StaticJsonDocument a little too much
- changed/added icons for published entities; fixed typo in WiFi
- v223
  • Loading branch information
lrswss committed Sep 19, 2022
1 parent 24f686c commit 2839dca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
// to make Arduino IDE happy
// version number is set in platformio.ini
#ifndef FIRMWARE_VERSION
#define FIRMWARE_VERSION 222
#define FIRMWARE_VERSION 223
#endif

// set default port for MQTT over TLS
Expand Down
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ default_envs = d1_mini
description = Firmware for ESP8266 power meter

[common]
firmware_version = 222
firmware_version = 223
upload_speed = 460800
monitor_speed = 115200
port = /dev/tty.wchusbserial1410
Expand Down
18 changes: 10 additions & 8 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static PubSubClient *mqtt = NULL;
// published or deletes Home Assistant auto discovery message
// https://www.home-assistant.io/docs/mqtt/discovery/
static void publishHADiscoveryMessage(bool publish) {
StaticJsonDocument<256> JSON;
StaticJsonDocument<512> JSON;
JsonObject dev;
char buf[448], devTopic[96];
char topicTotalCon[80], topicPower[80], topicRSSI[80], topicRuntime[80], topicCount[80];
Expand All @@ -48,9 +48,9 @@ static void publishHADiscoveryMessage(bool publish) {
Serial.println(F("Sending home asssistant MQTT auto-discovery message"));

JSON.clear();
JSON["name"] = "Wifi Power Meter " + String(settings.systemID) + " Ferraris Impuls Counter";
JSON["name"] = "WiFi Power Meter " + String(settings.systemID) + " Ferraris Impuls Counter";
JSON["unique_id"] = "wifipowermeter-" + String(settings.systemID)+ "-impuls-counter";
JSON["ic"] = "mdi:counter";
JSON["ic"] = "mdi:rotate-360";
JSON["stat_t"] = devTopic;
JSON["val_tpl"] = "{{ value_json."+ String(MQTT_SUBTOPIC_CNT) +" }}";
dev = JSON.createNestedObject("dev");
Expand All @@ -66,8 +66,9 @@ static void publishHADiscoveryMessage(bool publish) {
delay(50);

JSON.clear();
JSON["name"] = "Wifi Power Meter " + String(settings.systemID) + " Total Consumption";
JSON["name"] = "WiFi Power Meter " + String(settings.systemID) + " Total Consumption";
JSON["unique_id"] = "wifipowermeter-" + String(settings.systemID)+ "-total-consumption";
JSON["ic"] = "mdi:counter";
JSON["unit_of_meas"] = "kWh";
JSON["dev_cla"] = "energy";
JSON["stat_cla"] = "total_increasing";
Expand All @@ -86,8 +87,9 @@ static void publishHADiscoveryMessage(bool publish) {
delay(50);

JSON.clear();
JSON["name"] = "Wifi Power Meter " + String(settings.systemID) + " Current Power Consumption";
JSON["name"] = "WiFi Power Meter " + String(settings.systemID) + " Current Power Consumption";
JSON["unique_id"] = "wifipowermeter-" + String(settings.systemID)+ "-current-power";
JSON["ic"] = "mdi:lightning-bolt";
JSON["unit_of_meas"] = "W";
JSON["dev_cla"] = "power";
JSON["stat_cla"] = "measurement";
Expand All @@ -106,7 +108,7 @@ static void publishHADiscoveryMessage(bool publish) {
delay(50);

JSON.clear();
JSON["name"] = "Wifi Power Meter " + String(settings.systemID) + " WiFi Signal Strength";
JSON["name"] = "WiFi Power Meter " + String(settings.systemID) + " WiFi Signal Strength";
JSON["unique_id"] = "wifipowermeter-" + String(settings.systemID)+ "-rssi";
JSON["unit_of_meas"] = "dbm";
JSON["dev_cla"] = "signal_strength";
Expand All @@ -125,7 +127,7 @@ static void publishHADiscoveryMessage(bool publish) {
delay(50);

JSON.clear();
JSON["name"] = "Wifi Power Meter " + String(settings.systemID) + " Uptime";
JSON["name"] = "WiFi Power Meter " + String(settings.systemID) + " Uptime";
JSON["unique_id"] = "wifipowermeter-" + String(settings.systemID)+ "-uptime";
JSON["ic"] = "mdi:clock-outline";
JSON["dev_cla"] = "duration";
Expand Down Expand Up @@ -283,7 +285,7 @@ static void publishDataSingle() {

// publish data on base topic as JSON
static void publishDataJSON() {
StaticJsonDocument<96> JSON;
StaticJsonDocument<160> JSON;
static char topicStr[128], buf[128];

JSON.clear();
Expand Down

0 comments on commit 2839dca

Please sign in to comment.