mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 10:19:29 +02:00
Improvements in events publication to trigger
state change in Home Assistant. Changed value_template and added millis to payload
This commit is contained in:
parent
47fa46ed4e
commit
fa880a5228
1 changed files with 5 additions and 2 deletions
|
@ -23,9 +23,9 @@ static void publish_events(void);
|
||||||
|
|
||||||
/** Publish global values and call callbacks for specific modules */
|
/** Publish global values and call callbacks for specific modules */
|
||||||
static void publish_values(void) {
|
static void publish_values(void) {
|
||||||
|
publish_events();
|
||||||
publish_common_info();
|
publish_common_info();
|
||||||
publish_cell_voltages();
|
publish_cell_voltages();
|
||||||
publish_events();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HA_AUTODISCOVERY
|
#ifdef HA_AUTODISCOVERY
|
||||||
|
@ -207,7 +207,9 @@ void publish_events() {
|
||||||
doc["state_topic"] = state_topic;
|
doc["state_topic"] = state_topic;
|
||||||
doc["unique_id"] = "battery-emulator_" + String(hostname) + "_event";
|
doc["unique_id"] = "battery-emulator_" + String(hostname) + "_event";
|
||||||
doc["object_id"] = String(hostname) + "_event";
|
doc["object_id"] = String(hostname) + "_event";
|
||||||
doc["value_template"] = "{{ value_json.message }}";
|
doc["value_template"] =
|
||||||
|
"{{ value_json.event_type ~ ' (c:' ~ value_json.count ~ ',m:' ~ value_json.milis ~ ') ' ~ value_json.message "
|
||||||
|
"}}";
|
||||||
doc["json_attributes_topic"] = state_topic;
|
doc["json_attributes_topic"] = state_topic;
|
||||||
doc["json_attributes_template"] = "{{ value_json | tojson }}";
|
doc["json_attributes_template"] = "{{ value_json | tojson }}";
|
||||||
doc["enabled_by_default"] = true;
|
doc["enabled_by_default"] = true;
|
||||||
|
@ -243,6 +245,7 @@ void publish_events() {
|
||||||
doc["count"] = String(event_pointer->occurences);
|
doc["count"] = String(event_pointer->occurences);
|
||||||
doc["data"] = String(event_pointer->data);
|
doc["data"] = String(event_pointer->data);
|
||||||
doc["message"] = String(get_event_message_string(event_handle));
|
doc["message"] = String(get_event_message_string(event_handle));
|
||||||
|
doc["milis"] = String(millis());
|
||||||
|
|
||||||
serializeJson(doc, mqtt_msg);
|
serializeJson(doc, mqtt_msg);
|
||||||
if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) {
|
if (!mqtt_publish(state_topic.c_str(), mqtt_msg, false)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue