Fixed issues with HA sensors

This commit is contained in:
Gunnar Skjold
2024-06-06 15:41:21 +02:00
parent 32afea2817
commit eeaaf088ac
2 changed files with 8 additions and 5 deletions

View File

@@ -10,6 +10,7 @@
#include "AmsMqttHandler.h"
#include "HomeAssistantStatic.h"
#include "AmsConfiguration.h"
#include "hexutils.h"
class HomeAssistantMqttHandler : public AmsMqttHandler {
public:
@@ -32,13 +33,15 @@ public:
deviceModel = boardTypeToString(boardType);
manufacturer = boardManufacturerToString(boardType);
char hostname[32];
#if defined(ESP8266)
String hostname = WiFi.hostname();
strcpy(hostname, WiFi.hostname());
#elif defined(ESP32)
String hostname = WiFi.getHostname();
strcpy(hostname, WiFi.getHostname());
#endif
deviceUid = hostname; // Maybe configurable in the future?
stripNonAscii((uint8_t*) hostname, 32, false);
deviceUid = String(hostname); // Maybe configurable in the future?
if(strlen(config.discoveryHostname) > 0) {
if(strncmp_P(config.discoveryHostname, PSTR("http"), 4) == 0) {

View File

@@ -80,8 +80,8 @@ const HomeAssistantSensor List4ExportSensors[List4ExportSensorCount] PROGMEM = {
const uint8_t RealtimeSensorCount PROGMEM = 8;
const HomeAssistantSensor RealtimeSensors[RealtimeSensorCount] PROGMEM = {
{"Month max", "/realtime","max", 120, "kWh", "energy", "measurement"},
{"Tariff threshold", "/realtime","threshold", 120, "kWh", "energy", "measurement"},
{"Month max", "/realtime","max", 120, "kWh", "energy", ""},
{"Tariff threshold", "/realtime","threshold", 120, "kWh", "energy", ""},
{"Current hour used", "/realtime","hour.use", 120, "kWh", "energy", "total_increasing"},
{"Current hour cost", "/realtime","hour.cost", 120, "", "monetary", ""},
{"Current day used", "/realtime","day.use", 120, "kWh", "energy", "total_increasing"},