zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

BAC-002-ALZB - full support heating, cooling, ventilation

Open Prim0z opened this issue 5 years ago • 45 comments

BAC-002-ALZB thermostat supports heating, cooling and ventilation. With current device support #6761 you can only control cooling. For full support we also need heating and ventilation.

At current stage we are missing mode setpoint (heating/cooling/ventilation) and fan speed setpoint (1/2/3/auto).

Is anyone willing to implement this futures? I don't have deep enough technical knowledge about zigbee2mqtt to do it myself, but I can provide data logs and testing resources. I can also send you a BAC-002-ALZB thermostat for testing and development. No need to return it, you can keep it.

Prim0z avatar Jul 08 '21 06:07 Prim0z

I created configuration to support:

  • state: OFF, ON
  • system_mode: cool, heat, fan_only
  • fan_mode: low, medium, high, auto

If you want to include it in master branch, feel free to do so.

Instructions to include it as custom device:

  1. Currently you need a DEV branch.
  2. Stop zigbee2mqtt
  3. Create file zigbee2mqtt/data/BAC-002-ALZB.js
const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const ota = require('zigbee-herdsman-converters/lib/ota');
const {repInterval, defaultBindGroup, OneJanuary2000} = require('zigbee-herdsman-converters/lib/constants');
const utils = require('zigbee-herdsman-converters/lib/utils');
const e = exposes.presets;
const ea = exposes.access;



const fz_moes_thermostat_custom = {
	cluster: 'manuSpecificTuya',
	type: ['commandGetData', 'commandSetDataResponse'],
	convert: (model, msg, publish, options, meta) => {
		const dp = msg.data.dp;
		const value = tuya.getDataValue(msg.data.datatype, msg.data.data);
		let temperature;
		/* See tuyaThermostat above for message structure comment */
		switch (dp) {
		case tuya.dataPoints.moesSchedule:
			return {
				program: [
					{weekdays_p1: value[0] + 'h:' + value[1] + 'm ' + value[2]/2 + '°C'},
					{weekdays_p2: value[3] + 'h:' + value[4] + 'm ' + value[5]/2 + '°C'},
					{weekdays_p3: value[6] + 'h:' + value[7] + 'm ' + value[8]/2 + '°C'},
					{weekdays_p4: value[9] + 'h:' + value[10] + 'm ' + value[11]/2 + '°C'},
					{saturday_p1: value[12] + 'h:' + value[13] + 'm ' + value[14]/2+ '°C'},
					{saturday_p2: value[15] + 'h:' + value[16] + 'm ' + value[17]/2 + '°C'},
					{saturday_p3: value[18] + 'h:' + value[19] + 'm ' + value[20]/2 + '°C'},
					{saturday_p4: value[21] + 'h:' + value[22] + 'm ' + value[23]/2 + '°C'},
					{sunday_p1: value[24] + 'h:' + value[25] + 'm ' + value[26]/2 + '°C'},
					{sunday_p2: value[27] + 'h:' + value[28] + 'm ' + value[29]/2 + '°C'},
					{sunday_p3: value[30] + 'h:' + value[31] + 'm ' + value[32]/2 + '°C'},
					{sunday_p4: value[33] + 'h:' + value[34] + 'm ' + value[35]/2 + '°C'},
				],
			};
		case 1: // system mode (OFF, ON)
			if(value == 0) {
				return {state: 'OFF'};
			} else if(value == 1) {
				return {state: 'ON'};
			} else {
				return {};
			}
		case 2: // system mode (cooling, heating, fan)
			if(value == 0) {
				return {system_mode: 'cool'};
			} else if(value == 1) {
				return {system_mode: 'heat'};
			} else if(value == 2) {
				return {system_mode: 'fan_only'};
			} else {
				return {};
			}
		case 28: // fan mode
			if(value == 0) {
				return {fan_mode: 'low'};
			} else if(value == 1) {
				return {fan_mode: 'medium'};
			} else if(value == 2) {
				return {fan_mode: 'high'};
			} else if(value == 3) {
				return {fan_mode: 'auto'};
			} else {
				return {};
			}
		case 16: // temperature setpoint for both heating and cooling
			return {occupied_heating_setpoint: value, occupied_cooling_setpoint: value};
		case tuya.dataPoints.moesChildLock:
			return {child_lock: value ? 'LOCK' : 'UNLOCK'};
		case tuya.dataPoints.moesMaxTempLimit:
			return {max_temperature_limit: value};
		case tuya.dataPoints.moesMaxTemp:
			return {max_temperature: value};
		case tuya.dataPoints.moesDeadZoneTemp:
			return {deadzone_temperature: value};
		case tuya.dataPoints.moesLocalTemp:
			temperature = value & 1<<15 ? value - (1<<16) + 1 : value;
			return {local_temperature: parseFloat((temperature / 10).toFixed(1))};
		case tuya.dataPoints.moesTempCalibration:
			temperature = value;
			// for negative values produce complimentary hex (equivalent to negative values)
			if (temperature > 4000) temperature = temperature - 4096;
			return {local_temperature_calibration: temperature};
		case tuya.dataPoints.moesHold: // state is inverted, preset_mode is deprecated
			return {preset_mode: value ? 'program' : 'hold', preset: value ? 'program' : 'hold'};
		case tuya.dataPoints.moesScheduleEnable: // state is inverted, preset_mode is deprecated
			return {preset_mode: value ? 'hold' : 'program', preset: value ? 'hold' : 'program'};
		case tuya.dataPoints.moesValve:
			return {heat: value ? 'OFF' : 'ON'};
		case tuya.dataPoints.moesSensor:
			switch (value) {
			case 0:
				return {sensor: 'IN'};
			case 1:
				return {sensor: 'AL'};
			case 2:
				return {sensor: 'OU'};
			default:
				return {sensor: 'not_supported'};
			}
		default: // DataPoint 17 is unknown
			meta.logger.warn(`zigbee-herdsman-converters:Moes BHT-002: Unrecognized DP #${
				dp} with data ${JSON.stringify(msg.data)}`);
		}
	},
};


const tz_state = {
	key: ['state'],
	convertSet: async (entity, key, value, meta) => {
		if(value == "OFF") {
			await tuya.sendDataPointBool(entity, 1, false);
		} else if(value == "ON") {
			await tuya.sendDataPointBool(entity, 1, true);
		}
	},
};

const tz_system_mode = {
	key: ['system_mode'],
	convertSet: async (entity, key, value, meta) => {
		if(value == "cool") {
			await tuya.sendDataPointEnum(entity, 2, 0);
		} else if(value == "heat") {
			await tuya.sendDataPointEnum(entity, 2, 1);
		} else if(value == "fan_only") {
			await tuya.sendDataPointEnum(entity, 2, 2);
		}
	},
};

const tz_temperature_setpoint = {
	key: ['occupied_heating_setpoint', 'occupied_cooling_setpoint'],
	convertSet: async (entity, key, value, meta) => {
		await tuya.sendDataPointValue(entity, 16, value);
	},
};

const tz_fan_mode = {
	key: ['fan_mode'],
	convertSet: async (entity, key, value, meta) => {
		if(value == "low") {
			await tuya.sendDataPointEnum(entity, 28, 0);
		} else if(value == "medium") {
			await tuya.sendDataPointEnum(entity, 28, 1);
		} else if(value == "high") {
			await tuya.sendDataPointEnum(entity, 28, 2);			
		} else if(value == "auto") {
			await tuya.sendDataPointEnum(entity, 28, 3);			
		}
	},
};

module.exports = [
    {
        fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_dzuqwsyg'}],
        model: 'BAC-002-ALZB',
        vendor: 'HKGK',
        description: 'BAC series thermostat',
        fromZigbee: [fz_moes_thermostat_custom],
        toZigbee: [tz_state, tz_system_mode, tz_fan_mode, tz_temperature_setpoint, tz.moes_thermostat_child_lock, tz.moes_thermostat_current_heating_setpoint, tz.moes_thermostat_mode,
            tz.hgkg_thermostat_standby, tz.moes_thermostat_sensor, tz.moes_thermostat_calibration,
            tz.moes_thermostat_deadzone_temperature, tz.moes_thermostat_max_temperature_limit],
        exposes: [e.child_lock(), e.deadzone_temperature(), e.max_temperature_limit(),
			exposes.switch()
				.withState('state', false, 'OFF/ON state'),
            exposes.climate()
				.withSetpoint('occupied_heating_setpoint', 5, 35, 1, ea.STATE_SET)
				.withSetpoint('occupied_cooling_setpoint', 5, 35, 1, ea.STATE_SET)
                .withLocalTemperature(ea.STATE)
				.withLocalTemperatureCalibration(ea.STATE_SET)
                .withSystemMode(['cool', 'heat', 'fan_only'], ea.STATE_SET)
				.withFanMode(['low', 'medium', 'high', 'auto'], ea.STATE_SET)
				.withRunningState(['idle', 'heat', 'cool'], ea.STATE)
                .withPreset(['hold', 'program'])
				.withSensor(['IN', 'AL', 'OU'], ea.STATE_SET)],
        onEvent: tuya.onEventSetLocalTime,
    },
];

  1. Include external convertor to configuation.yaml
external_converters:
  - BAC-002-ALZB.js
  1. Start zigbee2mqtt

Prim0z avatar Jul 13 '21 11:07 Prim0z

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

github-actions[bot] avatar Aug 13 '21 00:08 github-actions[bot]

hi i am trying this procedure to add heating and fan features ..but it's doesn't work .. is there way to see this features integrated with z2m directly ? @Prim0z could you help me with manual integration ? i have done all steps ( and i hasn't error ) , but i can't see additional features in zigbee2mqtt edge activated .

my system : Versione Zigbee2MQTT 1.21.1-dev commit: 5829663 - HKGK BAC-002-ALZB - Tipo Coordinator zStack3x0 Revisione Coordinator 20210708 Versione frontend 0.6.8

regards

Luigi

mediaworld2007 avatar Dec 12 '21 09:12 mediaworld2007

I created configuration to support:

  • state: OFF, ON
  • system_mode: cool, heat, fan_only
  • fan_mode: low, medium, high, auto

@Prim0z Thanks a lot!!! You save my day!

Bandit13 avatar Dec 16 '21 12:12 Bandit13

hi i am trying this procedure to add heating and fan features ..but it's doesn't work .. is there way to see this features integrated with z2m directly ? @Prim0z could you help me with manual integration ? i have done all steps ( and i hasn't error ) , but i can't see additional features in zigbee2mqtt edge activated .

my system : Versione Zigbee2MQTT 1.21.1-dev commit: 5829663 - HKGK BAC-002-ALZB - Tipo Coordinator zStack3x0 Revisione Coordinator 20210708 Versione frontend 0.6.8

regards

Luigi

I solved ( issue were space in the file.js ) Thanks Luigi

mediaworld2007 avatar Jan 06 '22 22:01 mediaworld2007

 Yes! It works!  07.01.2022, 01:07, "mediaworld2007" @.>: I created configuration to support:state: OFF, ONsystem_mode: cool, heat, fan_onlyfan_mode: low, medium, high, @. Thanks a lot!!! You save my day!Hi Bandit, is this working for you at today ?regardsLuigi—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android.You are receiving this because you commented.Message ID: @.***>

Bandit13 avatar Jan 13 '22 11:01 Bandit13

This should be merged into the release. Natively in Z2M the device is supported, but Fan speed and mode is not exposed.

madspoulsen avatar Jun 09 '22 21:06 madspoulsen

hm, I set up the external converter and can now control all objects of the thermostat, but the feedback isn't being read. Values not updating. I get in logs this: Debug 2022-06-12 23:01:24No converter available for 'BAC-002-ALZB' with cluster 'manuSpecificTuya' and type 'commandDataResponse' and data '{"dpValues":[{"data":{"data":[0,0,0,25],"type":"Buffer"},"datatype":2,"dp":16}],"seq":4666}' Debug 2022-06-12 23:01:24Received Zigbee message from 'Living Room A/C', type 'commandDataResponse', cluster 'manuSpecificTuya', data '{"dpValues":[{"data":{"data":[0,0,0,25],"type":"Buffer"},"datatype":2,"dp":16}],"seq":4922}' from endpoint 1 with groupID 0

So it seems that the from zigbee is not converted properly.

Can this be because i'm not in DEV branch?

madspoulsen avatar Jun 12 '22 19:06 madspoulsen

hm, I set up the external converter and can now control all objects of the thermostat, but the feedback isn't being read. Values not updating. I get in logs this: Debug 2022-06-12 23:01:24No converter available for 'BAC-002-ALZB' with cluster 'manuSpecificTuya' and type 'commandDataResponse' and data '{"dpValues":[{"data":{"data":[0,0,0,25],"type":"Buffer"},"datatype":2,"dp":16}],"seq":4666}' Debug 2022-06-12 23:01:24Received Zigbee message from 'Living Room A/C', type 'commandDataResponse', cluster 'manuSpecificTuya', data '{"dpValues":[{"data":{"data":[0,0,0,25],"type":"Buffer"},"datatype":2,"dp":16}],"seq":4922}' from endpoint 1 with groupID 0

So it seems that the from zigbee is not converted properly.

Can this be because i'm not in DEV branch?

I have the same issue and I'm in DEV branch, did you manage to fix it?

dilayn avatar Jun 22 '22 05:06 dilayn

Dilayn, I'm using this currently. It supports the feature thermostat to a useable extend, with feedback. ` const fz = require('zigbee-herdsman-converters/converters/fromZigbee'); const tz = require('zigbee-herdsman-converters/converters/toZigbee'); const exposes = require('zigbee-herdsman-converters/lib/exposes'); const reporting = require('zigbee-herdsman-converters/lib/reporting'); const extend = require('zigbee-herdsman-converters/lib/extend'); const tuya = require('zigbee-herdsman-converters/lib/tuya'); const ota = require('zigbee-herdsman-converters/lib/ota'); const {repInterval, defaultBindGroup, OneJanuary2000} = require('zigbee-herdsman-converters/lib/constants'); const utils = require('zigbee-herdsman-converters/lib/utils'); const e = exposes.presets; const ea = exposes.access;

const fz_moes_thermostat_custom = { cluster: 'manuSpecificTuya', type: ['commandGetData', 'commandSetDataResponse', 'commandDataResponse'], convert: (model, msg, publish, options, meta) => { const dpValue = tuya.firstDpValue(msg, meta, 'moes_thermostat'); const dp = dpValue.dp; const value = tuya.getDataValue(dpValue); let temperature; /* See tuyaThermostat above for message structure comment */ switch (dp) { case tuya.dataPoints.moesSchedule: return { program: [ {weekdays_p1: value[0] + 'h:' + value[1] + 'm ' + value[2]/2 + '°C'}, {weekdays_p2: value[3] + 'h:' + value[4] + 'm ' + value[5]/2 + '°C'}, {weekdays_p3: value[6] + 'h:' + value[7] + 'm ' + value[8]/2 + '°C'}, {weekdays_p4: value[9] + 'h:' + value[10] + 'm ' + value[11]/2 + '°C'}, {saturday_p1: value[12] + 'h:' + value[13] + 'm ' + value[14]/2+ '°C'}, {saturday_p2: value[15] + 'h:' + value[16] + 'm ' + value[17]/2 + '°C'}, {saturday_p3: value[18] + 'h:' + value[19] + 'm ' + value[20]/2 + '°C'}, {saturday_p4: value[21] + 'h:' + value[22] + 'm ' + value[23]/2 + '°C'}, {sunday_p1: value[24] + 'h:' + value[25] + 'm ' + value[26]/2 + '°C'}, {sunday_p2: value[27] + 'h:' + value[28] + 'm ' + value[29]/2 + '°C'}, {sunday_p3: value[30] + 'h:' + value[31] + 'm ' + value[32]/2 + '°C'}, {sunday_p4: value[33] + 'h:' + value[34] + 'm ' + value[35]/2 + '°C'}, ], }; case 1: // system mode (OFF, ON) if(value == 0) { return {state: 'OFF'}; } else if(value == 1) { return {state: 'ON'}; } else { return {}; } case 2: // system mode (cooling, heating, fan) if(value == 0) { return {system_mode: 'cool'}; } else if(value == 1) { return {system_mode: 'heat'}; } else if(value == 2) { return {system_mode: 'fan_only'}; } else { return {}; } case 28: // fan mode if(value == 0) { return {fan_mode: 'low'}; } else if(value == 1) { return {fan_mode: 'medium'}; } else if(value == 2) { return {fan_mode: 'high'}; } else if(value == 3) { return {fan_mode: 'auto'}; } else { return {}; } case 16: // temperature setpoint for both heating and cooling return {occupied_heating_setpoint: value, occupied_cooling_setpoint: value}; case tuya.dataPoints.moesChildLock: return {child_lock: value ? 'LOCK' : 'UNLOCK'}; case tuya.dataPoints.moesMaxTempLimit: return {max_temperature_limit: value}; case tuya.dataPoints.moesMaxTemp: return {max_temperature: value}; case tuya.dataPoints.moesDeadZoneTemp: return {deadzone_temperature: value}; case tuya.dataPoints.moesLocalTemp: temperature = value & 1<<15 ? value - (1<<16) + 1 : value; return {local_temperature: parseFloat((temperature / 10).toFixed(1))}; case tuya.dataPoints.moesTempCalibration: temperature = value; // for negative values produce complimentary hex (equivalent to negative values) if (temperature > 4000) temperature = temperature - 4096; return {local_temperature_calibration: temperature}; case tuya.dataPoints.moesHold: // state is inverted, preset_mode is deprecated return {preset_mode: value ? 'program' : 'hold', preset: value ? 'program' : 'hold'}; case tuya.dataPoints.moesScheduleEnable: // state is inverted, preset_mode is deprecated return {preset_mode: value ? 'hold' : 'program', preset: value ? 'hold' : 'program'}; case tuya.dataPoints.moesValve: return {heat: value ? 'OFF' : 'ON'}; case tuya.dataPoints.moesSensor: switch (value) { case 0: return {sensor: 'IN'}; case 1: return {sensor: 'AL'}; case 2: return {sensor: 'OU'}; default: return {sensor: 'not_supported'}; } default: // DataPoint 17 is unknown meta.logger.warn(zigbee-herdsman-converters:Moes BHT-002: Unrecognized DP #${ dp} with data ${JSON.stringify(msg.data)}); } }, };

const tz_state = { key: ['state'], convertSet: async (entity, key, value, meta) => { if(value == "OFF") { await tuya.sendDataPointBool(entity, 1, false); } else if(value == "ON") { await tuya.sendDataPointBool(entity, 1, true); } }, };

const tz_system_mode = { key: ['system_mode'], convertSet: async (entity, key, value, meta) => { if(value == "cool") { await tuya.sendDataPointEnum(entity, 2, 0); } else if(value == "heat") { await tuya.sendDataPointEnum(entity, 2, 1); } else if(value == "fan_only") { await tuya.sendDataPointEnum(entity, 2, 2); } }, };

const tz_temperature_setpoint = { key: ['occupied_heating_setpoint', 'occupied_cooling_setpoint'], convertSet: async (entity, key, value, meta) => { await tuya.sendDataPointValue(entity, 16, value); }, };

const tz_fan_mode = { key: ['fan_mode'], convertSet: async (entity, key, value, meta) => { if(value == "low") { await tuya.sendDataPointEnum(entity, 28, 0); } else if(value == "medium") { await tuya.sendDataPointEnum(entity, 28, 1); } else if(value == "high") { await tuya.sendDataPointEnum(entity, 28, 2); } else if(value == "auto") { await tuya.sendDataPointEnum(entity, 28, 3); } }, };

module.exports = [ { fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_dzuqwsyg'}], model: 'BAC-002-ALZB', vendor: 'HKGK', description: 'BAC series thermostat', fromZigbee: [fz_moes_thermostat_custom], toZigbee: [tz_state, tz_system_mode, tz_fan_mode, tz_temperature_setpoint, tz.moes_thermostat_child_lock, tz.moes_thermostat_current_heating_setpoint, tz.moes_thermostat_mode, tz.hgkg_thermostat_standby, tz.moes_thermostat_sensor, tz.moes_thermostat_calibration, tz.moes_thermostat_deadzone_temperature, tz.moes_thermostat_max_temperature_limit], exposes: [e.child_lock(), e.deadzone_temperature(), e.max_temperature_limit(), exposes.switch() .withState('state', false, 'OFF/ON state'), exposes.climate() .withSetpoint('occupied_heating_setpoint', 16, 35, 1, ea.STATE_SET) .withSetpoint('occupied_cooling_setpoint', 16, 35, 1, ea.STATE_SET) .withLocalTemperature(ea.STATE) .withLocalTemperatureCalibration(ea.STATE_SET) .withSystemMode(['cool', 'heat', 'fan_only'], ea.STATE_SET) .withFanMode(['low', 'medium', 'high', 'auto'], ea.STATE_SET) .withRunningState(['idle', 'heat', 'cool'], ea.STATE) .withPreset(['hold', 'program']) .withSensor(['IN', 'AL', 'OU'], ea.STATE_SET)], onEvent: tuya.onEventSetLocalTime, }, ]; `

madspoulsen avatar Jun 22 '22 11:06 madspoulsen

ok, I dont know how to paste the file so it keeps the indentations.. pls advise.

madspoulsen avatar Jun 22 '22 11:06 madspoulsen

thank you,

try to upload the file as attachment

dilayn avatar Jun 22 '22 11:06 dilayn

BAC-002-ALZB_converter.js.txt

Ok, here it is, rename to .js

madspoulsen avatar Jun 22 '22 11:06 madspoulsen

in the Dashboard thermostat-view, it shows 2 temperature adjustments. For me it is the right one that adjusts the thermostat... :S

madspoulsen avatar Jun 22 '22 11:06 madspoulsen

was hoping this would fix the deadzone functionality, sadly not :')

dilayn avatar Jun 22 '22 11:06 dilayn

in the Dashboard thermostat-view, it shows 2 temperature adjustments. For me it is the right one that adjusts the thermostat... :S

Hi, your converter working perfect, but... I can't provide service 'climate.turn_off'

Can you help to tune your code? (I'm also trying but have no luck : ) ) My fancoil heaven't heating tubes. I need only one target temperature (for cooling) but also want to turn on/off , cool, fan_only, and adjust fan speed.

Smthg like this fancoil

c0dr1ver avatar Jul 01 '22 16:07 c0dr1ver

BAC-002-ALZB.js.txt

Use the file above or the code below as converter:

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const ota = require('zigbee-herdsman-converters/lib/ota');
const {repInterval, defaultBindGroup, OneJanuary2000} = require('zigbee-herdsman-converters/lib/constants');
const utils = require('zigbee-herdsman-converters/lib/utils');
const e = exposes.presets;
const ea = exposes.access;



const fz_moes_thermostat_custom = {
	cluster: 'manuSpecificTuya',
	type: ['commandGetData', 'commandSetDataResponse', 'commandDataResponse'],
	convert: (model, msg, publish, options, meta) => {
            const dpValue = tuya.firstDpValue(msg, meta, 'moes_thermostat');
            const dp = dpValue.dp;
            const value = tuya.getDataValue(dpValue);
		let temperature;
		/* See tuyaThermostat above for message structure comment */
		switch (dp) {
		case tuya.dataPoints.moesSchedule:
			return {
				program: [
					{weekdays_p1: value[0] + 'h:' + value[1] + 'm ' + value[2]/2 + '°C'},
					{weekdays_p2: value[3] + 'h:' + value[4] + 'm ' + value[5]/2 + '°C'},
					{weekdays_p3: value[6] + 'h:' + value[7] + 'm ' + value[8]/2 + '°C'},
					{weekdays_p4: value[9] + 'h:' + value[10] + 'm ' + value[11]/2 + '°C'},
					{saturday_p1: value[12] + 'h:' + value[13] + 'm ' + value[14]/2+ '°C'},
					{saturday_p2: value[15] + 'h:' + value[16] + 'm ' + value[17]/2 + '°C'},
					{saturday_p3: value[18] + 'h:' + value[19] + 'm ' + value[20]/2 + '°C'},
					{saturday_p4: value[21] + 'h:' + value[22] + 'm ' + value[23]/2 + '°C'},
					{sunday_p1: value[24] + 'h:' + value[25] + 'm ' + value[26]/2 + '°C'},
					{sunday_p2: value[27] + 'h:' + value[28] + 'm ' + value[29]/2 + '°C'},
					{sunday_p3: value[30] + 'h:' + value[31] + 'm ' + value[32]/2 + '°C'},
					{sunday_p4: value[33] + 'h:' + value[34] + 'm ' + value[35]/2 + '°C'},
				],
			};
		case 1: // system mode (OFF, ON)
			if(value == 0) {
				return {state: 'OFF'};
			} else if(value == 1) {
				return {state: 'ON'};
			} else {
				return {};
			}
		case 2: // system mode (cooling, heating, fan)
			if(value == 0) {
				return {system_mode: 'cool'};
			} else if(value == 1) {
				return {system_mode: 'heat'};
			} else if(value == 2) {
				return {system_mode: 'fan_only'};
			} else {
				return {};
			}
		case 28: // fan mode
			if(value == 0) {
				return {fan_mode: 'low'};
			} else if(value == 1) {
				return {fan_mode: 'medium'};
			} else if(value == 2) {
				return {fan_mode: 'high'};
			} else if(value == 3) {
				return {fan_mode: 'auto'};
			} else {
				return {};
			}
		case 16: // temperature setpoint for both heating and cooling
			return {occupied_heating_setpoint: value};
		case tuya.dataPoints.moesChildLock:
			return {child_lock: value ? 'LOCK' : 'UNLOCK'};
		case tuya.dataPoints.moesMaxTempLimit:
			return {max_temperature_limit: value};
		case tuya.dataPoints.moesMaxTemp:
			return {max_temperature: value};
		case tuya.dataPoints.moesDeadZoneTemp:
			return {deadzone_temperature: value};
		case tuya.dataPoints.moesLocalTemp:
			temperature = value & 1<<15 ? value - (1<<16) + 1 : value;
			return {local_temperature: parseFloat((temperature / 10).toFixed(1))};
		case tuya.dataPoints.moesTempCalibration:
			temperature = value;
			// for negative values produce complimentary hex (equivalent to negative values)
			if (temperature > 4000) temperature = temperature - 4096;
			return {local_temperature_calibration: temperature};
		case tuya.dataPoints.moesHold: // state is inverted, preset_mode is deprecated
			return {preset_mode: value ? 'program' : 'hold', preset: value ? 'program' : 'hold'};
		case tuya.dataPoints.moesScheduleEnable: // state is inverted, preset_mode is deprecated
			return {preset_mode: value ? 'hold' : 'program', preset: value ? 'hold' : 'program'};
		case tuya.dataPoints.moesValve:
			return {heat: value ? 'OFF' : 'ON'};
		case tuya.dataPoints.moesSensor:
			switch (value) {
			case 0:
				return {sensor: 'IN'};
			case 1:
				return {sensor: 'AL'};
			case 2:
				return {sensor: 'OU'};
			default:
				return {sensor: 'not_supported'};
			}
		default: // DataPoint 17 is unknown
			meta.logger.warn(`zigbee-herdsman-converters:Moes BHT-002: Unrecognized DP #${
				dp} with data ${JSON.stringify(msg.data)}`);
		}
	},
};


const tz_state = {
	key: ['state'],
	convertSet: async (entity, key, value, meta) => {
		if(value == "OFF") {
			await tuya.sendDataPointBool(entity, 1, false);
		} else if(value == "ON") {
			await tuya.sendDataPointBool(entity, 1, true);
		}
	},
};

const tz_system_mode = {
	key: ['system_mode'],
	convertSet: async (entity, key, value, meta) => {
		if(value == "cool") {
			await tuya.sendDataPointEnum(entity, 2, 0);
		} else if(value == "heat") {
			await tuya.sendDataPointEnum(entity, 2, 1);
		} else if(value == "fan_only") {
			await tuya.sendDataPointEnum(entity, 2, 2);
		}
	},
};

const tz_temperature_setpoint = {
	key: ['occupied_heating_setpoint'],
	convertSet: async (entity, key, value, meta) => {
		await tuya.sendDataPointValue(entity, 16, value);
	},
};

const tz_fan_mode = {
	key: ['fan_mode'],
	convertSet: async (entity, key, value, meta) => {
		if(value == "low") {
			await tuya.sendDataPointEnum(entity, 28, 0);
		} else if(value == "medium") {
			await tuya.sendDataPointEnum(entity, 28, 1);
		} else if(value == "high") {
			await tuya.sendDataPointEnum(entity, 28, 2);			
		} else if(value == "auto") {
			await tuya.sendDataPointEnum(entity, 28, 3);			
		}
	},
};

module.exports = [
    {
        fingerprint: [{modelID: 'TS0601', manufacturerName: '_TZE200_dzuqwsyg'}],
        model: 'BAC-002-ALZB',
        vendor: 'HKGK',
        description: 'BAC series thermostat',
        fromZigbee: [fz_moes_thermostat_custom],
        toZigbee: [tz_state, tz_system_mode, tz_fan_mode, tz_temperature_setpoint, tz.moes_thermostat_child_lock, tz.moes_thermostat_current_heating_setpoint, tz.moes_thermostat_mode,
            tz.hgkg_thermostat_standby, tz.moes_thermostat_sensor, tz.moes_thermostat_calibration,
            tz.moes_thermostat_deadzone_temperature, tz.moes_thermostat_max_temperature_limit],
        exposes: [e.child_lock(), e.deadzone_temperature(), e.max_temperature_limit(),
			exposes.switch()
				.withState('state', false, 'OFF/ON state'),
            exposes.climate()
				.withSetpoint('occupied_heating_setpoint', 16, 35, 1, ea.STATE_SET)
                .withLocalTemperature(ea.STATE)
				.withLocalTemperatureCalibration(ea.STATE_SET)
                .withSystemMode(['cool', 'heat', 'fan_only'], ea.STATE_SET)
				.withFanMode(['low', 'medium', 'high', 'auto'], ea.STATE_SET)
				.withRunningState(['idle', 'heat', 'cool'], ea.STATE)
                .withPreset(['hold', 'program'])
				.withSensor(['IN', 'AL', 'OU'], ea.STATE_SET)],
        onEvent: tuya.onEventSetLocalTime,
    },
];

And use the yaml below for dashboard card. (insert your device's friendly name)

type: grid
square: false
columns: 1
cards:
  - type: entities
    entities:
      - entity: switch.<device friendly name>
    title: Sal AC
  - type: thermostat
    entity: climate.<device friendly name>

dilayn avatar Jul 01 '22 16:07 dilayn

BAC-002-ALZB.js.txt

Use the file above or the code below as converter:

THX MAN!

c0dr1ver avatar Jul 01 '22 17:07 c0dr1ver

I tried to run it, but when zigbee2mqqt start I get this:

[22:16:48] INFO: Preparing to start...
[22:16:48] INFO: Socat not enabled
[22:16:49] INFO: Starting Zigbee2MQTT...
/app/data/extension/externally-loaded.js:182
				.withSensor(['IN', 'AL', 'OU'], ea.STATE_SET)],
				 ^
TypeError: exposes.climate(...).withSetpoint(...).withLocalTemperature(...).withLocalTemperatureCalibration(...).withSystemMode(...).withFanMode(...).withRunningState(...).withPreset(...).withSensor is not a function
    at /app/data/extension/externally-loaded.js:182:6
    at Script.runInContext (node:vm:141:12)
    at Script.runInNewContext (node:vm:146:17)
    at Object.runInNewContext (node:vm:306:38)
    at loadModuleFromText (/app/lib/util/utils.ts:150:8)
    at loadModuleFromFile (/app/lib/util/utils.ts:157:12)
    at Object.getExternalConvertersDefinitions (/app/lib/util/utils.ts:167:25)
    at getExternalConvertersDefinitions.next (<anonymous>)
    at new ExternalConverters (/app/lib/extension/externalConverters.ts:12:20)
    at new Controller (/app/lib/controller.ts:84:58)

Rick5o avatar Mar 14 '23 21:03 Rick5o

Hi all,

@Rick5o i have exactly the same issue on my side... any idea to solve this ?

ghost avatar May 18 '23 09:05 ghost