zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

Add new device "Moes BRT-100_TRV Thermostat TS0601 _TZE200_b6wax7g0"

Open vladi1234 opened this issue 5 years ago • 45 comments

Hello, I'm new here, but I've finished my converter for Moes-BRT-100_TRV thermostat and already tested it, it works. I created "devices.js" file and made changes to "/lib/tuya.js", "fromZigbee.js", "toZigbee.js" and "exposes.js" files. Where should I go with this thermostat supported? How should I add new "Moes BRT-100_TRV _TZE200_b6wax7g0" to the project?

vladi1234 avatar Jun 02 '21 20:06 vladi1234

Moes-BRT-100_TRV_TZE200_b6wax7g0

Bildschirmfoto vom 2021-06-03 12-12-37

Bildschirmfoto vom 2021-06-03 12-56-35

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 tuya = require('zigbee-herdsman-converters/lib/tuya');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
// const extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;

const definition = {
    fingerprint: [
        {
            modelID: 'TS0601',
            manufacturerName: '_TZE200_b6wax7g0',
        },
    ],
    model: 'BRT-100_TRV',
    vendor: 'Moes',
    description: 'Thermostatic Radiator Valve',
    supports: 'thermostat, temperature',
    fromZigbee: [
        fz.ignore_basic_report, fz.ignore_tuya_set_time,
        fz.tuya_data_point_dump,
        fz.moesS_thermostat,
    ],
    toZigbee: [
        tz.tuya_data_point_test, // Another debug converter
        tz.moesS_thermostat_current_heating_setpoint, tz.moesS_thermostat_child_lock,
        tz.moesS_thermostat_window_detection, tz.moesS_thermostat_temperature_calibration,
        tz.moesS_thermostat_temperature_calibration, tz.moesS_thermostat_system_mode,
        tz.moesS_thermostat_boost_heating, tz.moesS_thermostat_boostHeatingCountdownTimeSet,
        tz.moesS_thermostat_eco_temperature, tz.moesS_thermostat_max_temperature, tz.moesS_thermostat_min_temperature,
        tz.moesS_thermostat_schedule, tz.moesS_thermostat_moesSecoMode,
        tz.moesS_thermostat_boost_heating_countdown,
    ],
    onEvent: tuya.onEventSetLocalTime,
    meta: {
        configureKey: 1,
        tuyaThermostatSystemMode: tuya.thermostatSystemModes5,
    },
    configure: async (device, coordinatorEndpoint, logger) => {
        const endpoint = device.getEndpoint(1);
        await reporting.bind(endpoint, coordinatorEndpoint, ['genBasic', 'manuSpecificTuya']);
    },
    exposes: [
        e.battery(), e.child_lock(),
        exposes.climate()
            .withLocalTemperature(ea.STATE).withSetpoint('current_heating_setpoint', 5, 30, 0.5, ea.STATE_SET)
            .withLocalTemperatureCalibration(ea.STATE_SET).withSystemMode(['auto', 'manual', 'temphand', 'holiday'], ea.STATE_SET),
        exposes.text('schedule', ea.STATE).withDescription('MANUAL MODE ☝ - In this mode, the device executes manual temperature setting. '+
            'When the set temperature is lower than the "minimum temperature", the valve is closed (forced closed). ' +
            'PROGRAMMING MODE ⏱ -In this mode, the device executes a preset week programming temperature time and temperature. ' +
            'HOLIDAY MODE ⛱ - In this mode, for example, the vacation mode is set for 10 days and the temperature is set' +
            'to 15 degrees Celsius. After 10 days, the device will automatically switch to programming mode. ' +
            'TEMPORARY MANUAL MODE - In this mode, ☝ icon will flash. At this time, the device executes the manually set temperature' +
            'and returns to the weekly programming mode in the next time period. '),
        exposes.text('boost_heating', ea.STATE).withDescription('Boost Heating: Press and hold "+" for 3 seconds, the device will' +
            'enter the boost heating mode, and the ▷╵◁ will flash. The countdown will be displayed in the APP'),
        exposes.text('boost_heating_countdown', ea.STATE).withDescription('countdown in minutes'),
        e.boost_time( 300, 900, 10, ea.STATE_SET).withUnit('sec'),
        exposes.text('eco_mode', ea.STATE).withDescription('ON/OFF state ECO MODE'), e.eco_temperature(),
        e.max_temperature(), e.min_temperature(), e.window_detection(), e.position(),
        // e.boost_heating(), e.eco_mode(),
    ],
};

module.exports = definition;

vladi1234 avatar Jun 02 '21 20:06 vladi1234

Great your work. As soon as I have seen it I have wanted to try it. I'm sure I must do something wrong because it doesn't work for me, it won't start Zigbee2mqtt (502: Bad Gateway)

image

Thank you

jmarfer avatar Jun 03 '21 13:06 jmarfer

I've managed to start Z2M with a code from @vladi1234 with a little modification:

const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const fz = {...require('zigbee-herdsman-converters/converters/fromZigbee'), legacy: require('zigbee-herdsman-converters/lib/legacy').fromZigbee};
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const e = exposes.presets;
const ea = exposes.access;

module.exports = [
	{
		fingerprint: [
			{
				modelID: 'TS0601',
				manufacturerName: '_TZE200_b6wax7g0',
			},
		],
		model: 'BRT-100_TRV',
		vendor: 'Moes',
		description: 'Thermostatic Radiator Valve',
		supports: 'thermostat, temperature',
		fromZigbee: [
			fz.ignore_basic_report, fz.ignore_tuya_set_time,
			fz.tuya_data_point_dump,
			fz.moesS_thermostat,
		],
		toZigbee: [
			tz.tuya_data_point_test, // Another debug converter
			tz.moesS_thermostat_current_heating_setpoint, tz.moesS_thermostat_child_lock,
			tz.moesS_thermostat_window_detection, tz.moesS_thermostat_temperature_calibration,
			tz.moesS_thermostat_temperature_calibration, tz.moesS_thermostat_system_mode,
			tz.moesS_thermostat_boost_heating, tz.moesS_thermostat_boostHeatingCountdownTimeSet,
			tz.moesS_thermostat_eco_temperature, tz.moesS_thermostat_max_temperature, tz.moesS_thermostat_min_temperature,
			tz.moesS_thermostat_schedule, tz.moesS_thermostat_moesSecoMode,
			tz.moesS_thermostat_boost_heating_countdown,
		],
		onEvent: tuya.onEventSetLocalTime,
		meta: {
			configureKey: 1,
			tuyaThermostatSystemMode: tuya.thermostatSystemModes5,
		},
		configure: async (device, coordinatorEndpoint, logger) => {
			const endpoint = device.getEndpoint(1);
			await reporting.bind(endpoint, coordinatorEndpoint, ['genBasic', 'manuSpecificTuya']);
		},
		exposes: [
			e.battery(), e.child_lock(),
			exposes.climate()
				.withLocalTemperature(ea.STATE).withSetpoint('current_heating_setpoint', 5, 30, 0.5, ea.STATE_SET)
				.withLocalTemperatureCalibration(ea.STATE_SET).withSystemMode(['auto', 'heat', 'off'], ea.STATE_SET),
			exposes.text('schedule', ea.STATE).withDescription('MANUAL MODE ☝ - In this mode, the device executes manual temperature setting. ' +
				'When the set temperature is lower than the "minimum temperature", the valve is closed (forced closed). ' +
				'PROGRAMMING MODE ⏱ -In this mode, the device executes a preset week programming temperature time and temperature. ' +
				'HOLIDAY MODE ⛱ - In this mode, for example, the vacation mode is set for 10 days and the temperature is set' +
				'to 15 degrees Celsius. After 10 days, the device will automatically switch to programming mode. ' +
				'TEMPORARY MANUAL MODE - In this mode, ☝ icon will flash. At this time, the device executes the manually set temperature' +
				'and returns to the weekly programming mode in the next time period. '),
			exposes.text('boost_heating', ea.STATE).withDescription('Boost Heating: Press and hold "+" for 3 seconds, the device will' +
				'enter the boost heating mode, and the ▷╵◁ will flash. The countdown will be displayed in the APP'),
			exposes.text('boost_heating_countdown', ea.STATE).withDescription('countdown in minutes'),
			e.boost_time(300, 900, 10, ea.STATE_SET).withUnit('sec'),
			exposes.text('eco_mode', ea.STATE).withDescription('ON/OFF state ECO MODE'), e.eco_temperature(),
			e.max_temperature(), e.min_temperature(), e.window_detection(), e.position(),
			// e.boost_heating(), e.eco_mode(),
		],
	}];

but I've got a lot of errors:

zigbee2mqtt_1    | Zigbee2MQTT:error 2021-06-03 15:40:04: Failed to call 'Receive' 'onZigbeeEvent' (TypeError: Cannot read property 'type' of undefined
zigbee2mqtt_1    |     at /app/lib/extension/receive.js:117:42
zigbee2mqtt_1    |     at Array.filter (<anonymous>)
zigbee2mqtt_1    |     at Receive.onZigbeeEvent (/app/lib/extension/receive.js:116:65)
zigbee2mqtt_1    |     at Controller.callExtensionMethod (/app/lib/controller.js:386:44))

wizu avatar Jun 03 '21 13:06 wizu

You still have to make changes in the four files "/lib/tuya.js", "fromZigbee.js", "toZigbee.js" and "exposes.js", and insert additional code.

vladi1234 avatar Jun 03 '21 16:06 vladi1234

I apologize, I forgot the top line when copying / pasting.

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');

vladi1234 avatar Jun 03 '21 18:06 vladi1234

Great, I'm going to try right now and comment

jmarfer avatar Jun 03 '21 18:06 jmarfer

I have already corrected.

vladi1234 avatar Jun 03 '21 18:06 vladi1234

Now it works. When changing some parameter of settings, this error appears:

Error Failed to call 'EntityPublish' 'onMQTTMessage' (TypeError: Cannot read property 'key' of undefined at /app/lib/extension/publish.js:185:56 at Array.find () at EntityPublish.onMQTTMessage (/app/lib/extension/publish.js:185:42) at Controller.callExtensionMethod (/app/lib/controller.js:380:44) at processTicksAndRejections (internal/process/task_queues.js:93:5))

jmarfer avatar Jun 03 '21 18:06 jmarfer

You still have to make changes in the four files "/lib/tuya.js", "fromZigbee.js", "toZigbee.js" and "exposes.js", and insert additional code.

vladi1234 avatar Jun 03 '21 18:06 vladi1234


add to node_modules/zigbee-herdsman-converters/lib/tuya.js

    // MoesS Thermostat
    moesSsystemMode: 1,
    moesSheatingSetpoint: 2,
    moesSlocalTemp: 3,
    moesSboostHeating: 4,
    moesSboostHeatingCountdown: 5,
    moesSreset: 7,
    moesSwindowDetectionFunktion_A2: 8,
    moesSwindowDetection: 9,
    moesSchildLock: 13,
    moesSbattery: 14,
    moesSschedule: 101,
    moesSvalvePosition: 104,
    moesSboostHeatingCountdownTimeSet: 103,
    moesScompensationTempSet: 105,
    moesSecoMode: 106,
    moesSecoModeTempSet: 107,
    moesSmaxTempSet: 108,
    moesSminTempSet: 109,

add to node_modules/zigbee-herdsman-converters/converters/fromZigbee.js

   // ############################## fromZigbee.js moesS #######################################
    moesS_thermostat: {
        cluster: 'manuSpecificTuya',
        type: ['commandGetData', 'commandSetDataResponse'],
        convert: (model, msg, publish, options, meta) => {
            const dp = msg.data.dp; // First we get the data point ID
            const value = tuya.getDataValue(msg.data.datatype, msg.data.data);
            switch (dp) {
            case tuya.dataPoints.moesSsystemMode:
                switch (value) {
                case 0:
                    return {system_mode: 'auto'};
                case 1:
                    return {system_mode: 'manual'};
                case 2:
                    return {system_mode: 'temphand'};
                case 3:
                    return {system_mode: 'holiday'};
                }
                break;
            case tuya.dataPoints.moesSheatingSetpoint:
                // return {current_heating_setpoint: (value / 10).toFixed(1)};
                return {current_heating_setpoint: value};

            case tuya.dataPoints.moesSlocalTemp:
                return {local_temperature: (value / 10)};

            case tuya.dataPoints.moesSboostHeating:
                return {boost_heating: value ? 'ON' : 'OFF'};

            case tuya.dataPoints.moesSboostHeatingCountdown:
                return {boost_heating_countdown: value};

            case tuya.dataPoints.moesSreset:
                break;

            case tuya.dataPoints.moesSwindowDetectionFunktion_A2:
                return {window_detection: value ? 'ON' : 'OFF'};

            case tuya.dataPoints.moesSwindowDetection:
                return {window_detection: value ? 'ON' : 'OFF'};

            case tuya.dataPoints.moesSchildLock:
                return {child_lock: value ? 'LOCK' : 'UNLOCK'};
                // return {lock: value ? 'LOCK' : 'UNLOCK'};

            case tuya.dataPoints.moesSbattery:
                // return {battery: (value).toFixed(1)}; // 00,0%
                return {battery: value};

                // if (value === 0 - 100){
                //  return {battery_low: true };
                //  payload.battery_low = true;
                // }
                // return payload;

                // if (value !== 10 - 100){
                // return {battery_low: 0 };
                // return {battery_low: (value = 0).toFixed(1)};
                // const    msg.data.batteray === 0 - 100 ;

            case tuya.dataPoints.moesSschedule:
                return {
                    schedule: {
                        weekday: ' ' + value[0] + 'h:' + value[1] + 'm ' + value[2]/2 + '°C' +
                                ',  ' + value[3] + 'h:' + value[4] + 'm ' + value[5]/2 + '°C' +
                                ',  ' + value[6] + 'h:' + value[7] + 'm ' + value[8]/2 + '°C' +
                                ',  ' + value[9] + 'h:' + value[10] + 'm ' + value[11]/2 + '°C ',
                        saturday: '' + value[12] + 'h:' + value[13] + 'm ' + value[14]/2 + '°C' +
                                ',  ' + value[15] + 'h:' + value[16] + 'm ' + value[17]/2 + '°C' +
                                ',   ' + value[18] + 'h:' + value[19] + 'm ' + value[20]/2 + '°C' +
                                ',  ' + value[21] + 'h:' + value[22] + 'm ' + value[23]/2 + '°C ',
                        sunday: '  ' + value[24] + 'h:' + value[25] + 'm ' + value[26]/2 + '°C' +
                                ',  ' + value[27] + 'h:' + value[28] + 'm ' + value[29]/2 + '°C' +
                                ',  ' + value[30] + 'h:' + value[31] + 'm ' + value[32]/2 + '°C' +
                                ',  ' + value[33] + 'h:' + value[34] + 'm ' + value[35]/2 + '°C ',
                    },
                };

            case tuya.dataPoints.moesSboostHeatingCountdownTimeSet:
                return {boost_time: (value)};

            case tuya.dataPoints.moesSvalvePosition:
                return {position: value};

            case tuya.dataPoints.moesScompensationTempSet:
                return {local_temperature_calibration: value};

            case tuya.dataPoints.moesSecoMode:
                return {eco_mode: value ? 'ON' : 'OFF'};

            case tuya.dataPoints.moesSecoModeTempSet:
                return {eco_temperature: value};

            case tuya.dataPoints.moesSmaxTempSet:
                return {max_temperature: value};

            case tuya.dataPoints.moesSminTempSet:
                return {min_temperature: value};

            default:
                meta.logger.warn(`zigbee-herdsman-converters:moesS_thermostat: NOT RECOGNIZED DP #${
                    dp} with data ${JSON.stringify(msg.data)}`);
            }
        },
    },
    // ########################### fromZigbee.js ende moesS #########################################

add to node_modules/zigbee-herdsman-converters/converters/toZigbee.js

    // ############################### toZigbee.js moesS ############################################
    // moesSsystemMode: 1,
    moesS_thermostat_system_mode: {
        key: ['system_mode'],
        convertSet: async (entity, key, value, meta) => {
            await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSsystemMode, value);
            switch (value) {
            case 'auto':
                // return {system_mode: 'auto'};
                await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 0 /* auto */);
                break;
            case 'manual':
                await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 1 /* manual */);
                break;
            case 'temphand':
                await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 2 /* temphand */);
                break;
            case 'holiday':
                await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 3 /* holiday */);
                break;
            }
        },
    },
    // moesSheatingSetpoint: 2,
    moesS_thermostat_current_heating_setpoint: {
        key: ['current_heating_setpoint'],
        convertSet: async (entity, key, value, meta) => {
            // const temp = Math.round(value * 10);
            await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSheatingSetpoint, value);
        },
    },
    // moesSboostHeating: 4,
    moesS_thermostat_boost_heating: {
        key: ['boost_heating'],
        convertSet: async (entity, key, value, meta) => {
            // await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value);
            // await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value === 'LOCK');
            await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSboostHeating, value === 'OFF');
        },
    },
    // moesSboostHeatingCountdown: 5,
    moesS_thermostat_boost_heating_countdown: {
        key: ['boost_heating_countdown'],
        convertSet: async (entity, key, value, meta) => {
            // const temp = Math.round(value * 10);
            await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSboostHeatingCountdown, value);
        },
    },
    // moesSwindowDetection: 9,
    moesS_thermostat_window_detection: {
        key: ['window_detection'],
        convertSet: async (entity, key, value, meta) => {
            await tuya.sendDataPointRaw(entity, tuya.dataPoints.moesSwindowDetection, [value === 'ON' ? 1 : 0]);
        },
    },
    // moesSchildLock: 13,
    moesS_thermostat_child_lock: {
        key: ['child_lock'],
        convertSet: async (entity, key, value, meta) => {
            // await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value);
            // await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value === 'LOCK');
            await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value === 'LOCK');
        },
    },
    // moesSboostHeatingCountdownTimeSet: 103,
    moesS_thermostat_boostHeatingCountdownTimeSet: {
        key: ['boost_time'],
        convertSet: async (entity, key, value, meta) => {
            // const temp = Math.round(value * 10);
            await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSboostHeatingCountdownTimeSet, value);
        },
    },
    // moesScompensationTempSet: 105,
    moesS_thermostat_temperature_calibration: {
        key: ['local_temperature_calibration'],
        convertSet: async (entity, key, value, meta) => {
            let temp = Math.round(value * 1);
            if (temp < 0) {
                temp = 0xFFFFFFFF + temp + 1;
            }
            await tuya.sendDataPointValue(entity, tuya.dataPoints.moesScompensationTempSet, temp);
        },
    },
    // moesSecoMode: 106,
    moesS_thermostat_moesSecoMode: {
        key: ['eco_mode'],
        convertSet: async (entity, key, value, meta) => {
            // await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSwindowDetection,[value === 'ON' ? 1 : 0]);
            // await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSecoMode, value);
            // await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSecoMode, value === 'LOCK');
            await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSecoMode, value === 'OFF');
        },
    },
    // moesSecoModeTempSet: 107,
    moesS_thermostat_eco_temperature: {
        key: ['eco_temperature'],
        convertSet: async (entity, key, value, meta) => {
            // const temp = Math.round(value * 10);
            await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSecoModeTempSet, value);
        },
    },
    // moesSmaxTempSet: 108,
    moesS_thermostat_max_temperature: {
        key: ['max_temperature'],
        convertSet: async (entity, key, value, meta) => {
            // const temp = Math.round(value * 10);
            await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSmaxTempSet, value);
        },
    },
    // moesSminTempSet: 109,
    moesS_thermostat_min_temperature: {
        key: ['min_temperature'],
        convertSet: async (entity, key, value, meta) => {
            // const temp = Math.round(value * 10);
            await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSminTempSet, value);
        },
    },
    // ########################### toZigbee.js ende moesS #########################################

add to node_modules/zigbee-herdsman-converters/converters/lib/exposes.js

Insert 'manual', 'temphand', 'holiday' as shown below.

    withSystemMode(modes, access=a.ALL) {
        assert(!this.endpoint, 'Cannot add feature after adding endpoint');
        const allowed = ['off', 'heat', 'cool', 'auto', 'dry', 'fan_only', 'sleep', 'manual', 'temphand', 'holiday'];
        modes.forEach((m) => assert(allowed.includes(m)));
        this.features.push(new Enum('system_mode', access, modes).withDescription('Mode of this device'));
        return this;
    }

vladi1234 avatar Jun 03 '21 18:06 vladi1234

Sorry but I don't understand very well. I don't have those four files to modify. Do I have to create them? "/lib/tuya.js", "fromZigbee.js", "toZigbee.js" and "exposes.js"

jmarfer avatar Jun 03 '21 18:06 jmarfer

These four files are already there. You have to insert a piece of code, as I described above.

vladi1234 avatar Jun 03 '21 18:06 vladi1234

https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html

vladi1234 avatar Jun 03 '21 18:06 vladi1234

@vladi1234 try to make pull request to: https://github.com/Koenkk/zigbee-herdsman-converters https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request

https://www.google.com/search?q=github+how+to+make+pull+request&oq=github+how+to+mak&aqs=chrome.1.0l2j69i57j0i22i30l7.3239j0j7&sourceid=chrome&ie=UTF-8

wizu avatar Jun 03 '21 18:06 wizu

Nothing, this is too complex for me, I am not able to get it.

I will buy one of the compatible valves that link by default.

Thank you very much for your patience and work

jmarfer avatar Jun 03 '21 18:06 jmarfer

@vladi1234 try to make pull request to: https://github.com/Koenkk/zigbee-herdsman-converters https://docs.github.com/en/github/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request

https://www.google.com/search?q=github+how+to+make+pull+request&oq=github+how+to+mak&aqs=chrome.1.0l2j69i57j0i22i30l7.3239j0j7&sourceid=chrome&ie=UTF-8

Thanks for recommendation. I have to take more time to do right.

vladi1234 avatar Jun 03 '21 19:06 vladi1234

@vladi1234 if you use zigbee2mqtt hassio addon you don't have these files: "/lib/tuya.js", "fromZigbee.js", "toZigbee.js" and "exposes.js"

yarosman avatar Jun 03 '21 20:06 yarosman

I am not using the hassio addon. I favor zigbee2mqtt, Domoticz and Node-red.

vladi1234 avatar Jun 03 '21 20:06 vladi1234

so hard to be able to do it for me

jmarfer avatar Jun 03 '21 21:06 jmarfer

@vladi1234 windows detection seems not to work. I can't wait for you pull request and when it will be merged and this thermostat will work out of the box ;)

@jmarfer single file version:

const tuyaDataPoints = {
	moesSsystemMode: 1,
	moesSheatingSetpoint: 2,
	moesSlocalTemp: 3,
	moesSboostHeating: 4,
	moesSboostHeatingCountdown: 5,
	moesSreset: 7,
	moesSwindowDetectionFunktion_A2: 8,
	moesSwindowDetection: 9,
	moesSchildLock: 13,
	moesSbattery: 14,
	moesSschedule: 101,
	moesSvalvePosition: 104,
	moesSboostHeatingCountdownTimeSet: 103,
	moesScompensationTempSet: 105,
	moesSecoMode: 106,
	moesSecoModeTempSet: 107,
	moesSmaxTempSet: 108,
	moesSminTempSet: 109,
};

const tuya = {...require('zigbee-herdsman-converters/lib/tuya')};
tuya.dataPoints = {...tuya.dataPoints, ...tuyaDataPoints}

const fzExt = {
	moesS_thermostat: {
		cluster: 'manuSpecificTuya',
		type: ['commandGetData', 'commandSetDataResponse'],
		convert: (model, msg, publish, options, meta) => {
			const dp = msg.data.dp; // First we get the data point ID
			const value = tuya.getDataValue(msg.data.datatype, msg.data.data);
			switch (dp) {
				case tuya.dataPoints.moesSsystemMode:
					switch (value) {
						case 0:
							return {system_mode: 'auto'};
						case 1:
							return {system_mode: 'manual'};
						case 2:
							return {system_mode: 'temphand'};
						case 3:
							return {system_mode: 'holiday'};
					}
					break;
				case tuya.dataPoints.moesSheatingSetpoint:
					// return {current_heating_setpoint: (value / 10).toFixed(1)};
					return {current_heating_setpoint: value};

				case tuya.dataPoints.moesSlocalTemp:
					return {local_temperature: (value / 10)};

				case tuya.dataPoints.moesSboostHeating:
					return {boost_heating: value ? 'ON' : 'OFF'};

				case tuya.dataPoints.moesSboostHeatingCountdown:
					return {boost_heating_countdown: value};

				case tuya.dataPoints.moesSreset:
					break;

				case tuya.dataPoints.moesSwindowDetectionFunktion_A2:
					return {window_detection: value ? 'ON' : 'OFF'};

				case tuya.dataPoints.moesSwindowDetection:
					return {window_detection: value ? 'ON' : 'OFF'};

				case tuya.dataPoints.moesSchildLock:
					return {child_lock: value ? 'LOCK' : 'UNLOCK'};
				// return {lock: value ? 'LOCK' : 'UNLOCK'};

				case tuya.dataPoints.moesSbattery:
					// return {battery: (value).toFixed(1)}; // 00,0%
					return {battery: value};

				// if (value === 0 - 100){
				//  return {battery_low: true };
				//  payload.battery_low = true;
				// }
				// return payload;

				// if (value !== 10 - 100){
				// return {battery_low: 0 };
				// return {battery_low: (value = 0).toFixed(1)};
				// const    msg.data.batteray === 0 - 100 ;

				case tuya.dataPoints.moesSschedule:
					return {
						schedule: {
							weekday: ' ' + value[0] + 'h:' + value[1] + 'm ' + value[2] / 2 + '°C' +
								',  ' + value[3] + 'h:' + value[4] + 'm ' + value[5] / 2 + '°C' +
								',  ' + value[6] + 'h:' + value[7] + 'm ' + value[8] / 2 + '°C' +
								',  ' + value[9] + 'h:' + value[10] + 'm ' + value[11] / 2 + '°C ',
							saturday: '' + value[12] + 'h:' + value[13] + 'm ' + value[14] / 2 + '°C' +
								',  ' + value[15] + 'h:' + value[16] + 'm ' + value[17] / 2 + '°C' +
								',   ' + value[18] + 'h:' + value[19] + 'm ' + value[20] / 2 + '°C' +
								',  ' + value[21] + 'h:' + value[22] + 'm ' + value[23] / 2 + '°C ',
							sunday: '  ' + value[24] + 'h:' + value[25] + 'm ' + value[26] / 2 + '°C' +
								',  ' + value[27] + 'h:' + value[28] + 'm ' + value[29] / 2 + '°C' +
								',  ' + value[30] + 'h:' + value[31] + 'm ' + value[32] / 2 + '°C' +
								',  ' + value[33] + 'h:' + value[34] + 'm ' + value[35] / 2 + '°C ',
						},
					};

				case tuya.dataPoints.moesSboostHeatingCountdownTimeSet:
					return {boost_time: (value)};

				case tuya.dataPoints.moesSvalvePosition:
					return {position: value};

				case tuya.dataPoints.moesScompensationTempSet:
					return {local_temperature_calibration: value};

				case tuya.dataPoints.moesSecoMode:
					return {eco_mode: value ? 'ON' : 'OFF'};

				case tuya.dataPoints.moesSecoModeTempSet:
					return {eco_temperature: value};

				case tuya.dataPoints.moesSmaxTempSet:
					return {max_temperature: value};

				case tuya.dataPoints.moesSminTempSet:
					return {min_temperature: value};

				default:
					meta.logger.warn(`zigbee-herdsman-converters:moesS_thermostat: NOT RECOGNIZED DP #${
						dp} with data ${JSON.stringify(msg.data)}`);
			}
		},
	},
};

const tzExt = {
	moesS_thermostat_system_mode: {
		key: ['system_mode'],
		convertSet: async (entity, key, value, meta) => {
			await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSsystemMode, value);
			switch (value) {
				case 'auto':
					// return {system_mode: 'auto'};
					await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 0 /* auto */);
					break;
				case 'manual':
					await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 1 /* manual */);
					break;
				case 'temphand':
					await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 2 /* temphand */);
					break;
				case 'holiday':
					await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSsystemMode, 3 /* holiday */);
					break;
			}
		},
	},
	// moesSheatingSetpoint: 2,
	moesS_thermostat_current_heating_setpoint: {
		key: ['current_heating_setpoint'],
		convertSet: async (entity, key, value, meta) => {
			// const temp = Math.round(value * 10);
			await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSheatingSetpoint, value);
		},
	},
	// moesSboostHeating: 4,
	moesS_thermostat_boost_heating: {
		key: ['boost_heating'],
		convertSet: async (entity, key, value, meta) => {
			// await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value);
			// await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value === 'LOCK');
			await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSboostHeating, value === 'OFF');
		},
	},
	// moesSboostHeatingCountdown: 5,
	moesS_thermostat_boost_heating_countdown: {
		key: ['boost_heating_countdown'],
		convertSet: async (entity, key, value, meta) => {
			// const temp = Math.round(value * 10);
			await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSboostHeatingCountdown, value);
		},
	},
	// moesSwindowDetection: 9,
	moesS_thermostat_window_detection: {
		key: ['window_detection'],
		convertSet: async (entity, key, value, meta) => {
			await tuya.sendDataPointRaw(entity, tuya.dataPoints.moesSwindowDetection, [value === 'ON' ? 1 : 0]);
		},
	},
	// moesSchildLock: 13,
	moesS_thermostat_child_lock: {
		key: ['child_lock'],
		convertSet: async (entity, key, value, meta) => {
			// await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value);
			// await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value === 'LOCK');
			await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSchildLock, value === 'LOCK');
		},
	},
	// moesSboostHeatingCountdownTimeSet: 103,
	moesS_thermostat_boostHeatingCountdownTimeSet: {
		key: ['boost_time'],
		convertSet: async (entity, key, value, meta) => {
			// const temp = Math.round(value * 10);
			await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSboostHeatingCountdownTimeSet, value);
		},
	},
	// moesScompensationTempSet: 105,
	moesS_thermostat_temperature_calibration: {
		key: ['local_temperature_calibration'],
		convertSet: async (entity, key, value, meta) => {
			let temp = Math.round(value * 1);
			if (temp < 0) {
				temp = 0xFFFFFFFF + temp + 1;
			}
			await tuya.sendDataPointValue(entity, tuya.dataPoints.moesScompensationTempSet, temp);
		},
	},
	// moesSecoMode: 106,
	moesS_thermostat_moesSecoMode: {
		key: ['eco_mode'],
		convertSet: async (entity, key, value, meta) => {
			// await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSwindowDetection,[value === 'ON' ? 1 : 0]);
			// await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSecoMode, value);
			// await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSecoMode, value === 'LOCK');
			await tuya.sendDataPointBool(entity, tuya.dataPoints.moesSecoMode, value === 'OFF');
		},
	},
	// moesSecoModeTempSet: 107,
	moesS_thermostat_eco_temperature: {
		key: ['eco_temperature'],
		convertSet: async (entity, key, value, meta) => {
			// const temp = Math.round(value * 10);
			await tuya.sendDataPointEnum(entity, tuya.dataPoints.moesSecoModeTempSet, value);
		},
	},
	// moesSmaxTempSet: 108,
	moesS_thermostat_max_temperature: {
		key: ['max_temperature'],
		convertSet: async (entity, key, value, meta) => {
			// const temp = Math.round(value * 10);
			await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSmaxTempSet, value);
		},
	},
	// moesSminTempSet: 109,
	moesS_thermostat_min_temperature: {
		key: ['min_temperature'],
		convertSet: async (entity, key, value, meta) => {
			// const temp = Math.round(value * 10);
			await tuya.sendDataPointValue(entity, tuya.dataPoints.moesSminTempSet, value);
		},
	},
};

const tz = {...require('zigbee-herdsman-converters/converters/toZigbee'), ...tzExt};
const fz = {
	...require('zigbee-herdsman-converters/converters/fromZigbee'), ...fzExt,
	legacy: require('zigbee-herdsman-converters/lib/legacy').fromZigbee
};
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const e = exposes.presets;
const ea = exposes.access;

const climate = exposes.climate();

climate.withSystemMode = (modes, access=ea.ALL) => {
	climate.features.push(exposes.enum('system_mode', access, modes).withDescription('Mode of this device'));
	return climate;
};

const reporting = require('zigbee-herdsman-converters/lib/reporting');


module.exports = [
	{
		fingerprint: [
			{
				modelID: 'TS0601',
				manufacturerName: '_TZE200_b6wax7g0',
			},
		],
		model: 'BRT-100_TRV',
		vendor: 'Moes',
		description: 'Thermostatic Radiator Valve',
		supports: 'thermostat, temperature',
		fromZigbee: [
			fz.ignore_basic_report, fz.ignore_tuya_set_time,
			fz.tuya_data_point_dump,
			fz.moesS_thermostat,
		],
		toZigbee: [
			tz.tuya_data_point_test, // Another debug converter
			tz.moesS_thermostat_current_heating_setpoint, tz.moesS_thermostat_child_lock,
			tz.moesS_thermostat_window_detection, tz.moesS_thermostat_temperature_calibration,
			tz.moesS_thermostat_temperature_calibration, tz.moesS_thermostat_system_mode,
			tz.moesS_thermostat_boost_heating, tz.moesS_thermostat_boostHeatingCountdownTimeSet,
			tz.moesS_thermostat_eco_temperature, tz.moesS_thermostat_max_temperature, tz.moesS_thermostat_min_temperature,
			tz.moesS_thermostat_schedule, tz.moesS_thermostat_moesSecoMode,
			tz.moesS_thermostat_boost_heating_countdown,
		],
		onEvent: tuya.onEventSetLocalTime,
		meta: {
			configureKey: 1,
			tuyaThermostatSystemMode: tuya.thermostatSystemModes5,
		},
		configure: async (device, coordinatorEndpoint, logger) => {
			const endpoint = device.getEndpoint(1);
			await reporting.bind(endpoint, coordinatorEndpoint, ['genBasic', 'manuSpecificTuya']);
		},
		exposes: [
			e.battery(), e.child_lock(),
			climate
				.withLocalTemperature(ea.STATE).withSetpoint('current_heating_setpoint', 5, 30, 0.5, ea.STATE_SET)
				.withLocalTemperatureCalibration(ea.STATE_SET).withSystemMode(['auto', 'manual', 'temphand', 'holiday'], ea.STATE_SET),
			exposes.text('schedule', ea.STATE).withDescription('MANUAL MODE ☝ - In this mode, the device executes manual temperature setting. ' +
				'When the set temperature is lower than the "minimum temperature", the valve is closed (forced closed). ' +
				'PROGRAMMING MODE ⏱ -In this mode, the device executes a preset week programming temperature time and temperature. ' +
				'HOLIDAY MODE ⛱ - In this mode, for example, the vacation mode is set for 10 days and the temperature is set' +
				'to 15 degrees Celsius. After 10 days, the device will automatically switch to programming mode. ' +
				'TEMPORARY MANUAL MODE - In this mode, ☝ icon will flash. At this time, the device executes the manually set temperature' +
				'and returns to the weekly programming mode in the next time period. '),
			exposes.text('boost_heating', ea.STATE).withDescription('Boost Heating: Press and hold "+" for 3 seconds, the device will' +
				'enter the boost heating mode, and the ▷╵◁ will flash. The countdown will be displayed in the APP'),
			exposes.text('boost_heating_countdown', ea.STATE).withDescription('countdown in minutes'),
			e.boost_time(300, 900, 10, ea.STATE_SET).withUnit('sec'),
			exposes.text('eco_mode', ea.STATE).withDescription('ON/OFF state ECO MODE'), e.eco_temperature(),
			e.max_temperature(), e.min_temperature(), e.window_detection(), e.position(),
			// e.boost_heating(), e.eco_mode(),
		],
	}];

wizu avatar Jun 04 '21 08:06 wizu