Use code below, save this to a new file on your local zigbee2mqtt folder and name it testwarning.js
In your zigbee2mqtt configuration, add this local converter to your config:
external_converters:
- testwarning.js
devices: devices.yaml
Here’s the code for the local converter:
const fz = {...require('zigbee-herdsman-converters/converters/fromZigbee'), legacy: require('zigbee-herdsman-converters/lib/legacy').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 constants = require('zigbee-herdsman-converters/lib/constants');
const utils = require('zigbee-herdsman-converters/lib/utils');
const e = exposes.presets;
const ea = exposes.access;
const tzLocal = {
warning: {
key: ['warning'],
convertSet: async (entity, key, value, meta) => {
const mode = {'stop': 0, 'burglar': 1, 'fire': 2, 'emergency': 3, 'police_panic': 4, 'fire_panic': 5, 'emergency_panic': 6};
const level = {'low': 0, 'medium': 1, 'high': 2, 'very_high': 3};
const strobeLevel = {'low': 0, 'medium': 1, 'high': 2, 'very_high': 3};
const values = {
mode: value.mode || 'police_panic',
level: value.level || 'very_high',
strobe: value.hasOwnProperty('strobe') ? value.strobe : false,
duration: value.hasOwnProperty('duration') ? value.duration : 60,
strobeDutyCycle: value.hasOwnProperty('strobe_duty_cycle') ? value.strobe_duty_cycle * 10 : 0,
strobeLevel: value.hasOwnProperty('strobe_level') ? strobeLevel[value.strobe_level] : 1,
};
const info = (mode[values.mode]) + ((values.strobe ? 1 : 0) << 4) + (level[values.level] << 6);
await entity.command(
'ssIasWd',
'startWarning',
{startwarninginfo: info, warningduration: values.duration,
strobedutycycle: values.strobeDutyCycle, strobelevel: values.strobeLevel},
utils.getOptions(meta.mapped, entity),
);
},
},
}
module.exports = [
{
zigbeeModel: ['TS0216'],
model: 'TS0216',
vendor: 'TuYa',
description: 'Sound and flash siren',
fromZigbee: [fz.ts0216_siren, fz.battery],
exposes: [e.warning(), e.battery(), exposes.binary('alarm', ea.STATE_SET, true, false),
exposes.numeric('volume', ea.ALL).withValueMin(0).withValueMax(100).withDescription('Volume of siren')],
toZigbee: [tz.ts0216_alarm, tz.ts0216_duration, tz.ts0216_volume, tzLocal.warning],
configure: async (device, coordinatorEndpoint, logger) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
// Device advertises itself as Router but is an EndDevice
device.type = 'EndDevice';
device.save();
},
},
];
Restart Zigbee2MQTT, do a reconfigure on your Tyua device from the Z2M UI.
Then go to exposes, and play with the new warning settings, and report back if it works or not.
This is what now should be visible in the UI-> exposes