Advertisement
yurghie

Untitled

Apr 30th, 2023
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.49 KB | None | 0 0
  1. const herdsman = require('zigbee-herdsman');
  2. const exposes = require('zigbee-herdsman-converters/lib/exposes');
  3. const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
  4. const tz = require('zigbee-herdsman-converters/converters/toZigbee');
  5. const constants = require('zigbee-herdsman-converters/lib/constants');
  6. const reporting = require('zigbee-herdsman-converters/lib/reporting');
  7. const globalStore = require('zigbee-herdsman-converters/lib/store');
  8. const ota = require('zigbee-herdsman-converters/lib/ota');
  9. const utils = require('zigbee-herdsman-converters/lib/utils');
  10. const extend = require('zigbee-herdsman-converters/lib/extend');
  11. const ea = exposes.access;
  12. const e = exposes.presets;
  13.  
  14.  
  15. // const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
  16. // const tz = require('zigbee-herdsman-converters/converters/toZigbee');
  17. // const exposes = require('zigbee-herdsman-converters/lib/exposes');
  18. // const reporting = require('zigbee-herdsman-converters/lib/reporting');
  19. // const extend = require('zigbee-herdsman-converters/lib/extend');
  20. // const ota = require('zigbee-herdsman-converters/lib/ota');
  21. // const e = exposes.presets;
  22. // const ea = exposes.access;
  23.  
  24.  
  25. const sunricherManufacturer = {manufacturerCode: herdsman.Zcl.ManufacturerCode.SHENZHEN_SUNRICH};
  26.  
  27. const definition = {
  28. zigbeeModel: ['4512737', '4512738'],
  29. model: '4512737/4512738',
  30. vendor: 'Namron',
  31. description: 'Touch termostat usr',
  32. fromZigbee: [fz.thermostat, fz.namron_thermostat, fz.metering, fz.electrical_measurement,
  33. fz.namron_hvac_user_interface],
  34. toZigbee: [tz.thermostat_occupied_heating_setpoint, tz.thermostat_unoccupied_heating_setpoint, tz.thermostat_occupancy,
  35. tz.thermostat_local_temperature_calibration, tz.thermostat_local_temperature, tz.thermostat_outdoor_temperature,
  36. tz.thermostat_system_mode, tz.thermostat_control_sequence_of_operation, tz.thermostat_running_state,
  37. tz.namron_thermostat_child_lock, tz.namron_thermostat],
  38. exposes: [
  39. e.local_temperature(),
  40. exposes.numeric('outdoor_temperature', ea.STATE_GET).withUnit('°C')
  41. .withDescription('Current temperature measured from the floor sensor'),
  42. exposes.climate()
  43. .withSetpoint('occupied_heating_setpoint', 0, 40, 0.5)
  44. .withLocalTemperature()
  45. .withLocalTemperatureCalibration(-3, 3, 0.1)
  46. .withSystemMode(['off', 'auto', 'dry', 'heat'])
  47. .withRunningState(['idle', 'heat']),
  48. exposes.binary('away_mode', ea.ALL, 'ON', 'OFF')
  49. .withDescription('Enable/disable away mode'),
  50. exposes.binary('child_lock', ea.ALL, 'LOCK', 'UNLOCK')
  51. .withDescription('Enables/disables physical input on the device'),
  52. e.power(), e.current(), e.voltage(), e.energy(),
  53. exposes.enum('lcd_brightness', ea.ALL, ['low', 'mid', 'high'])
  54. .withDescription('OLED brightness when operating the buttons. Default: Medium.'),
  55. exposes.enum('button_vibration_level', ea.ALL, ['off', 'low', 'high'])
  56. .withDescription('Key beep volume and vibration level. Default: Low.'),
  57. exposes.enum('floor_sensor_type', ea.ALL, ['10k', '15k', '50k', '100k', '12k'])
  58. .withDescription('Type of the external floor sensor. Default: NTC 10K/25.'),
  59. exposes.enum('sensor', ea.ALL, ['air', 'floor', 'both'])
  60. .withDescription('The sensor used for heat control. Default: Room Sensor.'),
  61. exposes.enum('powerup_status', ea.ALL, ['default', 'last_status'])
  62. .withDescription('The mode after a power reset. Default: Previous Mode.'),
  63. exposes.numeric('floor_sensor_calibration', ea.ALL)
  64. .withUnit('°C')
  65. .withValueMin(-3).withValueMax(3).withValueStep(0.1)
  66. .withDescription('The tempearatue calibration for the exernal floor sensor, between -3 and 3 in 0.1°C. Default: 0.'),
  67. exposes.numeric('dry_time', ea.ALL)
  68. .withUnit('min')
  69. .withValueMin(5).withValueMax(100)
  70. .withDescription('The duration of Dry Mode, between 5 and 100 minutes. Default: 5.'),
  71. exposes.enum('mode_after_dry', ea.ALL, ['off', 'manual', 'auto', 'away'])
  72. .withDescription('The mode after Dry Mode. Default: Auto.'),
  73. exposes.enum('temperature_display', ea.ALL, ['room', 'floor'])
  74. .withDescription('The temperature on the display. Default: Room Temperature.'),
  75. exposes.numeric('window_open_check', ea.ALL)
  76. .withUnit('°C')
  77. .withValueMin(0).withValueMax(4).withValueStep(0.5)
  78. .withDescription('The threshold to detect window open, between 1.5 and 4 in 0.5 °C. Default: 0 (disabled).'),
  79. exposes.numeric('hysterersis', ea.ALL)
  80. .withUnit('°C')
  81. .withValueMin(0.5).withValueMax(2).withValueStep(0.1)
  82. .withDescription('Hysteresis setting, between 0.5 and 2 in 0.1 °C. Default: 0.5.'),
  83. exposes.enum('display_auto_off_enabled', ea.ALL, ['enabled', 'disabled']),
  84. exposes.numeric('alarm_airtemp_overvalue', ea.ALL)
  85. .withUnit('°C')
  86. .withValueMin(20).withValueMax(60)
  87. .withDescription('Room temperature alarm threshold, between 20 and 60 in °C. 0 means disabled. Default: 45.'),
  88. ],
  89. onEvent: async (type, data, device, options) => {
  90. const endpoint = device.getEndpoint(1);
  91. if (type === 'stop') {
  92. clearInterval(globalStore.getValue(device, 'time'));
  93. globalStore.clearValue(device, 'time');
  94. } else if (!globalStore.hasValue(device, 'time')) {
  95. const hours24 = 1000 * 60 * 60 * 24;
  96. const interval = setInterval(async () => {
  97. try {
  98. // Device does not asks for the time with binding, therefore we write the time every 24 hours
  99. const time = Math.round(((new Date()).getTime() - constants.OneJanuary2000) / 1000 + ((new Date())
  100. .getTimezoneOffset() * -1) * 60);
  101. const values = {time: time};
  102. endpoint.write('genTime', values);
  103. } catch (error) {/* Do nothing*/}
  104. }, hours24);
  105. globalStore.putValue(device, 'time', interval);
  106. }
  107. },
  108. configure: async (device, coordinatorEndpoint, logger) => {
  109. const endpoint = device.getEndpoint(1);
  110. const binds = [
  111. 'genBasic', 'genIdentify', 'hvacThermostat', 'seMetering', 'haElectricalMeasurement', 'genAlarms',
  112. 'msOccupancySensing', 'genTime', 'hvacUserInterfaceCfg',
  113. ];
  114. await reporting.bind(endpoint, coordinatorEndpoint, binds);
  115.  
  116. // standard ZCL attributes
  117. await reporting.thermostatTemperature(endpoint);
  118. await reporting.thermostatOccupiedHeatingSetpoint(endpoint);
  119. await reporting.thermostatUnoccupiedHeatingSetpoint(endpoint);
  120. await reporting.thermostatKeypadLockMode(endpoint);
  121.  
  122. // await endpoint.configureReporting('hvacThermostat', [{
  123. // attribute: 'occupancy',
  124. // minimumReportInterval: 0,
  125. // maximumReportInterval: constants.repInterval.HOUR,
  126. // reportableChange: null,
  127. // }]);
  128.  
  129. await endpoint.read('haElectricalMeasurement', ['acVoltageMultiplier', 'acVoltageDivisor', 'acCurrentMultiplier']);
  130. await endpoint.read('haElectricalMeasurement', ['acCurrentDivisor']);
  131.  
  132. await reporting.activePower(endpoint);
  133. await reporting.rmsCurrent(endpoint, {min: 10, change: 10});
  134. await reporting.rmsVoltage(endpoint, {min: 10});
  135. await reporting.readMeteringMultiplierDivisor(endpoint);
  136. await reporting.currentSummDelivered(endpoint);
  137.  
  138. // Custom attributes
  139. const options = {manufacturerCode: 0x1224};
  140.  
  141. // OperateDisplayLcdBrightnesss
  142. await endpoint.configureReporting('hvacThermostat', [{
  143. attribute: {ID: 0x1000, type: 0x30},
  144. minimumReportInterval: 0,
  145. maximumReportInterval: constants.repInterval.HOUR,
  146. reportableChange: null}],
  147. options);
  148. // ButtonVibrationLevel
  149. await endpoint.configureReporting('hvacThermostat', [{
  150. attribute: {ID: 0x1001, type: 0x30},
  151. minimumReportInterval: 0,
  152. maximumReportInterval: constants.repInterval.HOUR,
  153. reportableChange: null}],
  154. options);
  155. // FloorSensorType
  156. await endpoint.configureReporting('hvacThermostat', [{
  157. attribute: {ID: 0x1002, type: 0x30},
  158. minimumReportInterval: 0,
  159. maximumReportInterval: constants.repInterval.HOUR,
  160. reportableChange: null}],
  161. options);
  162. // ControlType
  163. await endpoint.configureReporting('hvacThermostat', [{
  164. attribute: {ID: 0x1003, type: 0x30},
  165. minimumReportInterval: 0,
  166. maximumReportInterval: constants.repInterval.HOUR,
  167. reportableChange: null}],
  168. options);
  169. // PowerUpStatus
  170. await endpoint.configureReporting('hvacThermostat', [{
  171. attribute: {ID: 0x1004, type: 0x30},
  172. minimumReportInterval: 0,
  173. maximumReportInterval: constants.repInterval.HOUR,
  174. reportableChange: null}],
  175. options);
  176. // FloorSensorCalibration
  177. await endpoint.configureReporting('hvacThermostat', [{
  178. attribute: {ID: 0x1005, type: 0x28},
  179. minimumReportInterval: 0,
  180. maximumReportInterval: constants.repInterval.HOUR,
  181. reportableChange: 0}],
  182. options);
  183. // DryTime
  184. await endpoint.configureReporting('hvacThermostat', [{
  185. attribute: {ID: 0x1006, type: 0x20},
  186. minimumReportInterval: 0,
  187. maximumReportInterval: constants.repInterval.HOUR,
  188. reportableChange: 0}],
  189. options);
  190. // ModeAfterDry
  191. await endpoint.configureReporting('hvacThermostat', [{
  192. attribute: {ID: 0x1007, type: 0x30},
  193. minimumReportInterval: 0,
  194. maximumReportInterval: constants.repInterval.HOUR,
  195. reportableChange: null}],
  196. options);
  197. // TemperatureDisplay
  198. await endpoint.configureReporting('hvacThermostat', [{
  199. attribute: {ID: 0x1008, type: 0x30},
  200. minimumReportInterval: 0,
  201. maximumReportInterval: constants.repInterval.HOUR,
  202. reportableChange: null}],
  203. options);
  204. // WindowOpenCheck
  205. await endpoint.configureReporting('hvacThermostat', [{
  206. attribute: {ID: 0x1009, type: 0x20},
  207. minimumReportInterval: 0,
  208. maximumReportInterval: constants.repInterval.HOUR,
  209. reportableChange: 0}],
  210. options);
  211.  
  212. // Hysterersis
  213. await endpoint.configureReporting('hvacThermostat', [{
  214. attribute: {ID: 0x100A, type: 0x20},
  215. minimumReportInterval: 0,
  216. maximumReportInterval: constants.repInterval.HOUR,
  217. reportableChange: 0}],
  218. options);
  219. // DisplayAutoOffEnable
  220. await endpoint.configureReporting('hvacThermostat', [{
  221. attribute: {ID: 0x100B, type: 0x30},
  222. minimumReportInterval: 0,
  223. maximumReportInterval: constants.repInterval.HOUR,
  224. reportableChange: null}],
  225. options);
  226.  
  227. // AlarmAirTempOverValue
  228. await endpoint.configureReporting('hvacThermostat', [{
  229. attribute: {ID: 0x2001, type: 0x20},
  230. minimumReportInterval: 0,
  231. maximumReportInterval: constants.repInterval.HOUR,
  232. reportableChange: 0}],
  233. options);
  234. // Away Mode Set
  235. await endpoint.configureReporting('hvacThermostat', [{
  236. attribute: {ID: 0x2002, type: 0x30},
  237. minimumReportInterval: 0,
  238. maximumReportInterval: constants.repInterval.HOUR,
  239. reportableChange: null}],
  240. options);
  241.  
  242. // Trigger initial read
  243. await endpoint.read('hvacThermostat', ['systemMode', 'runningState', 'occupiedHeatingSetpoint']);
  244. await endpoint.read('hvacThermostat', [0x1000, 0x1001, 0x1002, 0x1003], options);
  245. await endpoint.read('hvacThermostat', [0x1004, 0x1005, 0x1006, 0x1007], options);
  246. await endpoint.read('hvacThermostat', [0x1008, 0x1009, 0x100A, 0x100B], options);
  247. await endpoint.read('hvacThermostat', [0x2001, 0x2002], options);
  248. },
  249. ota: ota.zigbeeOTA
  250. };
  251.  
  252. module.exports = definition;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement