diff --git a/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp b/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp index fa4798c678fff2..024d70a33f60f0 100644 --- a/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp +++ b/examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp @@ -19,6 +19,7 @@ #include "AppTask.h" #include "PWMDevice.h" +#include #include #include #include @@ -26,6 +27,7 @@ using namespace chip; using namespace chip::app::Clusters; +using namespace chip::app::Clusters::OnOff; void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) @@ -70,5 +72,17 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfOnOffClusterInitCallback(EndpointId endpoint) { + EmberAfStatus status; + bool storedValue; + + // Read storedValue on/off value + status = Attributes::OnOff::Get(endpoint, &storedValue); + if (status == EMBER_ZCL_STATUS_SUCCESS) + { + // Set actual state to the cluster state that was last persisted + GetAppTask().GetLightingDevice().InitiateAction(storedValue ? PWMDevice::ON_ACTION : PWMDevice::OFF_ACTION, + AppEvent::kEventType_Lighting, reinterpret_cast(&storedValue)); + } + GetAppTask().UpdateClusterState(); }