mirror of
https://github.com/nekorevend/esphome-emporia-vue-utility.git
synced 2026-01-09 13:00:38 -07:00
Merge remote-tracking branch 'upstream/main'
This commit is contained in:
@@ -50,10 +50,12 @@ class EmporiaVueUtility : public Component, public UARTDevice {
|
|||||||
Sensor *kWh_net = new Sensor();
|
Sensor *kWh_net = new Sensor();
|
||||||
Sensor *kWh_consumed = new Sensor();
|
Sensor *kWh_consumed = new Sensor();
|
||||||
Sensor *kWh_returned = new Sensor();
|
Sensor *kWh_returned = new Sensor();
|
||||||
Sensor *Wh_net = new Sensor();
|
Sensor *Wh_net = new Sensor();
|
||||||
Sensor *Wh_consumed = new Sensor();
|
Sensor *Wh_consumed = new Sensor();
|
||||||
Sensor *Wh_returned = new Sensor();
|
Sensor *Wh_returned = new Sensor();
|
||||||
Sensor *W = new Sensor();
|
Sensor *W = new Sensor();
|
||||||
|
Sensor *W_consumed = new Sensor();
|
||||||
|
Sensor *W_returned = new Sensor();
|
||||||
|
|
||||||
const char *TAG = "Vue";
|
const char *TAG = "Vue";
|
||||||
const uint8_t meter_reading_interval;
|
const uint8_t meter_reading_interval;
|
||||||
@@ -531,6 +533,13 @@ class EmporiaVueUtility : public Component, public UARTDevice {
|
|||||||
last_reading_has_error = 1;
|
last_reading_has_error = 1;
|
||||||
} else {
|
} else {
|
||||||
W->publish_state(watts);
|
W->publish_state(watts);
|
||||||
|
if (watts > 0) {
|
||||||
|
W_consumed->publish_state(watts);
|
||||||
|
W_returned->publish_state(0);
|
||||||
|
} else {
|
||||||
|
W_consumed->publish_state(0);
|
||||||
|
W_returned->publish_state(-watts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(watts);
|
return(watts);
|
||||||
}
|
}
|
||||||
@@ -550,6 +559,13 @@ class EmporiaVueUtility : public Component, public UARTDevice {
|
|||||||
last_reading_has_error = 1;
|
last_reading_has_error = 1;
|
||||||
} else {
|
} else {
|
||||||
W->publish_state(watts);
|
W->publish_state(watts);
|
||||||
|
if (watts > 0) {
|
||||||
|
W_consumed->publish_state(watts);
|
||||||
|
W_returned->publish_state(0);
|
||||||
|
} else {
|
||||||
|
W_consumed->publish_state(0);
|
||||||
|
W_returned->publish_state(-watts);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(watts);
|
return(watts);
|
||||||
}
|
}
|
||||||
@@ -601,7 +617,7 @@ class EmporiaVueUtility : public Component, public UARTDevice {
|
|||||||
int handle_resp_firmware_ver() {
|
int handle_resp_firmware_ver() {
|
||||||
struct Ver *ver;
|
struct Ver *ver;
|
||||||
ver = &input_buffer.ver;
|
ver = &input_buffer.ver;
|
||||||
|
|
||||||
mgm_firmware_ver = ver->value;
|
mgm_firmware_ver = ver->value;
|
||||||
|
|
||||||
ESP_LOGI(TAG, "MGM Firmware Version: %d", mgm_firmware_ver);
|
ESP_LOGI(TAG, "MGM Firmware Version: %d", mgm_firmware_ver);
|
||||||
@@ -682,6 +698,19 @@ class EmporiaVueUtility : public Component, public UARTDevice {
|
|||||||
|
|
||||||
msg_len = read_msg();
|
msg_len = read_msg();
|
||||||
now = ::time(&now);
|
now = ::time(&now);
|
||||||
|
|
||||||
|
/* sanity checks! */
|
||||||
|
if (next_meter_request >
|
||||||
|
now + (INITIAL_STARTUP_DELAY + METER_REJOIN_INTERVAL)) {
|
||||||
|
ESP_LOGD(TAG,
|
||||||
|
"Time jumped back (%lld > %lld + %lld); resetting",
|
||||||
|
(long long) next_meter_request,
|
||||||
|
(long long) now,
|
||||||
|
(long long) (INITIAL_STARTUP_DELAY +
|
||||||
|
METER_REJOIN_INTERVAL));
|
||||||
|
next_meter_request = next_meter_join = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (msg_len != 0) {
|
if (msg_len != 0) {
|
||||||
|
|
||||||
msg_type = input_buffer.data[2];
|
msg_type = input_buffer.data[2];
|
||||||
@@ -761,9 +790,8 @@ class EmporiaVueUtility : public Component, public UARTDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (now >= next_meter_request) {
|
if (now >= next_meter_request) {
|
||||||
|
// Handle initial startup delay
|
||||||
// Handle initial startup delay
|
if (next_meter_request == 0) {
|
||||||
if (next_meter_request == 0) {
|
|
||||||
next_meter_request = now + INITIAL_STARTUP_DELAY;
|
next_meter_request = now + INITIAL_STARTUP_DELAY;
|
||||||
next_meter_join = next_meter_request + METER_REJOIN_INTERVAL;
|
next_meter_join = next_meter_request + METER_REJOIN_INTERVAL;
|
||||||
return;
|
return;
|
||||||
@@ -778,13 +806,12 @@ class EmporiaVueUtility : public Component, public UARTDevice {
|
|||||||
next_meter_join = now + METER_REJOIN_INTERVAL;
|
next_meter_join = now + METER_REJOIN_INTERVAL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startup_step == 0) send_version_req();
|
if (startup_step == 0) send_version_req();
|
||||||
else if (startup_step == 1) send_mac_req();
|
else if (startup_step == 1) send_mac_req();
|
||||||
else if (startup_step == 2) send_install_code_req();
|
else if (startup_step == 2) send_install_code_req();
|
||||||
else if (startup_step == 3) send_meter_join();
|
else if (startup_step == 3) send_meter_join();
|
||||||
else send_meter_request();
|
else send_meter_request();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ api:
|
|||||||
|
|
||||||
mqtt:
|
mqtt:
|
||||||
broker: !secret mqtt_broker
|
broker: !secret mqtt_broker
|
||||||
id: vue-utility
|
id: vue_utility
|
||||||
username: !secret mqtt_username
|
username: !secret mqtt_username
|
||||||
password: !secret mqtt_password
|
password: !secret mqtt_password
|
||||||
discovery: False # Only if you use the HA API usually
|
discovery: False # Only if you use the HA API usually
|
||||||
@@ -42,7 +42,7 @@ sensor:
|
|||||||
lambda: |-
|
lambda: |-
|
||||||
auto vue = new EmporiaVueUtility(id(emporia_uart));
|
auto vue = new EmporiaVueUtility(id(emporia_uart));
|
||||||
App.register_component(vue);
|
App.register_component(vue);
|
||||||
return {vue->kWh_consumed, vue->kWh_returned, vue->W, vue->kWh_net};
|
return {vue->kWh_consumed, vue->kWh_returned, vue->W_consumed, vue->W_returned, vue->W, vue->kWh_net};
|
||||||
sensors:
|
sensors:
|
||||||
- name: "kWh Consumed"
|
- name: "kWh Consumed"
|
||||||
id: kWh_consumed
|
id: kWh_consumed
|
||||||
@@ -88,6 +88,44 @@ sensor:
|
|||||||
lambda: |-
|
lambda: |-
|
||||||
ESP_LOGI("Vue", "kWh = %0.3f", x);
|
ESP_LOGI("Vue", "kWh = %0.3f", x);
|
||||||
|
|
||||||
|
- name: "Watts consumed"
|
||||||
|
id: watts_consumed
|
||||||
|
unit_of_measurement: "W"
|
||||||
|
accuracy_decimals: 0
|
||||||
|
state_class: measurement
|
||||||
|
device_class: power
|
||||||
|
# Report every 5 minutes or when +/- 20 watts
|
||||||
|
filters:
|
||||||
|
- or:
|
||||||
|
- throttle: 5min
|
||||||
|
- delta: 20 # <- watts
|
||||||
|
- lambda: |-
|
||||||
|
if (id(fast_reporting)) return(x);
|
||||||
|
return {};
|
||||||
|
on_raw_value:
|
||||||
|
then:
|
||||||
|
lambda: |-
|
||||||
|
ESP_LOGI("Vue", "Watts consumed = %0.3f", x);
|
||||||
|
|
||||||
|
- name: "Watts returned"
|
||||||
|
id: watts_returned
|
||||||
|
unit_of_measurement: "W"
|
||||||
|
accuracy_decimals: 0
|
||||||
|
state_class: measurement
|
||||||
|
device_class: power
|
||||||
|
# Report every 5 minutes or when +/- 20 watts
|
||||||
|
filters:
|
||||||
|
- or:
|
||||||
|
- throttle: 5min
|
||||||
|
- delta: 20 # <- watts
|
||||||
|
- lambda: |-
|
||||||
|
if (id(fast_reporting)) return(x);
|
||||||
|
return {};
|
||||||
|
on_raw_value:
|
||||||
|
then:
|
||||||
|
lambda: |-
|
||||||
|
ESP_LOGI("Vue", "Watts returned = %0.3f", x);
|
||||||
|
|
||||||
- name: "Watts"
|
- name: "Watts"
|
||||||
id: watts
|
id: watts
|
||||||
unit_of_measurement: "W"
|
unit_of_measurement: "W"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ api:
|
|||||||
|
|
||||||
mqtt:
|
mqtt:
|
||||||
broker: !secret mqtt_broker
|
broker: !secret mqtt_broker
|
||||||
id: vue-utility
|
id: vue_utility
|
||||||
username: !secret mqtt_username
|
username: !secret mqtt_username
|
||||||
password: !secret mqtt_password
|
password: !secret mqtt_password
|
||||||
discovery: False # Only if you use the HA API usually
|
discovery: False # Only if you use the HA API usually
|
||||||
|
|||||||
Reference in New Issue
Block a user