From d3a22d49c1d2c5b4c11826fd5a401b7728af2112 Mon Sep 17 00:00:00 2001 From: mgrom Date: Fri, 14 Aug 2020 11:43:52 +0200 Subject: [PATCH] Added presets (hold_modes) to climate sensor #3821 (#4070) * Added presets (hold_modes) to climate sensor #3821 and removed thermostatHeatCool as it's partially redundant * Added new configuration to TuYa thermostat TS0601_thermostat * eslint fixes * Added eco and comfort modes. Looks like they are usable. * Update homeassistant.js * Update homeassistant.js Co-authored-by: Koen Kanters --- lib/extension/homeassistant.js | 123 +++++++++++++++++---------------- 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/lib/extension/homeassistant.js b/lib/extension/homeassistant.js index 9d159ee7..6cda93fc 100644 --- a/lib/extension/homeassistant.js +++ b/lib/extension/homeassistant.js @@ -758,15 +758,17 @@ const sensorEndpoint = (endpointName) => { }; }; -const thermostat = (minTemp=7, maxTemp=30, temperatureStateProperty='occupied_heating_setpoint', tempStep=1) => { - return { + +const climate = (minTemp=7, maxTemp=30, temperatureStateProperty='occupied_heating_setpoint', + tempStep=1, systemModes=['off', 'auto', 'heat'], fanModes=[], holdModes=[], + temperatureLowStateTopic=false, temperatureHighStateTopic=false ) => { + const retVal = { type: 'climate', object_id: 'climate', discovery_payload: { state_topic: false, min_temp: `${minTemp}`, max_temp: `${maxTemp}`, - modes: ['off', 'auto', 'heat'], mode_state_topic: true, mode_state_template: '{{ value_json.system_mode }}', mode_command_topic: true, @@ -782,41 +784,41 @@ const thermostat = (minTemp=7, maxTemp=30, temperatureStateProperty='occupied_he ' %}{{ values[value_json.running_state] }}', }, }; + // system_modes empty <=> use auto (in other case ha ui is showing all modes) + if (systemModes.length > 0) { + retVal.discovery_payload.modes = systemModes; + } else { + retVal.discovery_payload.modes = ['auto']; + } + // hold_modes empty <=> don't use presets + if (holdModes.length > 0) { + retVal.discovery_payload.hold_modes = holdModes; + retVal.discovery_payload.hold_command_topic = true; + retVal.discovery_payload.hold_state_template = `{{ value_json.preset }}`; + retVal.discovery_payload.hold_state_topic = true; + } + // fan_modes empty <=> don't use fan modes + if (fanModes.length > 0) { + retVal.discovery_payload.fan_modes = fanModes; + retVal.discovery_payload.fan_mode_command_topic = true; + retVal.discovery_payload.fan_mode_state_template = `{{ value_json.fan_mode }}`; + retVal.discovery_payload.fan_mode_state_topic = true; + } + // use low target temperature + if (temperatureLowStateTopic) { + retVal.discovery_payload.temperature_low_state_topic = temperatureLowStateTopic; + retVal.discovery_payload.temperature_low_state_template = `{{ value_json.occupied_heating_setpoint }}`; + retVal.discovery_payload.temperature_low_command_topic = 'occupied_heating_setpoint'; + } + // use high target temperature + if (temperatureHighStateTopic) { + retVal.discovery_payload.temperature_high_state_topic = temperatureHighStateTopic; + retVal.discovery_payload.temperature_high_state_template = `{{ value_json.occupied_heating_setpoint }}`; + retVal.discovery_payload.temperature_high_command_topic = 'occupied_heating_setpoint'; + } + return retVal; }; -const thermostatHeatCool = /* istanbul ignore next */ (minTemp=7, maxTemp=30, tempStep=0.5, opModes, fanModes=[]) => { - return { - type: 'climate', - object_id: 'climate', - discovery_payload: { - state_topic: false, - temperature_unit: 'C', - min_temp: `${minTemp}`, - max_temp: `${maxTemp}`, - modes: opModes, - mode_state_topic: true, - mode_state_template: '{{ value_json.system_mode }}', - mode_command_topic: true, - current_temperature_topic: true, - current_temperature_template: '{{ value_json.local_temperature }}', - temperature_low_state_topic: true, - temperature_low_state_template: `{{ value_json.occupied_heating_setpoint }}`, - temperature_high_state_topic: true, - temperature_high_state_template: `{{ value_json.occupied_cooling_setpoint }}`, - temperature_low_command_topic: 'occupied_heating_setpoint', - temperature_high_command_topic: 'occupied_cooling_setpoint', - temp_step: tempStep, - action_topic: true, - action_template: - '{% set values = {\'idle\':\'off\',\'heat\':\'heating\',\'cool\':\'cooling\',\'fan only\':\'fan\'}'+ - ' %}{{ values[value_json.running_state] }}', - fan_modes: fanModes, - fan_mode_command_topic: true, - fan_mode_state_topic: true, - fan_mode_state_template: '{{ value_json.fan_mode }}', - }, - }; -}; // Map Home Assistant configurations to devices. const mapping = { @@ -1036,7 +1038,7 @@ const mapping = { 'GL-B-008Z': [cfg.light_brightness_colortemp_colorxy], 'AV2010/25': [cfg.switch, cfg.sensor_power], 'E12-N14': [cfg.light_brightness], - '1TST-EU': [thermostat(), cfg.sensor_battery], + '1TST-EU': [climate(), cfg.sensor_battery], 'RB 178 T': [cfg.light_brightness_colortemp], '45856GE': [cfg.switch], 'GL-D-003Z': [cfg.light_brightness_colortemp_colorxy], @@ -1047,7 +1049,7 @@ const mapping = { 'D1531': [cfg.light_brightness], 'D1532': [cfg.light_brightness], 'D1533': [cfg.light_brightness], - 'AV2010/32': [thermostat(7, 30, 'occupied_heating_setpoint', 0.5), cfg.sensor_battery], + 'AV2010/32': [climate(7, 30, 'occupied_heating_setpoint', 0.5), cfg.sensor_battery], 'HGZB-07A': [cfg.light_brightness_colortemp_colorxy], 'E1524/E1810': [cfg.sensor_action, cfg.sensor_battery], 'GL-C-006': [cfg.light_brightness_colortemp], @@ -1076,7 +1078,7 @@ const mapping = { 'NLG-RGBW light': [cfg.light_brightness_colortemp_colorxy], 'NLG-RGB-TW light': [cfg.light_brightness_colortemp_colorxy], 'TI0001': [switchEndpoint('left'), switchEndpoint('right')], - 'SPZB0001': [thermostat(5, 30, 'current_heating_setpoint', 0.5), cfg.sensor_battery], + 'SPZB0001': [climate(5, 30, 'current_heating_setpoint', 0.5), cfg.sensor_battery], 'HS3CG': [cfg.binary_sensor_gas], '81825': [cfg.sensor_action], 'Z809AF': [cfg.switch, cfg.sensor_power], @@ -1115,7 +1117,7 @@ const mapping = { '316GLEDRF': [cfg.light_brightness], 'LVS-ZB500D': [cfg.light_brightness], 'ST218': [ - thermostat(5, 30, 'occupied_heating_setpoint', 0.5), + climate(5, 30, 'occupied_heating_setpoint', 0.5), cfg.sensor_local_temperature, cfg.lock_keypad_lockout, ], @@ -1331,13 +1333,13 @@ const mapping = { 'LVS-SN10ZW': [cfg.sensor_battery, cfg.binary_sensor_occupancy], 'LVS-ZB15R': [cfg.switch], 'TH1123ZB': [ - thermostat(7, 30, 'occupied_heating_setpoint', 1.0), cfg.sensor_local_temperature, + climate(7, 30, 'occupied_heating_setpoint', 1.0), cfg.sensor_local_temperature, cfg.lock_keypad_lockout, cfg.sensor_power, ], - 'TH1124ZB': [thermostat()], - 'TH1400ZB': [thermostat()], - 'TH1500ZB': [thermostat()], - 'Zen-01-W': [thermostat(10, 30, 'occupied_heating_setpoint', 0.5)], + 'TH1124ZB': [climate()], + 'TH1400ZB': [climate()], + 'TH1500ZB': [climate()], + 'Zen-01-W': [climate(10, 30, 'occupied_heating_setpoint', 0.5)], '9290022166': [cfg.light_brightness_colortemp_colorxy], 'PM-C140-ZB': [cfg.sensor_power, cfg.switch], 'PM-B530-ZB': [cfg.sensor_power, cfg.switch], @@ -1449,7 +1451,7 @@ const mapping = { 'CR11S8UZ': [cfg.sensor_action], 'RB 148 T': [cfg.light_brightness_colortemp], 'STS-OUT-US-2': [cfg.switch, cfg.sensor_power], - 'UK7004240': [thermostat(), cfg.sensor_battery], + 'UK7004240': [climate(), cfg.sensor_battery], 'S31ZB': [cfg.switch], 'SA-003-Zigbee': [cfg.switch], 'SZ-DWS04': [cfg.binary_sensor_contact, cfg.sensor_temperature, cfg.sensor_battery], @@ -1523,24 +1525,24 @@ const mapping = { 'ZM-L03E-Z': [switchEndpoint('left'), switchEndpoint('center'), switchEndpoint('right')], 'DL15S-1BZ': [cfg.switch], 'E1D-G73WNA': [cfg.binary_sensor_contact, cfg.binary_sensor_battery_low], - 'WV704R0A0902': [thermostat()], + 'WV704R0A0902': [climate()], '067776': [cfg.cover_position], '067773': [cfg.sensor_action, cfg.sensor_battery], '067771': [cfg.light_brightness], '064873': [cfg.sensor_action], 'K4003C/L4003C/N4003C/NT4003C': [cfg.switch, cfg.sensor_action], 'STZB402': [ - thermostat(5, 30, 'occupied_heating_setpoint', 0.5), + climate(5, 30, 'occupied_heating_setpoint', 0.5), cfg.sensor_local_temperature, cfg.lock_keypad_lockout, ], 'SMT402': [ - thermostat(5, 30, 'occupied_heating_setpoint', 0.5), + climate(5, 30, 'occupied_heating_setpoint', 0.5), cfg.sensor_local_temperature, cfg.lock_keypad_lockout, ], 'SMT402AD': [ - thermostat(5, 30, 'occupied_heating_setpoint', 0.5), + climate(5, 30, 'occupied_heating_setpoint', 0.5), cfg.sensor_local_temperature, cfg.lock_keypad_lockout, ], @@ -1575,7 +1577,7 @@ const mapping = { 'ZG2835RAC': [cfg.light_brightness, cfg.sensor_power, cfg.sensor_energy], 'BW-IS2': [cfg.binary_sensor_contact, cfg.sensor_battery], 'BW-IS3': [cfg.binary_sensor_occupancy], - 'SLR1b': [thermostat()], + 'SLR1b': [climate()], 'WPT1': [], '4058075047853': [cfg.light_brightness_colortemp_colorxy], 'ROB_200-003-0': [cfg.switch], @@ -1647,7 +1649,7 @@ const mapping = { cfg.lock_child_lock, cfg.switch_window_detection, cfg.switch_valve_detection, - thermostat(5, 30, 'current_heating_setpoint', 0.5), + climate(5, 30, 'current_heating_setpoint', 0.5), cfg.sensor_battery, ], 'HLC614-ZLL': [switchEndpoint('l1'), switchEndpoint('l2'), switchEndpoint('l3')], @@ -1683,7 +1685,8 @@ const mapping = { 'E12-N1E': [cfg.light_brightness_colortemp_colorxy], '4040B': [cfg.sensor_power, switchEndpoint('l1'), switchEndpoint('l2')], '3460-L': [cfg.sensor_action, cfg.sensor_temperature, cfg.sensor_battery], - '3157100': [thermostatHeatCool(10, 30, 1, ['off', 'heat', 'cool'], ['auto', 'on']), cfg.sensor_battery], + '3157100': [climate(10, 30, 'occupied_heating_setpoint', 1, ['off', 'heat', 'cool'], + ['auto', 'on'], [], true, true), cfg.sensor_battery], '4257050-RZHAC': [cfg.switch, cfg.sensor_power], '27087-03': [cfg.switch, cfg.sensor_battery], '99140-002': [cfg.lock, cfg.sensor_battery], @@ -1691,8 +1694,9 @@ const mapping = { 'GL-S-004ZS': [cfg.light_brightness_colortemp_colorxy], '7121131PU': [cfg.light_brightness_colortemp_colorxy], 'RL804QZB': [switchEndpoint('l1'), switchEndpoint('l2'), switchEndpoint('l3')], - 'RC-2000WH': [thermostatHeatCool(10, 30, 1, ['off', 'auto', 'heat', 'cool'], ['auto', 'on', 'smart'])], - 'TH1300ZB': [thermostat()], + 'RC-2000WH': [climate(10, 30, 'occupied_heating_setpoint', 1, ['off', 'auto', 'heat', 'cool'], + ['auto', 'on', 'smart'], [], true, true)], + 'TH1300ZB': [climate()], 'SP 220': [cfg.switch], '511.040': [cfg.light_brightness_colortemp_colorxy], '511.344': [cfg.sensor_battery, cfg.sensor_action, cfg.sensor_action_color, cfg.sensor_action_color_temperature], @@ -1715,7 +1719,8 @@ const mapping = { 'RF 264': [cfg.light_brightness], 'TS0601_thermostat': [ cfg.lock_child_lock, cfg.switch_window_detection, cfg.switch_valve_detection, cfg.sensor_battery, - thermostat(5, 30, 'current_heating_setpoint', 0.5), + climate(5, 30, 'current_heating_setpoint', 0.5, [], [], + ['schedule', 'manual', 'away', 'boost', 'complex', 'comfort', 'eco']), ], 'WXKG07LM': [cfg.sensor_action, cfg.sensor_battery], 'MCLH-03': [cfg.switch, cfg.sensor_voltage, cfg.sensor_power, cfg.sensor_current], @@ -1733,7 +1738,7 @@ const mapping = { 'AU-A1ZBRC': [cfg.sensor_action, cfg.sensor_battery], 'AU-A1ZBPIRS': [cfg.binary_sensor_occupancy, cfg.binary_sensor_battery_low, cfg.sensor_illuminance_lux], 'TS0121': [cfg.switch, cfg.sensor_voltage, cfg.sensor_power, cfg.sensor_current], - 'ZK03840': [thermostat()], + 'ZK03840': [climate()], 'ZS1100400-IN-V1A02': [cfg.binary_sensor_occupancy, cfg.binary_sensor_battery_low], 'MCLH-08': [cfg.sensor_temperature, cfg.sensor_humidity, cfg.sensor_eco2, cfg.sensor_voc], 'GL-FL-005TZ': [cfg.light_brightness_colortemp_colorxy], @@ -1870,8 +1875,8 @@ const mapping = { 'HLQDQ01LM': [cfg.light_brightness], 'TS0502A': [cfg.light_brightness_colortemp], 'TS0004': [switchEndpoint('l1'), switchEndpoint('l2'), switchEndpoint('l3'), switchEndpoint('l4')], - 'U86KWF-ZPSJ': [thermostat(5, 30, 'current_heating_setpoint', 0.5)], - 'D3-DPWK-TY': [thermostat(5, 30, 'current_heating_setpoint', 0.5)], + 'U86KWF-ZPSJ': [climate(5, 30, 'current_heating_setpoint', 0.5)], + 'D3-DPWK-TY': [climate(5, 30, 'current_heating_setpoint', 0.5)], '100.075.74': [cfg.light_brightness_colortemp_colorxy], '9290019534': [cfg.light_brightness_colortemp], };