mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-15 08:22:10 +00:00
first working discovery
This commit is contained in:
parent
03089e92cb
commit
2e4e4328f2
@ -7,6 +7,8 @@
|
||||
#include "web/root/ha3pf_json.h"
|
||||
#include "web/root/jsonsys_json.h"
|
||||
#include "web/root/jsonprices_json.h"
|
||||
#include "web/root/hadiscover1_json.h"
|
||||
#include "web/root/hadiscover2_json.h"
|
||||
|
||||
bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
if(topic.isEmpty() || !mqtt->connected())
|
||||
@ -27,7 +29,7 @@ bool HomeAssistantMqttHandler::publish(AmsData* data, AmsData* previousState) {
|
||||
data->getMeterModel().c_str(),
|
||||
data->getActiveImportPower(),
|
||||
data->getReactiveImportPower(),
|
||||
sequence, //data->getActiveExportPower(),
|
||||
data->getActiveExportPower(),
|
||||
data->getReactiveExportPower(),
|
||||
data->getL1Current(),
|
||||
data->getL2Current(),
|
||||
@ -244,8 +246,53 @@ bool HomeAssistantMqttHandler::publishSystem(HwTools* hw) {
|
||||
);
|
||||
mqtt->publish(topic + "/state", json);
|
||||
}
|
||||
if(sequence % 6 == 1 && listType > 0){ // every 60 ams message, publish mqtt discovery
|
||||
mqtt->publish(topic + "/discovery", "{\"discovery\":1}"); // test
|
||||
if(sequence % 60 == 1 && listType > 0){ // every 60 ams message, publish mqtt discovery
|
||||
char json[512];
|
||||
String haTopic = "homeassistant/sensor/";
|
||||
String haUID = "ams-3a08";
|
||||
|
||||
snprintf_P(json, sizeof(json), HADISCOVER1_JSON,
|
||||
"AMS reader status",
|
||||
(topic + "/state").c_str(),
|
||||
(topic + "/state").c_str(),
|
||||
(haUID + "_status").c_str(),
|
||||
(haUID + "_status").c_str(),
|
||||
"dB",
|
||||
"rssi",
|
||||
haUID.c_str(),
|
||||
"AMS reader",
|
||||
"ESP32",
|
||||
"2.0.0",
|
||||
"AmsToMqttBridge"
|
||||
);
|
||||
mqtt->publish(haTopic + haUID + "_status/config", json);
|
||||
|
||||
snprintf_P(json, sizeof(json), HADISCOVER2_JSON,
|
||||
"AMS active import",
|
||||
(topic + "/sensor").c_str(),
|
||||
(haUID + "_activeI").c_str(),
|
||||
(haUID + "_activeI").c_str(),
|
||||
"W",
|
||||
"P",
|
||||
"power",
|
||||
"measurement",
|
||||
haUID.c_str()
|
||||
);
|
||||
mqtt->publish(haTopic + haUID + "_activeI/config", json);
|
||||
|
||||
snprintf_P(json, sizeof(json), HADISCOVER2_JSON,
|
||||
"AMS accumulated active energy",
|
||||
(topic + "/sensor").c_str(),
|
||||
(haUID + "_accumI").c_str(),
|
||||
(haUID + "_accumI").c_str(),
|
||||
"kWh",
|
||||
"tPI",
|
||||
"energy",
|
||||
"total_increasing",
|
||||
haUID.c_str()
|
||||
);
|
||||
mqtt->publish(haTopic + haUID + "_accumI/config", json);
|
||||
|
||||
}
|
||||
if(listType>0) sequence++;
|
||||
return true;
|
||||
|
||||
@ -2,14 +2,16 @@
|
||||
"name" : "%s",
|
||||
"stat_t" : "%s",
|
||||
"json_attr_t" : "%s",
|
||||
"uniq_id" : "%s",
|
||||
"obj_id" : "%s",
|
||||
"unit_of_meas" : "%s",
|
||||
"val_tpl" : "{{value_json['%s']}}",
|
||||
"uniq_id" : "%s",
|
||||
"json_attr_tpl" : "{{ value_json }}",
|
||||
"dev" : {
|
||||
"ids" : [ "%s" ],
|
||||
"name" : "AMS reader",
|
||||
"mdl" : "ESP32",
|
||||
"sw" : "2.0.0",
|
||||
"mf" : "AmsToMqttBridge"
|
||||
"name" : "%s",
|
||||
"mdl" : "%s",
|
||||
"sw" : "%s",
|
||||
"mf" : "%s"
|
||||
}
|
||||
}
|
||||
}
|
||||
13
web/hadiscover2.json
Normal file
13
web/hadiscover2.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name" : "%s",
|
||||
"stat_t" : "%s",
|
||||
"uniq_id" : "%s",
|
||||
"obj_id" : "%s",
|
||||
"unit_of_meas" : "%s",
|
||||
"val_tpl" : "{{value_json['%s']}}",
|
||||
"dev_cla" : "%s",
|
||||
"stat_cla" : "%s",
|
||||
"dev" : {
|
||||
"ids" : [ "%s" ]
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user