Skip to content

Commit

Permalink
- fixed ColorTemperature values for homekit;
Browse files Browse the repository at this point in the history
- improved curtains formatting;
  • Loading branch information
andreypopov committed Jun 26, 2022
1 parent f0f73cc commit 2d0ad32
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion nodes/out.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ module.exports = function(RED) {
msg['state'] = "on";
}
if (payload.ColorTemperature !== undefined) {
msg['color_temp'] = Zigbee2mqttHelper.convertRange(payload.ColorTemperature, [140,500], [50,400]);
msg['color_temp'] = Zigbee2mqttHelper.convertRange(payload.ColorTemperature, [150,500], [150,500]);
if ("current_values" in device) {
if ("color_temp" in device.current_values) device.current_values.color_temp = msg['color_temp'];
}
Expand Down
7 changes: 6 additions & 1 deletion nodes/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ module.exports = function(RED) {
node.devices[ind]['current_values'] = node.devices_values[topic];
node.devices[ind]['homekit'] = Zigbee2mqttHelper.payload2homekit(node.devices_values[topic]);
node.devices[ind]['format'] = Zigbee2mqttHelper.formatPayload(node.devices_values[topic], node.devices[ind]);
} else {
// node.warn('no retain option for: ' + topic)
//force get data
node.mqtt.publish(node.getTopic('/bridge/'+node.devices[ind]['ieee_address']+'/get'));

}
}

Expand Down Expand Up @@ -700,7 +705,7 @@ module.exports = function(RED) {
node.connection = true;
node.log('MQTT Connected');
node.emit('onMQTTConnect');
node.getDevices(function() {
node.getDevices(() => {
node.subscribeMQTT();
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"name": "node-red-contrib-zigbee2mqtt",
"description": "Zigbee2mqtt connectivity nodes for node-red",
"version": "2.2.5",
"version": "2.3.0",
"dependencies": {
"eventsource": "^2.0.2",
"mqtt": "^4.3.7",
Expand Down
40 changes: 33 additions & 7 deletions resources/Zigbee2mqttHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class Zigbee2mqttHelper {
sat = hsv.s;
}
var bri = Zigbee2mqttHelper.convertRange(parseInt(payload.brightness), [0, 255], [0, 100]);
var ct = "color_temp" in payload ? Zigbee2mqttHelper.convertRange(parseInt(payload.color_temp), [50, 400], [140, 500]) : null;
var ct = "color_temp" in payload ? Zigbee2mqttHelper.convertRange(parseInt(payload.color_temp), [150, 500], [150, 500]) : null;

msg["Lightbulb"] = {
"On": true,
Expand Down Expand Up @@ -265,10 +265,36 @@ class Zigbee2mqttHelper {
};
}

//Window
//WindowCovering
//Door
if ('position' in payload) {


// 0: "stopped"
// 1: "opening"
// 2: "closing"
// public static readonly DECREASING = 0;
// public static readonly INCREASING = 1;
// public static readonly STOPPED = 2;
if ('position' in payload && 'motor_state' in payload) {
let motor_state = null;
switch (payload.motor_state) {
case 'closing':
motor_state = 0;
break;
case 'opening':
motor_state = 1;
break;
case 'stopped':
default:
motor_state = 2;
break;
}

msg["Window"] = msg["WindowCovering"] = msg["Door"] = {
"CurrentPosition": parseInt(payload.position),
"TargetPosition": parseInt(payload.position),
"PositionState": motor_state
};

} else if ('position' in payload && 'running' in payload) { //old??
msg["Window"] = msg["WindowCovering"] = msg["Door"] = {
"CurrentPosition": parseInt(payload.position),
"TargetPosition": parseInt(payload.position),
Expand Down Expand Up @@ -341,9 +367,9 @@ class Zigbee2mqttHelper {
}

//Switch
if ("state" in payload && (payload.state == "ON" || payload.state == "OFF")) {
if ("state" in payload && (payload.state === "ON" || payload.state === "OFF")) {
msg["Switch"] = {
"On": payload.state == "ON"
"On": payload.state === "ON"
};
}

Expand Down
2 changes: 1 addition & 1 deletion resources/js/node-red-contrib-zigbee2mqtt-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Zigbee2MqttEditor {
});
}

if (device && 'homekit' in device && Object.keys(device.homekit).length) {
if (device && 'homekit' in device && device.homekit && Object.keys(device.homekit).length) {
html = $('<optgroup/>', {label: RED._("node-red-contrib-zigbee2mqtt/server:editor.homekit")});
html.appendTo(that.getDevicePropertyInput());

Expand Down

0 comments on commit 2d0ad32

Please sign in to comment.