-
Notifications
You must be signed in to change notification settings - Fork 225
How can I get the accumulated energy in Watts/hour? (CON-1359) #1102
Copy link
Copy link
Closed
Description
How can I get the accumulated energy in Watts/hour?
I am using the electrical_power_measurement cluster and also the electrical_energy_measurement cluster, to obtain the current power data, such as voltage, alternating current and watts, but I do not know how to obtain the accumulated consumption data in watts/hour.
This is app_main.cpp code:
extern "C" void app_main()
{
esp_err_t err = ESP_OK;
nvs_flash_init();
app_driver_handle_t electrical_sensor_handle = app_driver_PZEM004T_sensor_init();
app_driver_handle_t light_handle = app_driver_light_init();
app_driver_handle_t button_handle = app_driver_button_init();
app_reset_button_register(button_handle);
node::config_t node_config;
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
if (node!=nullptr)
{
on_off_light::config_t on_off_light_config;
endpoint_t *light_endpoint = on_off_light::create(node, &on_off_light_config, ENDPOINT_FLAG_NONE, light_handle);
if (light_endpoint)
{
light_endpoint_id = endpoint::get_id(light_endpoint);
ESP_LOGI(TAG, "Light Endpoint: %d", light_endpoint_id);
}
electrical_sensor::config_t electrical_sensor_config;
endpoint_t *electrical_endpoint = electrical_sensor::create(node, &electrical_sensor_config, ENDPOINT_FLAG_NONE, electrical_sensor_handle);
if (electrical_endpoint)
{
electrical_endpoint_id = endpoint::get_id(electrical_endpoint);
ESP_LOGI(TAG, "Device energy management Endpoint: %d", electrical_endpoint_id);
}
cluster::electrical_power_measurement::config_t measurement_power_config;
esp_matter::cluster_t *epower_cluster = cluster::electrical_power_measurement::create(electrical_endpoint, &measurement_power_config, CLUSTER_FLAG_SERVER, cluster::electrical_power_measurement::feature::alternating_current::get_id());
cluster::electrical_energy_measurement::config_t measurement_energy_config;
esp_matter::cluster_t *energy_cluster = cluster::electrical_energy_measurement::create(electrical_endpoint, &measurement_energy_config, CLUSTER_FLAG_SERVER, cluster::electrical_energy_measurement::feature::cumulative_energy::get_id() | cluster::electrical_energy_measurement::feature::imported_energy::get_id());
int64_t Voltaje = 0;
int64_t Watios = 0;
int64_t Amperios = 0;
int64_t WatiosAcumulados = 0;
cluster::electrical_power_measurement::attribute::create_voltage(epower_cluster, Voltaje);
cluster::electrical_power_measurement::attribute::create_active_power(epower_cluster, Watios);
cluster::electrical_power_measurement::attribute::create_active_current(epower_cluster, Amperios);
cluster::electrical_power_measurement::attribute::create_reactive_power(epower_cluster, WatiosAcumulados);
cluster::electrical_energy_measurement::attribute::create_cumulative_energy_imported(energy_cluster,0, 8, 1);
esp_openthread_platform_config_t config = {.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(), .host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(), .port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),};
set_openthread_platform_config(&config);
err = esp_matter::start(app_event_cb);
if(err==ESP_OK)
{
esp_matter::console::diagnostics_register_commands();
esp_matter::console::init();
}
else
{
ESP_LOGE(TAG, "Fallo en el arranque de Matter, err:%d", err);
}
}
else
{
ESP_LOGE(TAG, "Fallo al crear el nodo de Matter");
}
}
Then in the app_driver.cpp file I added the lines to update the attributes:
static void PZEM004T(void *pvParameter)
{
struct current_values pzValues;
esp_matter_attr_val_t voltaje = esp_matter_invalid(NULL);
esp_matter_attr_val_t Amperios = esp_matter_invalid(NULL);
esp_matter_attr_val_t Watios = esp_matter_invalid(NULL);
esp_matter_attr_val_t WatiosAcumulados = esp_matter_invalid(NULL);
ESP_LOGI(TAG, "Starting PZEM004T ...");
while (1==1)
{
PzemGetValues(&pzValues);
voltaje.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
voltaje.val.i64 = pzValues.voltage;
Amperios.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
Amperios.val.i64 = pzValues.current;
Watios.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
Watios.val.i64 = pzValues.power;
WatiosAcumulados.type = esp_matter_val_type_t::ESP_MATTER_VAL_TYPE_INT64;
WatiosAcumulados.val.i64 = pzValues.energy;
esp_matter::attribute::update(electrical_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::Voltage::Id, &voltaje);
esp_matter::attribute::update(electrical_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::ActiveCurrent::Id, &Amperios);
esp_matter::attribute::update(electrical_endpoint_id, ElectricalPowerMeasurement::Id, ElectricalPowerMeasurement::Attributes::ActivePower::Id, &Watios);
esp_matter::attribute::update(electrical_endpoint_id, ElectricalEnergyMeasurement::Id, ElectricalEnergyMeasurement::Attributes::CumulativeEnergyImported::Id, &WatiosAcumulados);
vTaskDelay(DEFAULT_MEASURE_INTERVAL / portTICK_PERIOD_MS);
}
vTaskDelete(NULL);
}
However, the following errors appear:
I (181960) PZEM-004T: CRC check OK for GetValues()
I (181960) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 234 **********
I (181960) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (181960) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 6 **********
I (181960) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001 is 8 **********
I (181960) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 6 **********
I (181970) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 234 **********
I (181970) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (181970) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001 is <invalid type: 4> **********
E (181970) esp_matter_attribute: Insufficient space for reading Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001: required: 4, max: 2
I (181970) chip[EM]: <<< [E:29462i S:22429 M:5844842] (S) Msg TX to 2:000000000001B669 [5EE6] [UDP:[FDDE:AD00:BEEF:CAFE:AB3E:6390:CD80:EBF]:36687] --- Type 0001:05 (IM:ReportData)
I (182050) chip[EM]: >>> [E:29462i S:22429 M:43702472 (Ack:5844842)] (S) Msg RX from 2:000000000001B669 [5EE6] --- Type 0001:01 (IM:StatusResponse)
I (182050) chip[IM]: Received status response, status is 0x00
I (182050) chip[EM]: <<< [E:29462i S:22429 M:5844843 (Ack:43702472)] (S) Msg TX to 2:000000000001B669 [5EE6] [UDP:[FDDE:AD00:BEEF:CAFE:AB3E:6390:CD80:EBF]:36687] --- Type 0000:10 (SecureChannel:StandaloneAck)
I (202030) PZEM-004T: CRC check OK for GetValues()
I (202030) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 235 **********
I (202030) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (202030) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 6 **********
I (202030) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001 is 8 **********
I (202030) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 6 **********
I (202030) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 235 **********
I (202030) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (202030) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001 is <invalid type: 4> **********
E (202040) esp_matter_attribute: Insufficient space for reading Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001: required: 4, max: 2
I (202040) chip[EM]: <<< [E:29463i S:22429 M:5844844] (S) Msg TX to 2:000000000001B669 [5EE6] [UDP:[FDDE:AD00:BEEF:CAFE:AB3E:6390:CD80:EBF]:36687] --- Type 0001:05 (IM:ReportData)
I (202110) chip[EM]: >>> [E:29463i S:22429 M:43702473 (Ack:5844844)] (S) Msg RX from 2:000000000001B669 [5EE6] --- Type 0001:01 (IM:StatusResponse)
I (202110) chip[IM]: Received status response, status is 0x00
I (202110) chip[EM]: <<< [E:29463i S:22429 M:5844845 (Ack:43702473)] (S) Msg TX to 2:000000000001B669 [5EE6] [UDP:[FDDE:AD00:BEEF:CAFE:AB3E:6390:CD80:EBF]:36687] --- Type 0000:10 (SecureChannel:StandaloneAck)
I (222100) PZEM-004T: CRC check OK for GetValues()
I (222100) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 235 **********
I (222100) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (222100) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 6 **********
I (222100) esp_matter_attribute: ********** W : Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001 is 8 **********
I (222100) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000008 is 6 **********
I (222110) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000004 is 235 **********
I (222110) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000090's Attribute 0x00000005 is 0 **********
I (222110) esp_matter_attribute: ********** R : Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001 is <invalid type: 4> **********
E (222110) esp_matter_attribute: Insufficient space for reading Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001: required: 4, max: 2
I (222110) chip[EM]: <<< [E:29464i S:22429 M:5844846] (S) Msg TX to 2:000000000001B669 [5EE6] [UDP:[FDDE:AD00:BEEF:CAFE:AB3E:6390:CD80:EBF]:36687] --- Type 0001:05 (IM:ReportData)
I (222170) chip[EM]: >>> [E:29464i S:22429 M:43702474 (Ack:5844846)] (S) Msg RX from 2:000000000001B669 [5EE6] --- Type 0001:01 (IM:StatusResponse)
I (222170) chip[IM]: Received status response, status is 0x00
I (222170) chip[EM]: <<< [E:29464i S:22429 M:5844847 (Ack:43702474)] (S) Msg TX to 2:000000000001B669 [5EE6] [UDP:[FDDE:AD00:BEEF:CAFE:AB3E:6390:CD80:EBF]:36687] --- Type 0000:10 (SecureChannel:StandaloneAck)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels