esp-matter
esp-matter copied to clipboard
How can I get the accumulated energy in Watts/hour? (CON-1359)
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)
Have you been able to identify the cause of this error?
No
@JoseAntonioMG Power can be easily calculated using voltage and current, right? Please check https://github.com/espressif/esp-matter/issues/1092#issuecomment-2373977781 for the error you got.
@jadhavrohit924, i get the power from the PZEM004T, I also get the watts/hour. Have you seen the code I wrote above in the app_driver.cpp? The question is to assign the watts/hour values that I get from the PZEM004T to an attribute that is of accumulated energy, for this I have used the electrical_energy_measurement cluster, which has the attributes CumulativeEnergyImported, CumulativeEnergyExported, periodicEnergyImported and periodicEnergyExported. I suppose that these attributes are used to update the accumulated energy values (watts/hour) that are obtained from the PZEM004T device. However I have written the code above and the error occurs:
esp_matter_attribute: Insufficient space for reading Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001: required: 4, max: 2
I seen the #1092 comment and it does not solve the problem since electrical_energy_measurement does not have a delegate.
also i seen the #1075 comment, where you mention this problem but I do not know how it is implemented with SDK connectedhomeip. Is there no documentation on this? or an example code that clarifies how to do it?
Thanks for your interest.
@jadhavrohit924, i get the power from the PZEM004T, I also get the watts/hour. Have you seen the code I wrote above in the app_driver.cpp? The question is to assign the watts/hour values that I get from the PZEM004T to an attribute that is of accumulated energy, for this I have used the electrical_energy_measurement cluster, which has the attributes CumulativeEnergyImported, CumulativeEnergyExported, periodicEnergyImported and periodicEnergyExported. I suppose that these attributes are used to update the accumulated energy values (watts/hour) that are obtained from the PZEM004T device. However I have written the code above and the error occurs:
esp_matter_attribute: Insufficient space for reading Endpoint 0x0002's Cluster 0x00000091's Attribute 0x00000001: required: 4, max: 2I seen the #1092 comment and it does not solve the problem since electrical_energy_measurement does not have a delegate.
also i seen the #1075 comment, where you mention this problem but I do not know how it is implemented with SDK connectedhomeip. Is there no documentation on this? or an example code that clarifies how to do it?
Thanks for your interest.
For updating energy I've a working code:
on global:
#include <app/clusters/electrical-energy-measurement-server/electrical-energy-measurement-server.h>
chip::app::Clusters::ElectricalEnergyMeasurement::ElectricalEnergyMeasurementAttrAccess* energyMeasurementAccess;
Initializing the cluster:
esp_matter::cluster::electrical_energy_measurement::config_t energy_measurement_config;
auto cumulative_energy_feature = esp_matter::cluster::electrical_energy_measurement::feature::cumulative_energy::get_id();
auto exported_energy_feature = esp_matter::cluster::electrical_energy_measurement::feature::exported_energy::get_id();
auto relay_energy_measurement_cluster = esp_matter::cluster::electrical_energy_measurement::create(relay_endpoint, &energy_measurement_config, esp_matter::CLUSTER_FLAG_SERVER, cumulative_energy_feature | exported_energy_feature);
auto mask = chip::BitMask<chip::app::Clusters::ElectricalEnergyMeasurement::Feature>(chip::app::Clusters::ElectricalEnergyMeasurement::Feature::kCumulativeEnergy, chip::app::Clusters::ElectricalEnergyMeasurement::Feature::kExportedEnergy);
auto optionalmask = chip::BitMask<chip::app::Clusters::ElectricalEnergyMeasurement::OptionalAttributes>(chip::app::Clusters::ElectricalEnergyMeasurement::OptionalAttributes::kOptionalAttributeCumulativeEnergyReset);
energyMeasurementAccess = new chip::app::Clusters::ElectricalEnergyMeasurement::ElectricalEnergyMeasurementAttrAccess(mask,optionalmask);
// energyMeasurementAccess.mEndpointId=relay_endpoint_id;
auto initerr = energyMeasurementAccess->Init();
if (chip::ChipError::IsSuccess(initerr) == false) {
logger.E("energyMeasurementAccess->Init() ERR %u %u", initerr.GetRange(), initerr.GetValue());
}
chip::app::Clusters::ElectricalEnergyMeasurement::Structs::MeasurementAccuracyStruct::Type measurementAccuracy;
chip::app::Clusters::ElectricalEnergyMeasurement::Structs::MeasurementAccuracyRangeStruct::Type measurementAccuracyRange;
measurementAccuracy.measured = true;
measurementAccuracy.measurementType = chip::app::Clusters::detail::MeasurementTypeEnum::kElectricalEnergy;
measurementAccuracy.maxMeasuredValue = max_energy;
measurementAccuracy.minMeasuredValue = 0;
measurementAccuracyRange.rangeMax = max_energy;
measurementAccuracyRange.rangeMin = 0;
measurementAccuracyRange.percentMax.SetValue(energy_max_accuracy);
measurementAccuracyRange.percentMin.SetValue(energy_min_accuracy);
measurementAccuracyRange.percentTypical.SetValue(energy_typ_accuracy);
// measurementAccuracyRange.fixedMax.SetValue(187650443764698);
// measurementAccuracyRange.fixedMin.SetValue(187650443764696);
// measurementAccuracyRange.fixedTypical.SetValue(0);
measurementAccuracy.accuracyRanges = {measurementAccuracyRange};
// chip::app::Clusters::ElectricalEnergyMeasurement::
auto err = chip::app::Clusters::ElectricalEnergyMeasurement::SetMeasurementAccuracy(relay_endpoint_id, measurementAccuracy);
if (chip::ChipError::IsSuccess(err) == false) {
logger.E("SetMeasurementAccuracy ERR %u %u", err.GetRange(), err.GetValue()); // Change to log_e or your own logger
}
Then when an energy value is ready:
chip::app::Clusters::ElectricalEnergyMeasurement::Structs::EnergyMeasurementStruct::Type measurement;
measurement.startTimestamp.SetValue(energy_start_time); // Change to your marked start EPOCH time of energy
measurement.endTimestamp.SetValue(getEPOCHTime()); // Change to your own API to get EPOCH time (Or use systime APIs)
measurement.energy = value;
chip::DeviceLayer::StackLock lock;
auto success = chip::app::Clusters::ElectricalEnergyMeasurement::NotifyCumulativeEnergyMeasured(endpoint_id, {}, chip::Optional<chip::app::Clusters::ElectricalEnergyMeasurement::Structs::EnergyMeasurementStruct::Type> (measurement));
logger.I("NotifyCumulativeEnergyMeasured() -> %u", success);
Note that I have only one issue not solved for now: Energy accuracy, which reads out in chip-tool empty:
>>> electricalenergymeasurement read accuracy 0x2222 0x2
[1728767805.459424][26766:26766] CHIP:TOO: Command: electricalenergymeasurement read accuracy 0x2222 0x2
[1728767805.459642][26766:26787] CHIP:TOO: Sending command to node 0x2222
[1728767805.459856][26766:26787] CHIP:CSM: FindOrEstablishSession: PeerId = [1:0000000000002222]
[1728767805.459883][26766:26787] CHIP:CSM: FindOrEstablishSession: No existing OperationalSessionSetup instance found
[1728767805.459896][26766:26787] CHIP:DIS: Found an existing secure session to [1:0000000000002222]!
[1728767805.459922][26766:26787] CHIP:DIS: OperationalSessionSetup[1:0000000000002222]: State change 1 --> 5
[1728767805.459933][26766:26787] CHIP:TOO: Sending ReadAttribute to:
[1728767805.459960][26766:26787] CHIP:TOO: cluster 0x0000_0091, attribute: 0x0000_0000, endpoint 2
[1728767805.459985][26766:26787] CHIP:DMG: SendReadRequest ReadClient[0x7fade000a740]: Sending Read Request
[1728767805.460082][26766:26787] CHIP:EM: <<< [E:15914i S:29226 M:94832233] (S) Msg TX to 1:0000000000002222 [2858] [UDP:[fe80::6ab6:b3ff:fe52:b16c%eth0]:5540] --- Type 0001:02 (IM:ReadRequest)
[1728767805.460154][26766:26787] CHIP:DMG: MoveToState ReadClient[0x7fade000a740]: Moving to [AwaitingIn]
[1728767805.486474][26766:26787] CHIP:EM: >>> [E:15914i S:29226 M:100204619 (Ack:94832233)] (S) Msg RX from 1:0000000000002222 [2858] --- Type 0001:05 (IM:ReportData)
[1728767805.486517][26766:26787] CHIP:EM: Found matching exchange: 15914i, Delegate: 0x7fade000a750
[1728767805.486527][26766:26787] CHIP:EM: Rxd Ack; Removing MessageCounter:94832233 from Retrans Table on exchange 15914i
[1728767805.486569][26766:26787] CHIP:DMG: ReportDataMessage =
[1728767805.486595][26766:26787] CHIP:DMG: {
[1728767805.486619][26766:26787] CHIP:DMG: AttributeReportIBs =
[1728767805.486648][26766:26787] CHIP:DMG: [
[1728767805.486672][26766:26787] CHIP:DMG: AttributeReportIB =
[1728767805.486682][26766:26787] CHIP:DMG: {
[1728767805.486705][26766:26787] CHIP:DMG: AttributeDataIB =
[1728767805.486731][26766:26787] CHIP:DMG: {
[1728767805.486757][26766:26787] CHIP:DMG: DataVersion = 0x60e48cb3,
[1728767805.486763][26766:26787] CHIP:DMG: AttributePathIB =
[1728767805.486767][26766:26787] CHIP:DMG: {
[1728767805.486772][26766:26787] CHIP:DMG: Endpoint = 0x2,
[1728767805.486777][26766:26787] CHIP:DMG: Cluster = 0x91,
[1728767805.486782][26766:26787] CHIP:DMG: Attribute = 0x0000_0000,
[1728767805.486787][26766:26787] CHIP:DMG: }
[1728767805.486792][26766:26787] CHIP:DMG:
[1728767805.486814][26766:26787] CHIP:DMG: Data =
[1728767805.486821][26766:26787] CHIP:DMG: {
[1728767805.486827][26766:26787] CHIP:DMG: 0x0 = 0 (unsigned),
[1728767805.486866][26766:26787] CHIP:DMG: 0x1 = false,
[1728767805.486918][26766:26787] CHIP:DMG: 0x2 = 0 (signed),
[1728767805.486945][26766:26787] CHIP:DMG: 0x3 = 0 (signed),
[1728767805.486953][26766:26787] CHIP:DMG: 0x4 = [
[1728767805.486982][26766:26787] CHIP:DMG:
[1728767805.486991][26766:26787] CHIP:DMG: ],
[1728767805.486998][26766:26787] CHIP:DMG: },
[1728767805.487003][26766:26787] CHIP:DMG: },
[1728767805.487011][26766:26787] CHIP:DMG:
[1728767805.487017][26766:26787] CHIP:DMG: },
[1728767805.487023][26766:26787] CHIP:DMG:
[1728767805.487045][26766:26787] CHIP:DMG: ],
[1728767805.487054][26766:26787] CHIP:DMG:
[1728767805.487058][26766:26787] CHIP:DMG: SuppressResponse = true,
[1728767805.487081][26766:26787] CHIP:DMG: InteractionModelRevision = 11
[1728767805.487088][26766:26787] CHIP:DMG: }
[1728767805.487145][26766:26787] CHIP:TOO: Endpoint: 2 Cluster: 0x0000_0091 Attribute 0x0000_0000 DataVersion: 1625590963
[1728767805.487569][26766:26787] CHIP:TOO: Accuracy: {
[1728767805.487659][26766:26787] CHIP:TOO: MeasurementType: 0
[1728767805.487720][26766:26787] CHIP:TOO: Measured: FALSE
[1728767805.487746][26766:26787] CHIP:TOO: MinMeasuredValue: 0
[1728767805.487752][26766:26787] CHIP:TOO: MaxMeasuredValue: 0
[1728767805.487776][26766:26787] CHIP:TOO: AccuracyRanges: 0 entries
[1728767805.487853][26766:26787] CHIP:TOO: }
Update: I've just called to set measurement accuracy after the initialization process, and it worked.
Just ensure the Accuracy Ranges be a static or global; because the list of accuracy ranges is captured as a span.
@HamzaHajeir I'm going to try it, I'll tell you how it went.
Update: I've just called to set measurement accuracy after the initialization process, and it worked.
Just ensure the Accuracy Ranges be a static or global; because the list of accuracy ranges is captured as a span.
hi what exactly do you mean by "after the initialization process". could you please share the updated/working code?
hi what exactly do you mean by "after the initialization process". could you please share the updated/working code?
I meant after calling esp_matter::start() at minimum, I was beforehand setting the accuracy ranges before esp_matter get started.
thanks. i got the code working - at least partly. the reporting of the energy values only works for the first few seconds (~30). then i constantly get errors like the following:
I (947524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x000000000006008F due to overflow: event priority_level: 1
I (952524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060090 due to overflow: event priority_level: 1
I (957524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060091 due to overflow: event priority_level: 1
I (962524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060092 due to overflow: event priority_level: 1
I (967524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060093 due to overflow: event priority_level: 1
I (972524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060094 due to overflow: event priority_level: 1
do you have any idea what could cause this?
thanks. i got the code working - at least partly. the reporting of the energy values only works for the first few seconds (~30). then i constantly get errors like the following:
I (947524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x000000000006008F due to overflow: event priority_level: 1 I (952524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060090 due to overflow: event priority_level: 1 I (957524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060091 due to overflow: event priority_level: 1 I (962524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060092 due to overflow: event priority_level: 1 I (967524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060093 due to overflow: event priority_level: 1 I (972524) chip[EVL]: Dropped 1 event from buffer with priority 1 and event number 0x0000000000060094 due to overflow: event priority_level: 1do you have any idea what could cause this?
Not, really. Perhaps something in the command issuer?
I have a working example for solar_power device type: app_main.cpp.
The values are static, but it works.
My case is for ExportedEnergy feature and CumulativeEnergyExported attribute.
I had to modify the Home Assitant source code to display this attribute:
Now we need to find how to implement a delegate for ElectricalPowerMeasurement cluster.
@lboue Please take a look at esp-matter docs to implement a delegate for ElectricalPowerMeasurement cluster.
That's what I'm trying to do here, but for the moment I'm getting an error: https://github.com/espressif/esp-matter/issues/1411#issuecomment-2864013189
Now my ElectricalPowerMeasurementDelegate is working and Accuracy attribute value is OK. I need to find how to use the delegate to update attributes values.
Hi @lboue, Please could you share the code?
Sure. My code is here: https://github.com/lboue/esp-matter/blob/1497afab4d965c5d4fa338cc93ac790512593c8e/examples/solar_power/main/app_main.cpp#L118-L120
You also mentioned that you had to modify the HomeAssistant code, could you share that modification? thanks
I assume the HomeAssistant modifications to implement attribute retrieval are at:
https://github.com/home-assistant/core/pull/144430
Thanks @lboue, I'll implement the code you wrote and test it.
I assume the HomeAssistant modifications to implement attribute retrieval are at:
This PR for ElectricalEnergyMeasurement CumulativeEnergyExported attribute:
- https://github.com/home-assistant/core/pull/144061
But my issue with delegate is for ElectricalPowerMeasurement cluster.
I understand, however, I've implemented the ElectricalPowerMeasurement cluster and haven't had any issues (without a delegate). I also get the active power (watts), current (amps), and grid voltage (volts) attributes. And I can see them in HomeAssistant.
My problem is getting the CumulativeEnergyExported attribute from the ElectricalEnergyMeasurement cluster. I can't get that Cumulative Power value in HomeAssistant.
I understand, however, I've implemented the ElectricalPowerMeasurement cluster and haven't had any issues (without a delegate). I also get the active power (watts), current (amps), and grid voltage (volts) attributes. And I can see them in HomeAssistant. Yes, I agree, I've made the same observation.
The problem is that to define the ElectricalPowerMeasurement Accuracy attribute, which is mandatory. From my understanding, we have to use the delegate ElectricalPowerMeasurementDelegate.cpp#L189
. When it's start, it's no longer possible to do a classic update of attribute values.
That's why I'm trying to figure out how to do it with the delegate, so as to manage everything in the same place.
My problem is getting the CumulativeEnergyExported attribute from the ElectricalEnergyMeasurement cluster. I can't get that Cumulative Power value in HomeAssistant.
Yes https://github.com/home-assistant/core/pull/144061 is needed in a dev env for that until next release.
I'd like to do something similar to this implementation: ElectricalSensorManager.cpp#L209C1-L212C90
gEPMDelegate->SetPowerMode(kAttributes[updateState].PowerMode);
gEPMDelegate->SetVoltage(MakeNullable(kAttributes[updateState].Voltage));
gEPMDelegate->SetActiveCurrent(MakeNullable(kAttributes[updateState].ActiveCurrent));
gEPMDelegate->SetActivePower(MakeNullable(kAttributes[updateState].ActivePower));
Do I have to create Delegate and Instance for Electrical Power/Energy Measurement like here ElectricalSensorManager.cpp#L68-L80?
/*
* @brief Creates a Delegate and Instance for Electrical Power/Energy Measurement and Power Topology clusters
*
* The Instance is a container around the Delegate, so
* create the Delegate first, then wrap it in the Instance
* Then call the Instance->Init() to register the attribute and command handlers
*/
CHIP_ERROR ElectricalSensorManager::Init()
{
EndpointId EPMEndpointId = DataModelHelper::GetEndpointIdFromCluster(ElectricalPowerMeasurement::Id);
EndpointId EEMEndpointId = DataModelHelper::GetEndpointIdFromCluster(ElectricalEnergyMeasurement::Id);
EndpointId PTEndpointId = DataModelHelper::GetEndpointIdFromCluster(PowerTopology::Id);
CHIP_ERROR err;
I'd be grateful if you could give me an example of a similar implementation with esp-matter.
Regards
The example is out in all-device-types app please check the latest commit.
Can we close the issue, if it is resolved?