-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I get the accumulated energy in Watts/hour? (CON-1359) #1102
Comments
Have you been able to identify the cause of this error? |
No |
@JoseAntonioMG Power can be easily calculated using voltage and current, right? |
@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?
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. 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:
|
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. |
hi |
I meant after calling |
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:
Then in the app_driver.cpp file I added the lines to update the attributes:
However, the following errors appear:
The text was updated successfully, but these errors were encountered: