Skip to content

Commit ef6dbcf

Browse files
committed
SiliconLabsGH-35: Consistency between UCL and ZWave precision
UCL precision is now always 2 whild Zwave is trying to adapt to the UCL precision.
1 parent f332df7 commit ef6dbcf

11 files changed

+836
-238
lines changed

applications/zpc/components/dotdot_mapper/rules/Thermostat.uam

+1-77
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@ def zwSENSOR_MULTILEVEL_SCALE 0x3104
66
def zwSENSOR_MULTILEVEL_SENSOR_VALUE 0x3105
77
def zwMULTILEVEL_SUPPORTED_SENSOR_TYPES 0x3106
88

9-
//Thermostat setpoint CC
10-
def zwTHERMOSTAT_SETPOINT_VERSION 0x4301
11-
def zwTHERMOSTAT_SUPPORTED_SETPOINT_TYPES 0x4302
12-
def zwTHERMOSTAT_SETPOINT_TYPE 0x4303
13-
def zwTHERMOSTAT_SETPOINT_VALUE 0x4304
14-
def zwTHERMOSTAT_SETPOINT_VALUE_SCALE 0x4305
15-
def zwTHERMOSTAT_SETPOINT_MIN_VALUE 0x4306
16-
def zwTHERMOSTAT_SETPOINT_MIN_VALUE_SCALE 0x4307
17-
def zwTHERMOSTAT_SETPOINT_MAX_VALUE 0x4308
18-
def zwTHERMOSTAT_SETPOINT_MAX_VALUE_SCALE 0x4309
19-
209
def zwTHERMOSTAT_MODE_VERSION 0x4001
2110
def zwTHERMOSTAT_MODE 0x4002
2211
def zwTHERMOSTAT_SUPPORTED_MODES 0x4003
@@ -54,75 +43,10 @@ def zb_ACLouverPosition 0x02010045
5443
def zb_ACCoilTemperature 0x02010046
5544
def zb_ACCapacityFormat 0x02010047
5645

57-
def thermostat_setpoint_supported (e'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE_SCALE | e'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE_SCALE)
58-
5946
scope 0 {
60-
// We map Setpoint setpoint_type 0x01 (HEATING) and 0x02 (COOLING)
61-
// The Z-Wave units are converted into milli units, in ZigBee is should be
62-
// deci-celsius.
63-
// A value scale of 1 means fahrenheit
64-
65-
// Heating
66-
r'zb_OccupiedHeatingSetpoint =
67-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 0 )
68-
(r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE / 10)
69-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 1 )
70-
(((r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE - 32000) * 5) / 90)
71-
undefined
72-
73-
d'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE =
74-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 0 )
75-
(d'zb_OccupiedHeatingSetpoint*10)
76-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 1 )
77-
(((d'zb_OccupiedHeatingSetpoint)*90) / 5 + 32000)
78-
undefined
79-
80-
r'zb_MinHeatSetpointLimit =
81-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MIN_VALUE_SCALE == 0)
82-
(r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MIN_VALUE / 10)
83-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MIN_VALUE_SCALE == 1)
84-
(((r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MIN_VALUE - 32000) * 5) / 90)
85-
undefined
86-
87-
r'zb_MaxHeatSetpointLimit =
88-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MAX_VALUE_SCALE == 0)
89-
(r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MAX_VALUE / 10)
90-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MAX_VALUE_SCALE == 1)
91-
(((r'zwTHERMOSTAT_SETPOINT_TYPE[1].zwTHERMOSTAT_SETPOINT_MAX_VALUE - 32000) * 5) / 90)
92-
undefined
93-
94-
// Cooling
95-
r'zb_OccupiedCoolingSetpoint =
96-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 0)
97-
(r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE / 10 )
98-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 1)
99-
(((r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE - 32000) * 5) / 90)
100-
undefined
101-
102-
r'zb_MinCoolSetpointLimit =
103-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MIN_VALUE_SCALE == 0)
104-
(r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MIN_VALUE / 10)
105-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MIN_VALUE_SCALE == 1)
106-
(((r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MIN_VALUE - 32000) * 5) / 90)
107-
undefined
108-
109-
r'zb_MaxCoolSetpointLimit =
110-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MAX_VALUE_SCALE == 0)
111-
(r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MAX_VALUE / 10)
112-
if(r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MAX_VALUE_SCALE == 1)
113-
(((r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_MAX_VALUE - 32000) * 5) / 90)
114-
undefined
115-
116-
d'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE =
117-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 0)
118-
(d'zb_OccupiedCoolingSetpoint*10)
119-
if( r'zwTHERMOSTAT_SETPOINT_TYPE[2].zwTHERMOSTAT_SETPOINT_VALUE_SCALE == 1 )
120-
(((d'zb_OccupiedCoolingSetpoint)*90) / 5 + 32000)
121-
undefined
122-
12347
// Local Temperature
12448
r'zb_LocalTemperature =
125-
if(thermostat_setpoint_supported == 0) undefined
49+
// if(thermostat_setpoint_supported == 0) undefined
12650
if(r'zwSENSOR_MULTILEVEL_SENSOR_TYPE[1].zwSENSOR_MULTILEVEL_SCALE == 0)
12751
(r'zwSENSOR_MULTILEVEL_SENSOR_TYPE[1].zwSENSOR_MULTILEVEL_SENSOR_VALUE / 10)
12852
if(r'zwSENSOR_MULTILEVEL_SENSOR_TYPE[1].zwSENSOR_MULTILEVEL_SCALE == 1)

applications/zpc/components/zpc_attribute_store/include/attribute_store_defined_attribute_types.h

+17-6
Original file line numberDiff line numberDiff line change
@@ -673,27 +673,38 @@ DEFINE_ATTRIBUTE(
673673
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPE,
674674
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x03))
675675

676+
// WARNING : applications/zpc/components/zwave_command_classes/src/zwave_command_class_thermostat_setpoint.cpp
677+
// use the attributes ID to determine value scale and precision. (+1 for scale and +2 for precision)
678+
// Be careful if you change the ID
679+
676680
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE,
677681
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x04))
678682

679683
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE_SCALE,
680684
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x05))
681685

682-
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE,
686+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE_PRECISION,
683687
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x06))
684688

685-
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE_SCALE,
689+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE,
686690
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x07))
687691

688-
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE,
692+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE_SCALE,
689693
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x08))
690694

691-
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE_SCALE,
695+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE_PRECISION,
692696
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x09))
693-
694-
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_VALUE_PRECISION,
697+
698+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE,
695699
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x0A))
696700

701+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE_SCALE,
702+
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x0B))
703+
704+
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE_PRECISION,
705+
((COMMAND_CLASS_THERMOSTAT_SETPOINT << 8) | 0x0C))
706+
707+
697708
/////////////////////////////////////////////////
698709
// Wakeup command class
699710
DEFINE_ATTRIBUTE(ATTRIBUTE_COMMAND_CLASS_WAKE_UP_VERSION,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/******************************************************************************
2+
* # License
3+
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
4+
******************************************************************************
5+
* The licensor of this software is Silicon Laboratories Inc. Your use of this
6+
* software is governed by the terms of Silicon Labs Master Software License
7+
* Agreement (MSLA) available at
8+
* www.silabs.com/about-us/legal/master-software-license-agreement. This
9+
* software is distributed to you in Source Code format and is governed by the
10+
* sections of the MSLA applicable to Source Code.
11+
*
12+
*****************************************************************************/
13+
14+
/**
15+
* @defgroup zpc_attribute_store_command_classes_types Type definitions for attribute storage of Command Classes
16+
* @ingroup zpc_attribute_store
17+
* @brief Type definitions for Command Classes, used for @ref attribute_store storage.
18+
*
19+
*/
20+
21+
/**
22+
* @defgroup zwave_command_class_thermostat_setpoint_types Type definitions for attribute storage of the Thermostat SetPoint Command Class
23+
* @ingroup zpc_attribute_store_command_classes_types
24+
* @brief Type definitions for the Thermostat SetPoint Command Class.
25+
*
26+
* @{
27+
*/
28+
29+
#ifndef ZWAVE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPES_H
30+
#define ZWAVE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPES_H
31+
32+
// Should be uint8_t, but kept int8_t for legacy reasons
33+
typedef int8_t thermostat_setpoint_type_t;
34+
typedef int32_t thermostat_setpoint_value_t;
35+
// Should be uint8_t, but kept uint32_t for legacy reasons
36+
typedef uint32_t thermostat_setpoint_scale_t;
37+
typedef uint8_t thermostat_setpoint_precision_t;
38+
39+
40+
#endif //ZWAVE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPES_H
41+
/** @} end zwave_command_class_thermostat_setpoint_types */

applications/zpc/components/zpc_attribute_store/src/zpc_attribute_store_type_registration.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,12 @@ static const std::vector<attribute_schema_t> attribute_schema = {
302302

303303
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE, "Min Value", ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPE, I32_STORAGE_TYPE},
304304
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE_SCALE, "Min Value Scale", ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPE, U32_STORAGE_TYPE},
305+
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MIN_VALUE_PRECISION, "Min Value Precision", ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPE, U8_STORAGE_TYPE},
306+
305307
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE, "Max Value", ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPE, I32_STORAGE_TYPE},
306308
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE_SCALE, "Max Value Scale", ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPE, U32_STORAGE_TYPE},
309+
{ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_MAX_VALUE_PRECISION, "Max Value Precision", ATTRIBUTE_COMMAND_CLASS_THERMOSTAT_SETPOINT_TYPE, U8_STORAGE_TYPE},
310+
307311
/////////////////////////////////////////////////////////////////////
308312
// Supervision Command Class attributes
309313
/////////////////////////////////////////////////////////////////////

applications/zpc/components/zwave_command_classes/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ add_library(
4545
src/zwave_command_class_switch_color.c
4646
src/zwave_command_class_switch_multilevel.c
4747
src/zwave_command_class_thermostat_mode.c
48-
src/zwave_command_class_thermostat_setpoint.c
48+
src/zwave_command_class_thermostat_setpoint.cpp
4949
src/zwave_command_class_time.c
5050
src/zwave_command_class_user_code.c
5151
src/zwave_command_class_version.c

applications/zpc/components/zwave_command_classes/include/zwave_command_classes_utils.h

+29-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ typedef struct zwave_minimum_frame {
5656
} zwave_minimum_frame_t;
5757

5858
// Helper macros
59-
#define FAHRENHEIT_TO_DEGREES(value) ((value - 32.0F) * 5 / 9);
60-
#define DEGREES_TO_FAHRENHEIT(value) (value * 9 / 5.0F) + 32;
59+
#define FAHRENHEIT_TO_DEGREES(value) ((value - 32.0) * 5 / 9);
60+
#define DEGREES_TO_FAHRENHEIT(value) (value * 9 / 5.0) + 32;
6161

6262
// Constants
6363
/// Additional delay in ms to wait before issuing a Get Command
@@ -214,7 +214,33 @@ int32_t get_signed_value_from_frame_and_size(const uint8_t *frame,
214214
*/
215215
uint32_t get_unsigned_value_from_frame_and_size(const uint8_t *frame,
216216
uint8_t size);
217+
217218
/**
219+
* @brief Convert a value from the Z-Wave world (precision = [0..7] and C° + F) into a UCL (Zigbee) world (precision = 2 and C°)
220+
*
221+
* @param zwave_value Current Z-Wave value
222+
* @param zwave_precision Reported Z-Wave precision
223+
* @param zwave_scale Reported Z-Wave scale (0 : C°, 1 : F)
224+
*
225+
* @return int16_t UCL temperature. Rounded down if Z-Wave precision is too high.
226+
*/
227+
int16_t zwave_temperature_to_ucl_temperature(int32_t zwave_value,
228+
uint8_t zwave_precision,
229+
uint8_t zwave_scale);
230+
231+
/**
232+
* @brief Convert a value from the UCL world (Zigbee) (precision = 2 and C°) to the ZWave world (precision = [0..7] and C° + F)
233+
*
234+
* @param ucl_value Current UCL value
235+
* @param zwave_precision Expected Z-Wave precision
236+
* @param zwave_scale Expected Z-Wave scale (0 : C°, 1 : F)
237+
*
238+
* @return int32_t Z-Wave temperature with given precision and scale.
239+
*/
240+
int32_t ucl_temperature_to_zwave_temperature(int16_t ucl_value,
241+
uint8_t zwave_precision,
242+
uint8_t zwave_scale);
243+
/**
218244
* @brief Converts a clock_time_t duration to a Z-Wave Command Class duration
219245
* byte
220246
*
@@ -224,7 +250,7 @@ uint32_t get_unsigned_value_from_frame_and_size(const uint8_t *frame,
224250
* @param time The system time duration
225251
* @returns uint8_t The corresponding Z-Wave duration encoding.
226252
*/
227-
uint8_t time_to_zwave_duration(clock_time_t time);
253+
uint8_t time_to_zwave_duration(clock_time_t time);
228254

229255
/**
230256
* @brief Converts a duration byte encoded for a Z-Wave command class and returns

0 commit comments

Comments
 (0)