Skip to content

Commit

Permalink
fix: Fix power source uknown for various SONOFF devices Koenkk/zigbee…
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Oct 22, 2024
1 parent 511a622 commit 7e8a807
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 52 deletions.
71 changes: 20 additions & 51 deletions src/devices/sonoff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
humidity,
iasZoneAlarm,
numeric,
occupancy,
onOff,
ota,
temperature,
Expand All @@ -27,7 +28,7 @@ import * as tuya from '../lib/tuya';
import {DefinitionWithExtend, Fz, KeyValue, KeyValueAny, ModernExtend, Tz} from '../lib/types';
import * as utils from '../lib/utils';

const {ewelinkAction} = ewelinkModernExtend;
const {ewelinkAction, ewelinkBattery} = ewelinkModernExtend;

const NS = 'zhc:sonoff';
const manufacturerOptions = {
Expand Down Expand Up @@ -639,45 +640,35 @@ const definitions: DefinitionWithExtend[] = [
vendor: 'SONOFF',
whiteLabel: [{vendor: 'eWeLink', model: 'RHK06'}, tuya.whitelabel('Tuya', 'WL-19DWZ', 'Contact sensor', ['_TZ3000_n2egfsli'])],
description: 'Contact sensor',
exposes: [e.contact(), e.battery_low(), e.battery(), e.battery_voltage()],
fromZigbee: [fz.ias_contact_alarm_1, fz.battery],
toZigbee: [],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
await reporting.batteryVoltage(endpoint, {min: 3600, max: 7200});
await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200});
},
extend: [ewelinkBattery(), iasZoneAlarm({zoneType: 'contact', zoneAttributes: ['alarm_1', 'battery_low']})],
},
{
zigbeeModel: ['WB01', 'WB-01'],
model: 'SNZB-01',
vendor: 'SONOFF',
whiteLabel: [{vendor: 'eWeLink', model: 'RHK07'}],
description: 'Wireless button',
exposes: [e.battery(), e.action(['single', 'double', 'long']), e.battery_voltage()],
fromZigbee: [fz.ewelink_action, fz.battery],
extend: [ewelinkBattery()],
exposes: [e.action(['single', 'double', 'long'])],
fromZigbee: [fz.ewelink_action],
toZigbee: [],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff', 'genPowerCfg']);
await reporting.batteryVoltage(endpoint, {min: 3600, max: 7200});
await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200});
await reporting.bind(endpoint, coordinatorEndpoint, ['genOnOff']);
},
},
{
zigbeeModel: ['KF01', 'KF-01'],
model: 'SNZB-01-KF',
vendor: 'SONOFF',
description: 'Wireless button',
exposes: [e.battery(), e.action(['off', 'single']), e.battery_voltage()],
fromZigbee: [fz.command_status_change_notification_action, fz.battery],
extend: [ewelinkBattery()],
exposes: [e.action(['off', 'single'])],
fromZigbee: [fz.command_status_change_notification_action],
toZigbee: [],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['ssIasZone', 'genPowerCfg']);
await reporting.batteryVoltage(endpoint, {min: 3600, max: 7200});
await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200});
await reporting.bind(endpoint, coordinatorEndpoint, ['ssIasZone']);
},
},
{
Expand Down Expand Up @@ -712,6 +703,8 @@ const definitions: DefinitionWithExtend[] = [
fromZigbee: [fz.SNZB02_temperature, fz.humidity, fz.battery],
toZigbee: [],
configure: async (device, coordinatorEndpoint) => {
device.powerSource = 'Battery';
device.save();
try {
const endpoint = device.getEndpoint(1);
const bindClusters = ['msTemperatureMeasurement', 'msRelativeHumidity', 'genPowerCfg'];
Expand All @@ -731,7 +724,7 @@ const definitions: DefinitionWithExtend[] = [
model: 'SNZB-02D',
vendor: 'SONOFF',
description: 'Temperature and humidity sensor with screen',
extend: [battery({percentage: true}), temperature(), humidity(), bindCluster({cluster: 'genPollCtrl', clusterType: 'input'})],
extend: [battery(), temperature(), humidity(), bindCluster({cluster: 'genPollCtrl', clusterType: 'input'})],
},
{
fingerprint: [
Expand All @@ -754,18 +747,7 @@ const definitions: DefinitionWithExtend[] = [
vendor: 'SONOFF',
whiteLabel: [{vendor: 'eWeLink', model: 'RHK09'}],
description: 'Motion sensor',
fromZigbee: [fz.ias_occupancy_alarm_1, fz.battery],
toZigbee: [],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
const bindClusters = ['genPowerCfg'];
await reporting.bind(endpoint, coordinatorEndpoint, bindClusters);
// 3600/7200 prevents disconnect
// https://github.com/Koenkk/zigbee2mqtt/issues/13600#issuecomment-1283827935
await reporting.batteryVoltage(endpoint, {min: 3600, max: 7200});
await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200});
},
exposes: [e.occupancy(), e.battery_low(), e.battery(), e.battery_voltage()],
extend: [ewelinkBattery(), iasZoneAlarm({zoneType: 'occupancy', zoneAttributes: ['alarm_1', 'battery_low']})],
},
{
zigbeeModel: ['S26R2ZB'],
Expand Down Expand Up @@ -839,9 +821,8 @@ const definitions: DefinitionWithExtend[] = [
model: 'SNZB-04P',
vendor: 'SONOFF',
description: 'Contact sensor',
exposes: [e.contact(), e.battery_low(), e.battery(), e.battery_voltage()],
fromZigbee: [fz.ias_contact_alarm_1, fz.battery],
extend: [
iasZoneAlarm({zoneType: 'contact', zoneAttributes: ['alarm_1', 'battery_low']}),
binary({
name: 'tamper',
cluster: 0xfc11,
Expand All @@ -853,22 +834,16 @@ const definitions: DefinitionWithExtend[] = [
access: 'STATE_GET',
}),
ota(),
ewelinkBattery(),
],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
await reporting.batteryVoltage(endpoint, {min: 3600, max: 7200});
await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200});
},
},
{
zigbeeModel: ['SNZB-03P'],
model: 'SNZB-03P',
vendor: 'SONOFF',
description: 'Zigbee PIR sensor',
fromZigbee: [fz.occupancy, fz.battery],
exposes: [e.occupancy(), e.battery()],
extend: [
occupancy(),
numeric({
name: 'motion_timeout',
cluster: 0x0406,
Expand All @@ -887,13 +862,8 @@ const definitions: DefinitionWithExtend[] = [
access: 'STATE',
}),
ota(),
ewelinkBattery(),
],
configure: async (device, coordinatorEndpoint) => {
const endpoint = device.getEndpoint(1);
await reporting.bind(endpoint, coordinatorEndpoint, ['genPowerCfg']);
await reporting.batteryVoltage(endpoint, {min: 3600, max: 7200});
await reporting.batteryPercentageRemaining(endpoint, {min: 3600, max: 7200});
},
},
{
zigbeeModel: ['SNZB-05P'],
Expand All @@ -907,9 +877,8 @@ const definitions: DefinitionWithExtend[] = [
model: 'SNZB-06P',
vendor: 'SONOFF',
description: 'Zigbee occupancy sensor',
fromZigbee: [fz.occupancy],
exposes: [e.occupancy()],
extend: [
occupancy(),
numeric({
name: 'occupancy_timeout',
cluster: 0x0406,
Expand Down
12 changes: 11 additions & 1 deletion src/lib/ewelink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {presets} from './exposes';
import {setupConfigureForBinding} from './modernExtend';
import {battery, setupConfigureForBinding} from './modernExtend';
import {Configure, Expose, Fz, KeyValueAny, ModernExtend} from './types';

export const ewelinkModernExtend = {
Expand All @@ -21,6 +21,16 @@ export const ewelinkModernExtend = {

return {exposes, fromZigbee, configure, isModernExtend: true};
},
ewelinkBattery: (): ModernExtend => {
// 3600/7200 prevents disconnect
// https://github.com/Koenkk/zigbee2mqtt/issues/13600#issuecomment-1283827935
return battery({
voltage: true,
voltageReporting: true,
percentageReportingConfig: {min: 3600, max: 7200, change: 10},
voltageReportingConfig: {min: 3600, max: 7200, change: 10},
});
},
};

export {ewelinkModernExtend as modernExtend};

0 comments on commit 7e8a807

Please sign in to comment.