Skip to content

Commit

Permalink
fixed wall thermostat temp and setpoint
Browse files Browse the repository at this point in the history
ivesdebruycker/node-red-contrib-maxcube#15

used info in https://github.com/Bouni/max-cube-protocol/blob/master/L-Message.md#actual-temperature-wallmountedthermostat to decode correctly the wall thermostat "Actual temperature" (temp) and "Temperature" (setpoint)
  • Loading branch information
maxill1 committed Oct 16, 2017
1 parent 09ffe96 commit 51b8003
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions maxcube-commandparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function decodeDevice (payload) {
switch (payload[0]) {
case 8: deviceType = EQ3MAX_DEV_TYPE_PUSH_BUTTON; break;
case 11: deviceType = EQ3MAX_DEV_TYPE_THERMOSTAT; deviceStatus = decodeDeviceThermostat (payload); break;
case 12: deviceType = EQ3MAX_DEV_TYPE_WALLTHERMOSTAT; deviceStatus = decodeDeviceThermostat (payload); break;
case 12: deviceType = EQ3MAX_DEV_TYPE_WALLTHERMOSTAT; deviceStatus = decodeDeviceWallThermostat (payload); break;
default: deviceType = EQ3MAX_DEV_TYPE_UNKNOWN; break;
}

Expand Down Expand Up @@ -288,4 +288,44 @@ function decodeDeviceThermostat (payload) {
return deviceStatus;
}

exports.parse = parse;
function decodeDeviceWallThermostat (payload) {

//regular device parsing
var deviceStatus = decodeDeviceThermostat (payload);

//wall thermostat has different temp and setpoint parsing:
//https://github.com/Bouni/max-cube-protocol/blob/master/L-Message.md#actual-temperature-wallmountedthermostat

/*
Actual Temperature (WallMountedThermostat)
11 Actual Temperature 1 219
Room temperature measured by the wall mounted thermostat in °C * 10. For example 0xDB = 219 = 21.9°C The temperature is represented by 9 bits; the 9th bit is available as the top bit at offset 8
offset| 8 | ... | 12 |
hex | B2 | | 24 |
binary| 1011 0010 | ... | 0010 0100 |
| || |||| |||| ||||
| ++-++++--------------------- temperature (°C*2): 110010 = 25.0°C
| |||| ||||
+-----------------++++-++++--- actual temperature (°C*10): 100100100 = 29.2°C
*/

//offset 8 binary to extract only needed bit
var off8Bin= (payload[8] >>> 0).toString(2);

//offset8 without top bit (it is used by actual temperature and will corrupt the setpoint value)
var setPoint = parseInt(((off8Bin + '').substring(1)).replace(/[^01]/gi, ''), 2);
//C/2
deviceStatus.setpoint = setPoint / 2;

//get the TopBit and zero fill right to use it as 9 bit of offset 12
var off8TopBit = parseInt(off8Bin.substring(0,1)) << 8;
//Bitwise OR offset 8/offset 12 and finally C/10 to read the actual temperature
deviceStatus.temp = (parseInt(off8TopBit) | parseInt(payload[12])) / 10;

return deviceStatus;
}

exports.parse = parse;

0 comments on commit 51b8003

Please sign in to comment.