mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-17 17:03:12 +00:00
Added static HA content to progmem
This commit is contained in:
parent
cbbb52d32a
commit
2ef1700cfe
@ -32,6 +32,7 @@ ADC_MODE(ADC_VCC);
|
||||
|
||||
#include "hexutils.h"
|
||||
#include "HwTools.h"
|
||||
|
||||
#include "entsoe/EntsoeApi.h"
|
||||
|
||||
#include "web/AmsWebServer.h"
|
||||
|
||||
@ -106,6 +106,10 @@ bool EnergyAccounting::update(AmsData* amsData) {
|
||||
if(debugger->isActive(RemoteDebug::VERBOSE)) debugger->printf("(EnergyAccounting) new threshold %d\n", currentThresholdIdx);
|
||||
}
|
||||
|
||||
if(use > data.maxHour) {
|
||||
data.maxHour = use; // Not really a good idea to use calculated value, but when you pass midnight and have the highest use at hour 23, it will not be included through 'calcDayUse'
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include "HomeAssistantMqttHandler.h"
|
||||
#include "HomeAssistantStatic.h"
|
||||
#include "hexutils.h"
|
||||
#include "Uptime.h"
|
||||
#include "version.h"
|
||||
@ -213,32 +214,32 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw) {
|
||||
String haUrl = "http://" + haUID + ".local/";
|
||||
|
||||
for(int i=0;i<sensors;i++){
|
||||
if(stacl[i].length() > 0) { // TODO: reduce to single JSON, state_class: null (witout quotation). or make it some extra optional string that us appended
|
||||
if(strlen(HA_STACL[i]) > 0) { // TODO: reduce to single JSON, state_class: null (witout quotation). or make it some extra optional string that us appended
|
||||
snprintf_P(json, BufferSize, HADISCOVER2_JSON,
|
||||
names[i].c_str(), // name
|
||||
(topic + topics[i]).c_str(), // state_topic
|
||||
(haUID + "_" + params[i]).c_str(), // unique_id
|
||||
(haUID + "_" + params[i]).c_str(), // object_id
|
||||
uom[i].c_str(), // unit_of_measurement
|
||||
params[i].c_str(), // value_template
|
||||
devcl[i].c_str(), // device_class
|
||||
HA_NAMES[i], // name
|
||||
(topic + HA_TOPICS[i]), // state_topic
|
||||
(haUID + "_" + HA_PARAMS[i]), // unique_id
|
||||
(haUID + "_" + HA_PARAMS[i]), // object_id
|
||||
HA_UOM[i], // unit_of_measurement
|
||||
HA_PARAMS[i], // value_template
|
||||
HA_DEVCL[i], // device_class
|
||||
haUID.c_str(), // dev ids
|
||||
haName.c_str(), // name
|
||||
haModel.c_str(), // model
|
||||
VERSION, // fw version
|
||||
haManuf.c_str(), // manufacturer
|
||||
haUrl.c_str(), // configuration_url
|
||||
stacl[i].c_str() // state_class
|
||||
HA_STACL[i] // state_class
|
||||
);
|
||||
} else {
|
||||
snprintf_P(json, BufferSize, HADISCOVER1_JSON,
|
||||
names[i].c_str(), // name
|
||||
(topic + topics[i]).c_str(), // state_topic
|
||||
(haUID + "_" + params[i]).c_str(), // unique_id
|
||||
(haUID + "_" + params[i]).c_str(), // object_id
|
||||
uom[i].c_str(), // unit_of_measurement
|
||||
params[i].c_str(), // value_template
|
||||
devcl[i].c_str(), // device_class
|
||||
HA_NAMES[i], // name
|
||||
(topic + HA_TOPICS[i]).c_str(), // state_topic
|
||||
(haUID + "_" + HA_PARAMS[i]).c_str(), // unique_id
|
||||
(haUID + "_" + HA_PARAMS[i]).c_str(), // object_id
|
||||
HA_UOM[i], // unit_of_measurement
|
||||
HA_PARAMS[i], // value_template
|
||||
HA_DEVCL[i], // device_class
|
||||
haUID.c_str(), // dev ids
|
||||
haName.c_str(), // name
|
||||
haModel.c_str(), // model
|
||||
@ -247,7 +248,7 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw) {
|
||||
haUrl.c_str() // configuration_url
|
||||
);
|
||||
}
|
||||
mqtt->publish(haTopic + haUID + "_" + params[i] + "/config", json, true, 0);
|
||||
mqtt->publish(haTopic + haUID + "_" + HA_PARAMS[i] + "/config", json, true, 0);
|
||||
}
|
||||
autodiscoverInit = true;
|
||||
}
|
||||
|
||||
@ -17,13 +17,6 @@ public:
|
||||
|
||||
private:
|
||||
static const uint8_t sensors = 17;
|
||||
String topics[sensors] = {"/state", "/state", "/state", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/energy", "/energy", "/energy", "/energy"};
|
||||
String names[sensors] = {"Status", "Supply volt", "Temperature", "Active import", "Reactive import", "Active export", "Reactive export", "L1 current", "L2 current", "L3 current",
|
||||
"L1 voltage", "L2 voltage", "L3 voltage", "Accumulated active import", "Accumulated active export", "Accumulated reactive import", "Accumulated reactive export"};
|
||||
String params[sensors] = {"rssi", "vcc", "temp", "P", "Q", "PO", "QO", "I1", "I2", "I3", "U1", "U2", "U3", "tPI", "tPO", "tQI", "tQO"};
|
||||
String uom[sensors] = {"dBm", "V", "C", "W", "W", "W", "W", "A", "A", "A", "V", "V", "V", "kWh", "kWh", "kWh", "kWh"};
|
||||
String devcl[sensors] = {"signal_strength", "voltage", "temperature", "power", "power", "power", "power", "current", "current", "current", "voltage", "voltage", "voltage", "energy", "energy", "energy", "energy"};
|
||||
String stacl[sensors] = {"", "", "", "measurement", "measurement", "measurement", "measurement", "", "", "", "", "", "", "total_increasing", "total_increasing", "total_increasing", "total_increasing"};
|
||||
|
||||
String haTopic = "homeassistant/sensor/";
|
||||
|
||||
|
||||
14
src/mqtt/HomeAssistantStatic.h
Normal file
14
src/mqtt/HomeAssistantStatic.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _HOMEASSISTANTSTATIC_H
|
||||
#define _HOMEASSISTANTSTATIC_H
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
const char* HA_TOPICS[17] PROGMEM = {"/state", "/state", "/state", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/power", "/energy", "/energy", "/energy", "/energy"};
|
||||
const char* HA_NAMES[17] PROGMEM = {"Status", "Supply volt", "Temperature", "Active import", "Reactive import", "Active export", "Reactive export", "L1 current", "L2 current", "L3 current",
|
||||
"L1 voltage", "L2 voltage", "L3 voltage", "Accumulated active import", "Accumulated active export", "Accumulated reactive import", "Accumulated reactive export"};
|
||||
const char* HA_PARAMS[17] PROGMEM = {"rssi", "vcc", "temp", "P", "Q", "PO", "QO", "I1", "I2", "I3", "U1", "U2", "U3", "tPI", "tPO", "tQI", "tQO"};
|
||||
const char* HA_UOM[17] PROGMEM = {"dBm", "V", "C", "W", "W", "W", "W", "A", "A", "A", "V", "V", "V", "kWh", "kWh", "kWh", "kWh"};
|
||||
const char* HA_DEVCL[17] PROGMEM = {"signal_strength", "voltage", "temperature", "power", "power", "power", "power", "current", "current", "current", "voltage", "voltage", "voltage", "energy", "energy", "energy", "energy"};
|
||||
const char* HA_STACL[17] PROGMEM = {"", "", "", "measurement", "measurement", "measurement", "measurement", "", "", "", "", "", "", "total_increasing", "total_increasing", "total_increasing", "total_increasing"};
|
||||
|
||||
#endif
|
||||
Loading…
x
Reference in New Issue
Block a user