Skip to content

Commit

Permalink
Add water heater to energy management app (#34886)
Browse files Browse the repository at this point in the history
* Refactored file location for chip-energy-management-app. Updated esp32 and linux build files.

* Updated some all-clusters-app build and CMakeLists (linux, esp32, psoc6)

* Updated remaining build and CMakefiles with new folders.

* Fixed unit tests BUILD.gn

* Restyled by gn

* Missed Ameba .cmake

* Missed all-clusters-minimal-app/esp32/main/CMakeLists.txt

* Added basic hooks to ESP32 to allow EVSE or Water Heater app

* Added initial WaterHeaterMain.cpp - needs rework

* Configure runner command to use --application <dem|eevse|whm> option

* Unify the WHM and EEVSE/DEM apps

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Rename application names

* Get ESP32 energy management app building with water-heater. Move water heater files from all-clusters-app to examples/energy-management-app/energy-management-common/water-heater

* Get WHM triggers working

* Get energy tests passing

* Add some more build infrastructure to set the DEM feature map

* Address review comments from James and fix some CI tests

* Restyled by clang-format

* Restyled by gn

* Undo changes to Objects.py

* Address review from James and fix forecast subscription issues

* Address review from James

* Added ENERGY_REPORTING_TRIGGERS option to ESP32 and updated ESP32 README.md

* Guard against a EVSE and WHM app being simultaneously defined

* Updated Linux README.md to highlight --application and --featureSet args.

* Fixed mis-spell

* Removed duplicate WaterHeaterMode::Shutdown()

* Fixed missing free of WaterHeaterMode and made a call to both EvseMain shutdown and WaterHeaterMain shutdown regardless of application mode.

* Restyled by whitespace

* Restyled by clang-format

* Applied code review comments, attempt to fix clang build failure with type in loop.

* Restyled by whitespace

* Restyled by clang-format

* Get DEM and EEM tests passing when running combined app in WHM mode

* Restyled by clang-format

* Ensure absMinPower and absMaxPower are set

* Fix CI build error

* Restyled by whitespace

* Restyled by clang-format

* Fix power levels so they fit within absMinPower and absMaxPower

* Fix definition of CHIP_DEVICE_CONFIG_ENABLE_ENERGY_REPORTING_TRIGGER

---------

Co-authored-by: Restyled.io <[email protected]>
Co-authored-by: pcoleman <[email protected]>
Co-authored-by: PeterC1965 <[email protected]>
  • Loading branch information
4 people authored and pull[bot] committed Aug 30, 2024
1 parent 50bcfed commit 1103358
Show file tree
Hide file tree
Showing 50 changed files with 1,031 additions and 144 deletions.
2 changes: 2 additions & 0 deletions examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(PRIV_INCLUDE_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/device-energy-management/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-evse/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-reporting/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/water-heater/include"
"${CMAKE_CURRENT_LIST_DIR}/include"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32"
Expand All @@ -36,6 +37,7 @@ set(SRC_DIRS_LIST
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/device-energy-management/src"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-evse/src"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/energy-reporting/src"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/energy-management-app/energy-management-common/water-heater/src"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common"
Expand Down
11 changes: 6 additions & 5 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ if (chip_enable_pw_rpc) {

source_set("chip-all-clusters-common") {
sources = [
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmDelegateImpl.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmInstance.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmMain.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/WhmManufacturer.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/air-quality-instance.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/binding-handler.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/boolcfg-stub.cpp",
Expand Down Expand Up @@ -62,7 +58,6 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-modes-manager.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/static-supported-temperature-levels.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/water-heater-mode.cpp",
"${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/common/src/EnergyTimeUtils.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/src/DeviceEnergyManagementDelegateImpl.cpp",
Expand All @@ -75,6 +70,11 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/EnergyEvseTargetsStore.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/src/energy-evse-mode.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/src/ElectricalPowerMeasurementDelegate.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmInstance.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmMain.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/WhmManufacturer.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/src/water-heater-mode.cpp",
"${chip_root}/examples/thermostat/thermostat-common/src/thermostat-delegate-impl.cpp",
"AllClustersCommandDelegate.cpp",
"AllClustersCommandDelegate.h",
Expand Down Expand Up @@ -102,6 +102,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/energy-management-app/energy-management-common/device-energy-management/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-evse/include",
"${chip_root}/examples/energy-management-app/energy-management-common/energy-reporting/include",
"${chip_root}/examples/energy-management-app/energy-management-common/water-heater/include",
"${chip_root}/examples/thermostat/thermostat-common/include",
]

Expand Down
1 change: 0 additions & 1 deletion examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ void ApplicationShutdown()
Clusters::WaterHeaterMode::Shutdown();

Clusters::WaterHeaterManagement::WhmApplicationShutdown();
Clusters::WaterHeaterMode::Shutdown();

if (sChipNamedPipeCommands.Stop() != CHIP_NO_ERROR)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <DeviceEnergyManagementDelegateImpl.h>

chip::app::Clusters::DeviceEnergyManagement::DeviceEnergyManagementDelegate * GetDEMDelegate();
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* limitations under the License.
*/

#include <DEMDelegate.h>
#include <DeviceEnergyManagementDelegateImpl.h>
#include <EVSEManufacturerImpl.h>
#include <app/clusters/device-energy-management-server/DeviceEnergyManagementTestEventTriggerHandler.h>
Expand All @@ -41,16 +42,6 @@ static chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustCapabili
static chip::app::DataModel::Nullable<chip::app::Clusters::DeviceEnergyManagement::Structs::PowerAdjustCapabilityStruct::Type>
sPowerAdjustmentCapability;

DeviceEnergyManagementDelegate * GetDEMDelegate()
{
EVSEManufacturer * mn = GetEvseManufacturer();
VerifyOrDieWithMsg(mn != nullptr, AppServer, "EVSEManufacturer is null");
DeviceEnergyManagementDelegate * dg = mn->GetDEMDelegate();
VerifyOrDieWithMsg(dg != nullptr, AppServer, "DEM Delegate is null");

return dg;
}

CHIP_ERROR ConfigureForecast(uint16_t numSlots)
{
uint32_t chipEpoch = 0;
Expand Down Expand Up @@ -92,9 +83,9 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots)

if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kPowerForecastReporting))
{
sSlots[0].nominalPower.SetValue(1500);
sSlots[0].minPower.SetValue(1000);
sSlots[0].maxPower.SetValue(2000);
sSlots[0].nominalPower.SetValue(2500000);
sSlots[0].minPower.SetValue(1200000);
sSlots[0].maxPower.SetValue(7600000);
}

sSlots[0].nominalEnergy.SetValue(2000);
Expand All @@ -119,9 +110,9 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots)

if (GetDEMDelegate()->HasFeature(DeviceEnergyManagement::Feature::kPowerForecastReporting))
{
sSlots[slotNo].nominalPower.SetValue(2 * sSlots[slotNo - 1].nominalPower.Value());
sSlots[slotNo].minPower.SetValue(2 * sSlots[slotNo - 1].minPower.Value());
sSlots[slotNo].maxPower.SetValue(2 * sSlots[slotNo - 1].maxPower.Value());
sSlots[slotNo].nominalPower.SetValue(sSlots[slotNo - 1].nominalPower.Value());
sSlots[slotNo].minPower.SetValue(sSlots[slotNo - 1].minPower.Value());
sSlots[slotNo].maxPower.SetValue(sSlots[slotNo - 1].maxPower.Value());

sSlots[slotNo].nominalEnergy.SetValue(2 * sSlots[slotNo - 1].nominalEnergy.Value());
}
Expand All @@ -134,10 +125,7 @@ CHIP_ERROR ConfigureForecast(uint16_t numSlots)

sForecastStruct.slots = DataModel::List<const DeviceEnergyManagement::Structs::SlotStruct::Type>(sSlots, numSlots);

EVSEManufacturer * mn = GetEvseManufacturer();
mn->GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct));
mn->GetDEMDelegate()->SetAbsMinPower(1000);
mn->GetDEMDelegate()->SetAbsMaxPower(256 * 2000 * 1000);
GetDEMDelegate()->SetForecast(DataModel::MakeNullable(sForecastStruct));

return CHIP_NO_ERROR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,14 @@ Status DeviceEnergyManagementDelegate::StartTimeAdjustRequest(const uint32_t req
mForecast.Value().startTime = savedStartTime;
mForecast.Value().endTime = savedEndTime;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);

return Status::Failure;
}
}

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);

return Status::Success;
}

Expand Down Expand Up @@ -457,10 +461,14 @@ Status DeviceEnergyManagementDelegate::PauseRequest(const uint32_t durationS, Ad
if (cause == AdjustmentCauseEnum::kLocalOptimization)
{
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kLocalOptimization;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
}
else if (cause == AdjustmentCauseEnum::kGridOptimization)
{
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kGridOptimization;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
}

return Status::Success;
Expand Down Expand Up @@ -606,6 +614,8 @@ Status DeviceEnergyManagementDelegate::ResumeRequest()
// The PauseRequest has effectively been cancelled so as a result the device should
// go back to InternalOptimisation
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
}

CHIP_ERROR err = CancelPauseRequestAndGenerateEvent(CauseEnum::kCancelled);
Expand Down Expand Up @@ -672,6 +682,8 @@ Status DeviceEnergyManagementDelegate::ModifyForecastRequest(
}

mForecast.Value().forecastID++;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
}

return status;
Expand Down Expand Up @@ -725,6 +737,8 @@ Status DeviceEnergyManagementDelegate::RequestConstraintBasedForecast(

mForecast.Value().forecastID++;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);

status = Status::Success;
}

Expand All @@ -748,6 +762,8 @@ Status DeviceEnergyManagementDelegate::CancelRequest()

mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);

/* It is expected the mpDEMManufacturerDelegate will cancel the effects of any previous adjustment
* request commands, and re-evaluate its forecast for intended operation ignoring those previous
* requests.
Expand Down Expand Up @@ -980,6 +996,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal
if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kLocalOptOut))
{
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
// Generate a new forecast with Internal Optimization
// TODO
}
Expand All @@ -988,6 +1006,8 @@ CHIP_ERROR DeviceEnergyManagementDelegate::SetOptOutState(OptOutStateEnum newVal
if ((mOptOutState == OptOutStateEnum::kOptOut) || (mOptOutState == OptOutStateEnum::kGridOptOut))
{
mForecast.Value().forecastUpdateReason = ForecastUpdateReasonEnum::kInternalOptimization;

MatterReportingAttributeChangeCallback(mEndpointId, DeviceEnergyManagement::Id, Forecast::Id);
// Generate a new forecast with Internal Optimization
// TODO
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,16 @@

#pragma once

#include <lib/core/CHIPError.h>

void EvseApplicationInit();
void EvseApplicationShutdown();

CHIP_ERROR DeviceEnergyManagementInit();
CHIP_ERROR DeviceEnergyManagementShutdown();

CHIP_ERROR EnergyMeterInit();
CHIP_ERROR EnergyMeterShutdown();

CHIP_ERROR PowerTopologyInit();
CHIP_ERROR PowerTopologyShutdown();
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ CHIP_ERROR EVSEManufacturer::Init()
/* For Device Energy Management we need the ESA to be Online and ready to accept commands */
dem->SetESAState(ESAStateEnum::kOnline);

// Set the abs min and max power
dem->SetAbsMinPower(1200000); // 1.2KW
dem->SetAbsMaxPower(7600000); // 7.6KW

/*
* This is an example implementation for manufacturers to consider
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ EVSEManufacturer * EnergyEvse::GetEvseManufacturer()
return gEvseManufacturer.get();
}

DeviceEnergyManagement::DeviceEnergyManagementDelegate * GetDEMDelegate()
{
VerifyOrDieWithMsg(gDEMDelegate.get() != nullptr, AppServer, "DEM Delegate is null");

return gDEMDelegate.get();
}

/*
* @brief Creates a Delegate and Instance for DEM
*
Expand Down Expand Up @@ -472,7 +479,7 @@ void EvseApplicationInit()

void EvseApplicationShutdown()
{
ChipLogDetail(AppServer, "Energy Management App: ApplicationShutdown()");
ChipLogDetail(AppServer, "Energy Management App (EVSE): ApplicationShutdown()");

/* Shutdown in reverse order that they were created */
EVSEManufacturerShutdown(); /* Free the EVSEManufacturer */
Expand Down
Loading

0 comments on commit 1103358

Please sign in to comment.