ZigbeePilotWireControl Library
Zigbee Pilot Wire Control Library
Loading...
Searching...
No Matches
ZigbeePilotWireControl.h
1
4#pragma once
5
6#include <soc/soc_caps.h>
7#include <sdkconfig.h>
8
9#if ! CONFIG_ZB_ENABLED
10#error "This library requires Zigbee support to be enabled in sdkconfig"
11#endif // CONFIG_ZB_ENABLED
12
13#include <ZigbeeEP.h>
14#include <ha/esp_zigbee_ha_standard.h>
15#include <Preferences.h>
16
24#ifndef PILOT_WIRE_MANUF_NAME
25#define PILOT_WIRE_MANUF_NAME "EpsilonRT"
26#endif
27
35#ifndef PILOT_WIRE_MODEL_NAME
36#define PILOT_WIRE_MODEL_NAME "ERT-MPZ-03"
37#endif
38
47#ifndef PILOT_WIRE_MANUF_CODE
48#define PILOT_WIRE_MANUF_CODE 0x1234
49#endif
50
55#define PILOT_WIRE_CLUSTER_ID 0xFC00
56
60#define PILOT_WIRE_MODE_ATTR_ID 0x0000
61
66enum ZigbeePilotWireMode : uint8_t {
67 PILOTWIRE_MODE_OFF = 0,
68 PILOTWIRE_MODE_COMFORT,
69 PILOTWIRE_MODE_ECO,
70 PILOTWIRE_MODE_FROST_PROTECTION,
71 PILOTWIRE_MODE_COMFORT_MINUS_1,
72 PILOTWIRE_MODE_COMFORT_MINUS_2
73};
74
79const ZigbeePilotWireMode PILOTWIRE_MODE_MIN = PILOTWIRE_MODE_OFF;
80
85const ZigbeePilotWireMode PILOTWIRE_MODE_MAX = PILOTWIRE_MODE_COMFORT_MINUS_2;
86
91const uint8_t PILOTWIRE_MODE_COUNT = (PILOTWIRE_MODE_COMFORT_MINUS_2 - PILOTWIRE_MODE_OFF + 1);
92
99 public:
107 ZigbeePilotWireControl (uint8_t endpoint);
108
118 ZigbeePilotWireControl (uint8_t endpoint, float tempMin, float tempMax);
119
129 ZigbeePilotWireControl (uint8_t endpoint, uint32_t meteringMultiplier);
130
141 ZigbeePilotWireControl (uint8_t endpoint, float tempMin, float tempMax, uint32_t meteringMultiplier);
142
155 void onPilotWireModeChange (void (*callback) (ZigbeePilotWireMode mode)) {
156 _on_mode_change = callback;
157 }
158
166 bool begin ();
167
176 bool begin (float currentTemperature);
177
188 bool begin (int32_t currentPower, uint32_t meteringMultiplier = 0);
189
202 bool begin (float currentTemperature, int32_t currentPower, uint32_t meteringMultiplier = 0);
203
208 ZigbeePilotWireMode pilotWireMode() const {
209 return static_cast<ZigbeePilotWireMode> (_current_mode);
210 }
211
216 bool powerState() const {
217 return _current_state;
218 }
219
230 bool setPilotWireMode (ZigbeePilotWireMode mode);
231
238
244 bool setTemperature (float value);
245
250 float temperature() const {
251 return _temperature_value;
252 }
253
258 float temperatureMin() const;
259
264 float temperatureMax() const;
265
273 bool setTemperatureReporting (uint16_t min_interval, uint16_t max_interval, float delta);
274
282
289 bool setEnergyWh (uint64_t summation_wh);
290
295 uint64_t energyWh() const;
296
304
312 bool setEnergyWhReporting (uint16_t min_interval, uint16_t max_interval, float delta);
313
319 bool setPowerW (int32_t demand_w);
320
325 int32_t powerW() const;
326
334
342 bool setPowerWReporting (uint16_t min_interval, uint16_t max_interval, float delta);
343
357 bool setMeteringStatus (uint8_t status);
358
363 uint8_t meteringStatus() const {
364 return _metering_cfg.status;
365 }
366
374
381 void enableNvs (bool enable) {
382 _nvs_enabled = enable;
383 _prefs.putBool ("restore", enable);
384 }
385
390 bool isNvsEnabled() const {
391 return _nvs_enabled;
392 }
393
399 end();
400 }
401
406 void end() {
407 _prefs.end();
408 }
409
415 void printClusterInfo (Print &out = Serial);
416
417 protected:
418 void zbAttributeSet (const esp_zb_zcl_set_attr_value_message_t *message) override;
419 bool setReporting (uint16_t cluster_id, uint16_t attr_id,
420 uint16_t min_interval, uint16_t max_interval, float delta,
421 uint16_t manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC);
422 bool reportAttribute (uint16_t cluster_id, uint16_t attr_id, uint16_t manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC);
424 bool createTemperatureMeasurementCluster (float currentTemperature);
425 bool createMeteringCluster (int32_t currentPower, uint32_t meteringMultiplier);
426
427 private:
429
432 void (*_on_mode_change) (ZigbeePilotWireMode mode);
433
437 Preferences _prefs;
438
440 esp_zb_temperature_meas_cluster_cfg_t _temperature_cfg;
442
443 // Member variables for Simple Metering cluster (0x0702)
445 esp_zb_metering_cluster_cfg_t _metering_cfg;
446 esp_zb_uint48_t _summationDelivered;
447 esp_zb_uint24_t _multiplier;
448 esp_zb_uint24_t _divisor;
449 esp_zb_int24_t _instantaneousDemand;
450};
451
Class representing a Zigbee Pilot Wire Control endpoint. This class extends the ZigbeeEP class to imp...
float temperatureMax() const
Get the maximum temperature value.
bool setTemperature(float value)
Set the temperature value for the temperature measurement cluster.
bool setPowerW(int32_t demand_w)
Set the electric power attribute in the metering cluster.
ZigbeePilotWireControl(uint8_t endpoint, float tempMin, float tempMax, uint32_t meteringMultiplier)
Constructor for ZigbeePilotWireControl with temperature measurement and metering. This constructor en...
void printClusterInfo(Print &out=Serial)
Print the cluster information of the ZigbeePilotWireControl endpoint. This method outputs the cluster...
void(* _on_mode_change)(ZigbeePilotWireMode mode)
bool setPowerWReporting(uint16_t min_interval, uint16_t max_interval, float delta)
Set the reporting interval for the electric power attribute in the metering cluster.
bool reportEnergyWh()
Report the current summation delivered value to the Zigbee network. The reporting is configured via s...
bool powerState() const
Get the current power state.
void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override
void enableNvs(bool enable)
Enable or disable restore mode. When restore mode is enabled, the Pilot Wire mode is restored from NV...
bool begin()
Initialize the ZigbeePilotWireControl endpoint and create clusters. This method sets up the necessary...
uint64_t energyWh() const
Get the current summation delivered value.
ZigbeePilotWireControl(uint8_t endpoint)
Constructor for ZigbeePilotWireControl.
~ZigbeePilotWireControl()
Destructor for ZigbeePilotWireControl. Cleans up resources and ends NVS preferences.
bool reportAttribute(uint16_t cluster_id, uint16_t attr_id, uint16_t manuf_code=ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC)
bool reportPowerW()
Report the current electric power value to the Zigbee network. The reporting is configured via setPow...
bool begin(int32_t currentPower, uint32_t meteringMultiplier=0)
Initialize the ZigbeePilotWireControl endpoint with metering. This method sets up the necessary clust...
bool setPilotWireMode(ZigbeePilotWireMode mode)
Set the Pilot Wire mode. This method updates the Pilot Wire mode attribute and notifies the applicati...
bool setReporting(uint16_t cluster_id, uint16_t attr_id, uint16_t min_interval, uint16_t max_interval, float delta, uint16_t manuf_code=ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC)
ZigbeePilotWireMode pilotWireMode() const
Get the current Pilot Wire mode.
int32_t powerW() const
Get the current electric power value.
bool setTemperatureReporting(uint16_t min_interval, uint16_t max_interval, float delta)
Set the reporting interval for the temperature measurement cluster.
bool reportAttributes()
Report the current attributes to the Zigbee network. This method updates the Pilot Wire mode,...
uint8_t meteringStatus() const
Get the current metering status value.
bool reportTemperature()
Report the current temperature value to the Zigbee network. The reporting is configured via setTemper...
bool begin(float currentTemperature, int32_t currentPower, uint32_t meteringMultiplier=0)
Initialize the ZigbeePilotWireControl endpoint with temperature measurement and metering....
bool begin(float currentTemperature)
Initialize the ZigbeePilotWireControl endpoint with temperature measurement. This method sets up the ...
bool createTemperatureMeasurementCluster(float currentTemperature)
float temperature() const
Get the current temperature value.
bool reportPilotModeAndOnOff()
Report the current Pilot Wire mode and On/Off attributes to the Zigbee network. This method call the ...
esp_zb_temperature_meas_cluster_cfg_t _temperature_cfg
bool setEnergyWh(uint64_t summation_wh)
Set the summation delivered attribute in the metering cluster.
float temperatureMin() const
Get the minimum temperature value.
bool createMeteringCluster(int32_t currentPower, uint32_t meteringMultiplier)
ZigbeePilotWireControl(uint8_t endpoint, uint32_t meteringMultiplier)
Constructor for ZigbeePilotWireControl with metering. This constructor enables the metering cluster....
void onPilotWireModeChange(void(*callback)(ZigbeePilotWireMode mode))
Set a callback function to be called when the Pilot Wire mode changes. This function must be called t...
esp_zb_metering_cluster_cfg_t _metering_cfg
void end()
End the ZigbeePilotWireControl and clean up resources. This method should be called to properly relea...
bool isNvsEnabled() const
Check if restore mode is enabled.
bool setMeteringStatus(uint8_t status)
Set the metering status attribute in the metering cluster.
ZigbeePilotWireControl(uint8_t endpoint, float tempMin, float tempMax)
Constructor for ZigbeePilotWireControl with temperature measurement. This constructor enables the tem...
bool setEnergyWhReporting(uint16_t min_interval, uint16_t max_interval, float delta)
Set the reporting interval for the summation delivered attribute in the metering cluster.