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

Add support for Keen Home smart vent #276

Merged
merged 18 commits into from
Feb 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion converters/fromZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,14 @@ const converters = {
return {temperature: precisionRoundOptions(temperature, options, 'temperature')};
},
},
generic_temperature_change: {
cid: 'msTemperatureMeasurement',
type: 'devChange',
convert: (model, msg, publish, options) => {
const temperature = parseFloat(msg.data.data['measuredValue']) / 100.0;
return {temperature: precisionRoundOptions(temperature, options, 'temperature')};
},
},
xiaomi_temperature: {
cid: 'msTemperatureMeasurement',
type: 'attReport',
Expand Down Expand Up @@ -666,7 +674,7 @@ const converters = {
return {illuminance: msg.data.data['measuredValue']};
},
},
xiaomi_pressure: {
generic_pressure: {
cid: 'msPressureMeasurement',
type: 'attReport',
convert: (model, msg, publish, options) => {
Expand Down Expand Up @@ -1267,6 +1275,15 @@ const converters = {
}
},
},
generic_battery_change: {
cid: 'genPowerCfg',
type: 'devChange',
convert: (model, msg, publish, options) => {
if (msg.data.data.hasOwnProperty('batteryPercentageRemaining')) {
return {battery: msg.data.data['batteryPercentageRemaining']};
}
},
},
hue_battery: {
cid: 'genPowerCfg',
type: 'attReport',
Expand Down Expand Up @@ -1735,6 +1752,44 @@ const converters = {
return {action: `${direction}`};
},
},
cover_position: {
cid: 'genLevelCtrl',
type: 'devChange',
convert: (model, msg, publish, options) => {
const currentLevel = msg.data.data['currentLevel'];
const position = Math.round(Number(currentLevel) / 2.55).toString();
const state = position > 0 ? 'OPEN' : 'CLOSE';
return {state: state, position: position};
},
},
cover_position_report: {
cid: 'genLevelCtrl',
type: 'attReport',
convert: (model, msg, publish, options) => {
const currentLevel = msg.data.data['currentLevel'];
const position = Math.round(Number(currentLevel) / 2.55).toString();
const state = position > 0 ? 'OPEN' : 'CLOSE';
return {state: state, position: position};
},
},
keen_home_smart_vent_pressure: {
cid: 'msPressureMeasurement',
type: 'devChange',
convert: (model, msg, publish, options) => {
// '{"cid":"msPressureMeasurement","data":{"32":990494}}'
const pressure = parseFloat(msg.data.data['32']) / 1000.0;
return {pressure: precisionRoundOptions(pressure, options, 'pressure')};
},
},
keen_home_smart_vent_pressure_report: {
cid: 'msPressureMeasurement',
type: 'attReport',
convert: (model, msg, publish, options) => {
// '{"cid":"msPressureMeasurement","data":{"32":990494}}'
const pressure = parseFloat(msg.data.data['32']) / 1000.0;
return {pressure: precisionRoundOptions(pressure, options, 'pressure')};
},
},

// Ignore converters (these message dont need parsing).
ignore_doorlock_change: {
Expand Down
49 changes: 49 additions & 0 deletions converters/toZigbee.js
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,55 @@ const converters = {
return converters.light_colortemp.convert(key, value, message, type, postfix);
},
},
cover_open_close: {
key: ['state'],
convert: (key, value, message, type, postfix) => {
if (type === 'set') {
if (typeof value !== 'string') {
return;
}

const positionByState = {
'open': 100,
'close': 0,
};

value = positionByState[value.toLowerCase()];
}

return converters.cover_position.convert(key, value, message, type, postfix);
},
},
cover_position: {
key: ['position'],
Copy link
Owner

Choose a reason for hiding this comment

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

This should be 'state' (as homeassistant sends 100, not {"position": 100}, when the payload is not JSON, state will be used as default).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I probably need more explanation on this ... :)

I was reading this https://www.home-assistant.io/components/cover.mqtt/#set_position_topic
and it sounds like I should use "set_position_topic" instead of "command_topic"

So in this case, I'd think it should be like this?

    cover_position: {
        key: ['state'],
        convert: (key, value, message, type, postfix) => {
            const cid = 'genLevelCtrl';
            const attrId = 'currentLevel';

            if (type === 'set') {
                value = Math.round(Number(value) * 2.55).toString();
                return {
                    cid: cid,
                    cmd: 'moveToLevelWithOnOff',
                    cmdType: 'functional',
                    zclData: {
                        level: value,
                        transtime: 0,
                    },
                    cfg: cfg.default,
                    readAfterWriteTime: 0,
                };
            } else if (type === 'get') {
                return {
                    cid: cid,
                    cmd: 'read',
                    cmdType: 'foundation',
                    zclData: [{attrId: zclId.attr(cid, attrId).value}],
                    cfg: cfg.default,
                };
            }
        },
    },

What I'm also confused about is the 'get' part, I assume it's used by "position_topic"? But as you can see the return value for get is just a command object, how do I convert from brightness to position (0-100) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correction not brightness but currentLevel which is 0-255 based

convert: (key, value, message, type, postfix) => {
const cid = 'genLevelCtrl';
const attrId = 'currentLevel';

if (type === 'set') {
value = Math.round(Number(value) * 2.55).toString();
return {
cid: cid,
cmd: 'moveToLevelWithOnOff',
cmdType: 'functional',
zclData: {
level: value,
transtime: 0,
},
cfg: cfg.default,
readAfterWriteTime: 0,
};
} else if (type === 'get') {
return {
cid: cid,
cmd: 'read',
cmdType: 'foundation',
zclData: [{attrId: zclId.attr(cid, attrId).value}],
cfg: cfg.default,
};
}
},
},

// Ignore converters
ignore_transition: {
Expand Down
38 changes: 37 additions & 1 deletion devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ const devices = [
description: 'Aqara temperature, humidity and pressure sensor',
supports: 'temperature, humidity and pressure',
fromZigbee: [
fz.xiaomi_battery_3v, fz.xiaomi_temperature, fz.xiaomi_humidity, fz.xiaomi_pressure,
fz.xiaomi_battery_3v, fz.xiaomi_temperature, fz.xiaomi_humidity, fz.generic_pressure,
fz.ignore_basic_change, fz.ignore_temperature_change, fz.ignore_humidity_change,
fz.ignore_pressure_change, fz.WSDCGQ01LM_WSDCGQ11LM_interval,
],
Expand Down Expand Up @@ -2579,6 +2579,42 @@ const devices = [
},
},

// Keen Home
{
zigbeeModel: ['SV01-410-MP-1.0', 'SV01-410-MP-1.4', 'SV01-410-MP-1.5'],
model: 'SV01',
vendor: 'Keen Home',
description: 'Smart vent',
supports: 'open, close, position, temperature, pressure, battery',
fromZigbee: [
fz.cover_position,
fz.cover_position_report,
fz.generic_temperature,
fz.generic_temperature_change,
fz.generic_battery,
fz.generic_battery_change,
fz.keen_home_smart_vent_pressure,
fz.keen_home_smart_vent_pressure_report,
fz.ignore_onoff_change,
fz.ignore_onoff_report,
],
toZigbee: [
tz.cover_open_close,
tz.cover_position,
],
configure: (ieeeAddr, shepherd, coordinator, callback) => {
const device = shepherd.find(ieeeAddr, 1);
const actions = [
(cb) => device.bind('genLevelCtrl', coordinator, cb),
(cb) => device.bind('genPowerCfg', coordinator, cb),
(cb) => device.bind('msTemperatureMeasurement', coordinator, cb),
(cb) => device.bind('msPressureMeasurement', coordinator, cb),
];

execute(device, actions, callback);
},
},

// ELKO
{
zigbeeModel: ['ElkoDimmerZHA'],
Expand Down