Merge pull request #9407 from s-hadinger/zigbee_sea_pressure_dev

Zigbee add SeaPressure
This commit is contained in:
s-hadinger 2020-09-27 17:02:40 +02:00 committed by GitHub
commit d0b2b9f70a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 158 additions and 127 deletions

View File

@ -328,6 +328,7 @@ const char Z_strings[] PROGMEM =
"PressureMaxScaledValue" "\x00" "PressureMaxScaledValue" "\x00"
"PressureScaledTolerance" "\x00" "PressureScaledTolerance" "\x00"
"PressureScale" "\x00" "PressureScale" "\x00"
"SeaPressure" "\x00"
"FlowRate" "\x00" "FlowRate" "\x00"
"FlowMinMeasuredValue" "\x00" "FlowMinMeasuredValue" "\x00"
"FlowMaxMeasuredValue" "\x00" "FlowMaxMeasuredValue" "\x00"
@ -707,128 +708,129 @@ enum Z_offsets {
Zo_PressureMaxScaledValue = 4338, Zo_PressureMaxScaledValue = 4338,
Zo_PressureScaledTolerance = 4361, Zo_PressureScaledTolerance = 4361,
Zo_PressureScale = 4385, Zo_PressureScale = 4385,
Zo_FlowRate = 4399, Zo_SeaPressure = 4399,
Zo_FlowMinMeasuredValue = 4408, Zo_FlowRate = 4411,
Zo_FlowMaxMeasuredValue = 4429, Zo_FlowMinMeasuredValue = 4420,
Zo_FlowTolerance = 4450, Zo_FlowMaxMeasuredValue = 4441,
Zo_Humidity = 4464, Zo_FlowTolerance = 4462,
Zo_HumidityMinMeasuredValue = 4473, Zo_Humidity = 4476,
Zo_HumidityMaxMeasuredValue = 4498, Zo_HumidityMinMeasuredValue = 4485,
Zo_HumidityTolerance = 4523, Zo_HumidityMaxMeasuredValue = 4510,
Zo_Occupancy = 4541, Zo_HumidityTolerance = 4535,
Zo_OccupancySensorType = 4551, Zo_Occupancy = 4553,
Zo_ZoneState = 4571, Zo_OccupancySensorType = 4563,
Zo_ZoneType = 4581, Zo_ZoneState = 4583,
Zo_ZoneStatus = 4590, Zo_ZoneType = 4593,
Zo_CurrentSummDelivered = 4601, Zo_ZoneStatus = 4602,
Zo_CompanyName = 4622, Zo_CurrentSummDelivered = 4613,
Zo_MeterTypeID = 4634, Zo_CompanyName = 4634,
Zo_DataQualityID = 4646, Zo_MeterTypeID = 4646,
Zo_CustomerName = 4660, Zo_DataQualityID = 4658,
Zo_Model = 4673, Zo_CustomerName = 4672,
Zo_PartNumber = 4679, Zo_Model = 4685,
Zo_ProductRevision = 4690, Zo_PartNumber = 4691,
Zo_SoftwareRevision = 4706, Zo_ProductRevision = 4702,
Zo_UtilityName = 4723, Zo_SoftwareRevision = 4718,
Zo_POD = 4735, Zo_UtilityName = 4735,
Zo_AvailablePower = 4739, Zo_POD = 4747,
Zo_PowerThreshold = 4754, Zo_AvailablePower = 4751,
Zo_RMSVoltage = 4769, Zo_PowerThreshold = 4766,
Zo_RMSCurrent = 4780, Zo_RMSVoltage = 4781,
Zo_ActivePower = 4791, Zo_RMSCurrent = 4792,
Zo_NumberOfResets = 4803, Zo_ActivePower = 4803,
Zo_PersistentMemoryWrites = 4818, Zo_NumberOfResets = 4815,
Zo_LastMessageLQI = 4841, Zo_PersistentMemoryWrites = 4830,
Zo_LastMessageRSSI = 4856, Zo_LastMessageLQI = 4853,
Zo_Identify = 4872, Zo_LastMessageRSSI = 4868,
Zo_xxxx = 4881, Zo_Identify = 4884,
Zo_IdentifyQuery = 4886, Zo_xxxx = 4893,
Zo_AddGroup = 4900, Zo_IdentifyQuery = 4898,
Zo_xxxx00 = 4909, Zo_AddGroup = 4912,
Zo_ViewGroup = 4916, Zo_xxxx00 = 4921,
Zo_GetGroup = 4926, Zo_ViewGroup = 4928,
Zo_01xxxx = 4935, Zo_GetGroup = 4938,
Zo_GetAllGroups = 4942, Zo_01xxxx = 4947,
Zo_00 = 4955, Zo_GetAllGroups = 4954,
Zo_RemoveGroup = 4958, Zo_00 = 4967,
Zo_RemoveAllGroups = 4970, Zo_RemoveGroup = 4970,
Zo_ViewScene = 4986, Zo_RemoveAllGroups = 4982,
Zo_xxxxyy = 4996, Zo_ViewScene = 4998,
Zo_RemoveScene = 5003, Zo_xxxxyy = 5008,
Zo_RemoveAllScenes = 5015, Zo_RemoveScene = 5015,
Zo_RecallScene = 5031, Zo_RemoveAllScenes = 5027,
Zo_GetSceneMembership = 5043, Zo_RecallScene = 5043,
Zo_PowerOffEffect = 5062, Zo_GetSceneMembership = 5055,
Zo_xxyy = 5077, Zo_PowerOffEffect = 5074,
Zo_PowerOnRecall = 5082, Zo_xxyy = 5089,
Zo_PowerOnTimer = 5096, Zo_PowerOnRecall = 5094,
Zo_xxyyyyzzzz = 5109, Zo_PowerOnTimer = 5108,
Zo_xx0A00 = 5120, Zo_xxyyyyzzzz = 5121,
Zo_DimmerUp = 5127, Zo_xx0A00 = 5132,
Zo_00190200 = 5136, Zo_DimmerUp = 5139,
Zo_DimmerDown = 5145, Zo_00190200 = 5148,
Zo_01190200 = 5156, Zo_DimmerDown = 5157,
Zo_DimmerStop = 5165, Zo_01190200 = 5168,
Zo_ResetAlarm = 5176, Zo_DimmerStop = 5177,
Zo_xxyyyy = 5187, Zo_ResetAlarm = 5188,
Zo_ResetAllAlarms = 5194, Zo_xxyyyy = 5199,
Zo_xx000A00 = 5209, Zo_ResetAllAlarms = 5206,
Zo_HueSat = 5218, Zo_xx000A00 = 5221,
Zo_xxyy0A00 = 5225, Zo_HueSat = 5230,
Zo_Color = 5234, Zo_xxyy0A00 = 5237,
Zo_xxxxyyyy0A00 = 5240, Zo_Color = 5246,
Zo_xxxx0A00 = 5253, Zo_xxxxyyyy0A00 = 5252,
Zo_ShutterOpen = 5262, Zo_xxxx0A00 = 5265,
Zo_ShutterClose = 5274, Zo_ShutterOpen = 5274,
Zo_ShutterStop = 5287, Zo_ShutterClose = 5286,
Zo_ShutterLift = 5299, Zo_ShutterStop = 5299,
Zo_xx = 5311, Zo_ShutterLift = 5311,
Zo_ShutterTilt = 5314, Zo_xx = 5323,
Zo_Shutter = 5326, Zo_ShutterTilt = 5326,
Zo_DimmerMove = 5334, Zo_Shutter = 5338,
Zo_xx0A = 5345, Zo_DimmerMove = 5346,
Zo_DimmerStepUp = 5350, Zo_xx0A = 5357,
Zo_00xx0A00 = 5363, Zo_DimmerStepUp = 5362,
Zo_DimmerStepDown = 5372, Zo_00xx0A00 = 5375,
Zo_01xx0A00 = 5387, Zo_DimmerStepDown = 5384,
Zo_DimmerStep = 5396, Zo_01xx0A00 = 5399,
Zo_xx190A00 = 5407, Zo_DimmerStep = 5408,
Zo_01 = 5416, Zo_xx190A00 = 5419,
Zo_HueMove = 5419, Zo_01 = 5428,
Zo_xx19 = 5427, Zo_HueMove = 5431,
Zo_HueStepUp = 5432, Zo_xx19 = 5439,
Zo_HueStepDown = 5442, Zo_HueStepUp = 5444,
Zo_03xx0A00 = 5454, Zo_HueStepDown = 5454,
Zo_HueStep = 5463, Zo_03xx0A00 = 5466,
Zo_SatMove = 5471, Zo_HueStep = 5475,
Zo_SatStep = 5479, Zo_SatMove = 5483,
Zo_xx190A = 5487, Zo_SatStep = 5491,
Zo_ColorMove = 5494, Zo_xx190A = 5499,
Zo_xxxxyyyy = 5504, Zo_ColorMove = 5506,
Zo_ColorStep = 5513, Zo_xxxxyyyy = 5516,
Zo_ColorTempMoveUp = 5523, Zo_ColorStep = 5525,
Zo_01xxxx000000000000 = 5539, Zo_ColorTempMoveUp = 5535,
Zo_ColorTempMoveDown = 5558, Zo_01xxxx000000000000 = 5551,
Zo_03xxxx000000000000 = 5576, Zo_ColorTempMoveDown = 5570,
Zo_ColorTempMoveStop = 5595, Zo_03xxxx000000000000 = 5588,
Zo_00xxxx000000000000 = 5613, Zo_ColorTempMoveStop = 5607,
Zo_ColorTempMove = 5632, Zo_00xxxx000000000000 = 5625,
Zo_xxyyyy000000000000 = 5646, Zo_ColorTempMove = 5644,
Zo_ColorTempStepUp = 5665, Zo_xxyyyy000000000000 = 5658,
Zo_01xxxx0A0000000000 = 5681, Zo_ColorTempStepUp = 5677,
Zo_ColorTempStepDown = 5700, Zo_01xxxx0A0000000000 = 5693,
Zo_03xxxx0A0000000000 = 5718, Zo_ColorTempStepDown = 5712,
Zo_ColorTempStep = 5737, Zo_03xxxx0A0000000000 = 5730,
Zo_xxyyyy0A0000000000 = 5751, Zo_ColorTempStep = 5749,
Zo_ArrowClick = 5770, Zo_xxyyyy0A0000000000 = 5763,
Zo_ArrowHold = 5781, Zo_ArrowClick = 5782,
Zo_ArrowRelease = 5791, Zo_ArrowHold = 5793,
Zo_ZoneStatusChange = 5804, Zo_ArrowRelease = 5803,
Zo_xxxxyyzz = 5821, Zo_ZoneStatusChange = 5816,
Zo_xxyyzzzz = 5830, Zo_xxxxyyzz = 5833,
Zo_AddScene = 5839, Zo_xxyyzzzz = 5842,
Zo_xxyyyyzz = 5848, Zo_AddScene = 5851,
Zo_StoreScene = 5857, Zo_xxyyyyzz = 5860,
Zo_StoreScene = 5869,
}; };

View File

@ -489,6 +489,7 @@ const Z_AttributeConverter Z_PostProcess[] PROGMEM = {
{ Zint16, Cx0403, 0x0012, Z_(PressureMaxScaledValue), 1 }, // { Zint16, Cx0403, 0x0012, Z_(PressureMaxScaledValue), 1 }, //
{ Zuint16, Cx0403, 0x0013, Z_(PressureScaledTolerance), 1 }, // { Zuint16, Cx0403, 0x0013, Z_(PressureScaledTolerance), 1 }, //
{ Zint8, Cx0403, 0x0014, Z_(PressureScale), 1 }, // { Zint8, Cx0403, 0x0014, Z_(PressureScale), 1 }, //
{ Zint16, Cx0403, 0xFF00, Z_(SeaPressure), 1 }, // Pressure at Sea Level, Tasmota specific
{ Zunk, Cx0403, 0xFFFF, Z_(), 0 }, // Remove all other Pressure values { Zunk, Cx0403, 0xFFFF, Z_(), 0 }, // Remove all other Pressure values
// Flow Measurement cluster // Flow Measurement cluster
@ -665,6 +666,7 @@ public:
void parseReportAttributes(Z_attribute_list& attr_list); void parseReportAttributes(Z_attribute_list& attr_list);
void generateSyntheticAttributes(Z_attribute_list& attr_list); void generateSyntheticAttributes(Z_attribute_list& attr_list);
void computeSyntheticAttributes(Z_attribute_list& attr_list);
void generateCallBacks(Z_attribute_list& attr_list); void generateCallBacks(Z_attribute_list& attr_list);
void parseReadAttributes(Z_attribute_list& attr_list); void parseReadAttributes(Z_attribute_list& attr_list);
void parseReadAttributesResponse(Z_attribute_list& attr_list); void parseReadAttributesResponse(Z_attribute_list& attr_list);
@ -1096,6 +1098,9 @@ void ZCLFrame::parseReportAttributes(Z_attribute_list& attr_list) {
} }
} }
//
// Extract attributes hidden in other compound attributes
//
void ZCLFrame::generateSyntheticAttributes(Z_attribute_list& attr_list) { void ZCLFrame::generateSyntheticAttributes(Z_attribute_list& attr_list) {
// scan through attributes and apply specific converters // scan through attributes and apply specific converters
for (auto &attr : attr_list) { for (auto &attr : attr_list) {
@ -1103,11 +1108,6 @@ void ZCLFrame::generateSyntheticAttributes(Z_attribute_list& attr_list) {
uint32_t ccccaaaa = (attr.key.id.cluster << 16) | attr.key.id.attr_id; uint32_t ccccaaaa = (attr.key.id.cluster << 16) | attr.key.id.attr_id;
switch (ccccaaaa) { // 0xccccaaaa . c=cluster, a=attribute switch (ccccaaaa) { // 0xccccaaaa . c=cluster, a=attribute
case 0x00010020: // BatteryVoltage
if (attr_list.countAttribute(0x0001,0x0021) == 0) { // if it does not already contain BatteryPercentage
uint32_t mv = attr.getUInt()*100;
attr_list.addAttribute(0x0001, 0x0021).setUInt(toPercentageCR2032(mv) * 2);
}
case 0x0000FF01: case 0x0000FF01:
syntheticAqaraSensor(attr_list, attr); syntheticAqaraSensor(attr_list, attr);
break; break;
@ -1125,6 +1125,33 @@ void ZCLFrame::generateSyntheticAttributes(Z_attribute_list& attr_list) {
} }
} }
//
// Compute new attributes based on the standard set
// Note: both function are now split to compute on extracted attributes
//
void ZCLFrame::computeSyntheticAttributes(Z_attribute_list& attr_list) {
// scan through attributes and apply specific converters
for (auto &attr : attr_list) {
if (attr.key_is_str) { continue; } // pass if key is a name
uint32_t ccccaaaa = (attr.key.id.cluster << 16) | attr.key.id.attr_id;
switch (ccccaaaa) { // 0xccccaaaa . c=cluster, a=attribute
case 0x00010020: // BatteryVoltage
if (attr_list.countAttribute(0x0001,0x0021) == 0) { // if it does not already contain BatteryPercentage
uint32_t mv = attr.getUInt()*100;
attr_list.addAttribute(0x0001, 0x0021).setUInt(toPercentageCR2032(mv) * 2);
}
break;
case 0x04030000: // Pressure
int16_t pressure = attr.getInt();
int16_t pressure_sealevel = (pressure / FastPrecisePow(1.0 - ((float)Settings.altitude / 44330.0f), 5.255f)) - 21.6f;
attr_list.addAttribute(0x0403, 0xFF00).setInt(pressure_sealevel);
// We create a synthetic attribute 0403/FF00 to indicate sea level
break;
}
}
}
// Set deferred callbacks for Occupancy // Set deferred callbacks for Occupancy
// TODO make delay a parameter // TODO make delay a parameter
void ZCLFrame::generateCallBacks(Z_attribute_list& attr_list) { void ZCLFrame::generateCallBacks(Z_attribute_list& attr_list) {
@ -1672,6 +1699,7 @@ void ZCLFrame::postProcessAttributes(uint16_t shortaddr, Z_attribute_list& attr_
case 0x03000007: device.ct = uval16; break; case 0x03000007: device.ct = uval16; break;
case 0x03000008: device.colormode = uval16; break; case 0x03000008: device.colormode = uval16; break;
case 0x04020000: device.temperature = fval * 10 + 0.5f; break; case 0x04020000: device.temperature = fval * 10 + 0.5f; break;
case 0x0403FF00: device.pressure = fval + 0.5f; break; // give priority to sea level
case 0x04030000: device.pressure = fval + 0.5f; break; case 0x04030000: device.pressure = fval + 0.5f; break;
case 0x04050000: device.humidity = fval + 0.5f; break; case 0x04050000: device.humidity = fval + 0.5f; break;
case 0x0B040505: device.mains_voltage = uval16; break; case 0x0B040505: device.mains_voltage = uval16; break;

View File

@ -1396,6 +1396,7 @@ void Z_IncomingMessage(class ZCLFrame &zcl_received) {
} }
zcl_received.generateSyntheticAttributes(attr_list); zcl_received.generateSyntheticAttributes(attr_list);
zcl_received.computeSyntheticAttributes(attr_list);
zcl_received.generateCallBacks(attr_list); // set deferred callbacks, ex: Occupancy zcl_received.generateCallBacks(attr_list); // set deferred callbacks, ex: Occupancy
zcl_received.postProcessAttributes(srcaddr, attr_list); zcl_received.postProcessAttributes(srcaddr, attr_list);