Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tuya.ts to correct presence sensor ZY-M100-24G #6959

Merged
merged 11 commits into from
Jan 28, 2024
Merged

Update tuya.ts to correct presence sensor ZY-M100-24G #6959

merged 11 commits into from
Jan 28, 2024

Conversation

juan11perez
Copy link
Contributor

e.numeric('fading_time', ea.STATE_SET).withValueMin(1).withValueMax(1500).withValueStep(1).withDescription('Delay time').withUnit('s'),
e.numeric('presence_sensitivity', ea.STATE_SET).withValueMin(1).withValueMax(10).withValueStep(1).withDescription('Presence sensitivity'),
],
exposes.enum('state', ea.STATE, ['none', 'presence', 'move'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you fix the build? e.g. exposes.enum should be e.enum

@juan11perez
Copy link
Contributor Author

@Koenkk
Thank you for your guidance. It's finally passed !
As you'll see from the commit history, I'm as they say 'flying by the seat of may pants', nevertheless after several attempts seems done.
Nevertheless I'd appreciate it if you could take a look at the custom converter below. I tried to follow the examples in your repo and believe its correct, but i'm not sure.

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

const dataTypes = {
	raw: 0, // [ bytes ]
	bool: 1, // [0/1]
	number: 2, // [ 4 byte value ]
	string: 3, // [ N byte string ]
	enum: 4, // [ 0-255 ]
	bitmap: 5, // [ 1,2,4 bytes ] as bits
};

const dpMap = {
	dpPresenceState: 112,
	dpState: 105,
	dpMoveSensitivity: 106,
	dpPresenceSensitivity: 111,
	dpTimeout: 110,
	dpDistance: 109,
	dpRange: 107,
	dpIlluminanceLux: 104,

};
const fzLocal = {
	cluster: 'manuSpecificTuya',
	type: ['commandDataResponse', 'commandDataReport'],
	convert: (model, msg, publish, options, meta) => {
		const dp = msg.data.dpValues[0].dp;
		const data = msg.data;
		const value = legacy.getDataValue(data.dpValues[0]);
		const result = {};

		switch (dp) {
			case dpMap.dpPresenceState:
				result.presence = value ? true : false;
				break;
			case dpMap.dpMoveSensitivity:
				result.move_sensitivity = (value / 10);
				break;
			case dpMap.dpPresenceSensitivity:
				result.presence_sensitivity = (value / 10);
				break;
			case dpMap.dpRange:
				result.radar_range = (value / 100);
				break;
			case dpMap.dpDistance:
				result.distance = (value / 100);
				break;
			case dpMap.dpTimeout:
				result.presence_timeout = (value);
				break;
			case dpMap.dpIlluminanceLux:
				result.illuminance_lux = (value);
				break;

			case dpMap.dpState:
				result.state = {
					0: 'none',
					1: 'presence',
					2: 'move'
				} [value];
				break;

				// meta.logger.debug(
				// 	`未解析的数据DP: ${dp} DATA: ${JSON.stringify(msg.data)}`
				// );

		}
		return result;
	},
}
const tzLocal = {
	key: [
		'move_sensitivity',
		'presence_sensitivity',
		'radar_range',
		'presence_timeout',

	],
	convertSet: async (entity, key, value, meta) => {

		switch (key) {
			case 'move_sensitivity':
				await legacy.sendDataPointValue(entity, dpMap.dpMoveSensitivity, value);
				break;
			case 'presence_sensitivity':
				await legacy.sendDataPointValue(entity, dpMap.dpPresenceSensitivity, value);
				break;
			case 'radar_range':
				await legacy.sendDataPointValue(entity, dpMap.dpRange, value * 100);
				break;
			case 'presence_timeout':
				await legacy.sendDataPointValue(entity, dpMap.dpTimeout, value);
				break;

		}
		return {
			key: value
		};
	},

}

module.exports = [{
	fingerprint: [{
		modelID: 'TS0601',
		manufacturerName: '_TZE204_ijxvkhd0',
	}],
	model: 'ZY-M100-24G',
	vendor: 'TuYa',
	description: 'Micro Motion Sensor v1.2',
	fromZigbee: [fzLocal],
	toZigbee: [tzLocal],
	onEvent: legacy.onEventSetLocalTime,
	exposes: [
		exposes.enum('state', ea.STATE, ['none', 'presence', 'move'])
		.withDescription(''),
		e.presence().withDescription(''),
		exposes.numeric('distance', ea.STATE)
		.withDescription(''),
		e.illuminance_lux(),
		exposes.numeric('move_sensitivity', ea.STATE_SET).withValueMin(1)
		.withValueMax(10)
		.withValueStep(1)
		.withDescription(''),
		exposes.numeric('presence_sensitivity', ea.STATE_SET).withValueMin(1)
		.withValueMax(10)
		.withValueStep(1)
		.withDescription(''),
		exposes.numeric('radar_range', ea.STATE_SET).withValueMin(1.5)
		.withValueMax(5.5)
		.withValueStep(1)
		.withUnit('m').withDescription(''),
		exposes.numeric('presence_timeout', ea.STATE_SET).withValueMin(1)
		.withValueMax(1500)
		.withValueStep(1)
		.withUnit('s').withDescription(''),
	],
	meta: {
		multiEndpoint: true,
		tuyaDatapoints: [
			[112, 'presence', tuya.valueConverter.trueFalse1],
			[106, 'move_sensitivity', tuya.valueConverter.divideBy10],
			[111, 'presence_sensitivity', tuya.valueConverter.divideBy10],
			[107, 'radar_range', tuya.valueConverter.divideBy100],
			[109, 'distance', tuya.valueConverter.divideBy100],
			[110, 'presence_timeout', tuya.valueConverter.raw],
			[104, 'illuminance_lux', tuya.valueConverter.raw],
			[105, 'state', tuya.valueConverterBasic.lookup({
				'none': 0,
				'presence': 1,
				'move': 2
			})],

		],
	},

}, ];

e.numeric('move_sensitivity', ea.STATE_SET).withValueMin(1)
.withValueMax(10)
.withValueStep(1)
.withDescription(''),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this initially, but could you add descriptions to all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Koenkk
done

@Koenkk Koenkk merged commit f1ee1b9 into Koenkk:master Jan 28, 2024
2 checks passed
@Koenkk
Copy link
Owner

Koenkk commented Jan 28, 2024

Thanks!

@DuncanRae
Copy link

DuncanRae commented Feb 5, 2024

Hi,

This latest update seems to have broken the ZY-M100-24G devices. They are working as far as detecting presence, but I am unable to change any settings relating to sensitivity, timeout etc. since the most recent update.

For some values it looks like it changed correctly but goes back to the previous value when you refresh the page, and some, (like Presence Timeout aka Fading Time) give this error:

No converter available for 'presence_timeout' (11)

Presence Sensitivity is the other value that can't be changed, but doesn't give an error. I see both of these were changed in the messages above.

Not sure if this is the right place to report this. Happy to post if elsewhere if more appropriate.

Also spotted a spelling mistake here:

e.presence().withDescription('Ocuppancy'),

Thanks for the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants