Skip to content

Commit

Permalink
bug fix for multiple RGBW lights in a row
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt committed Dec 6, 2023
1 parent baa9bde commit 191ddb9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,31 +90,31 @@ dynalite:
name: Cupboard Strip Light
type: light
mode: rgbw
channel: red
channel: onoff
fade: 0.0
'2':
name: Cupboard Strip Light
type: light
mode: rgbw
channel: green
channel: red
fade: 0.0
'3':
name: Cupboard Strip Light
type: light
mode: rgbw
channel: blue
channel: green
fade: 0.0
'4':
name: Cupboard Strip Light
type: light
mode: rgbw
channel: white
channel: blue
fade: 0.0
'5':
name: Cupboard Strip Light
type: light
mode: rgbw
channel: onoff
channel: white
fade: 0.0
'101':
name: Aircon 1
Expand Down
45 changes: 25 additions & 20 deletions src/entities/homeAssistantHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const startup = ({
color_mode: true,
supported_color_modes: ["rgbw"]
};
// Reset 'sendonce' count in case for multiple RGBW lights in a row
if (sendonce >= 5) {
sendonce = 0;
}
// Only publish on first channel for RGBW light mode
if (sendonce >= 1) {
publish_topic = false;
}
Expand Down Expand Up @@ -212,23 +217,23 @@ export const commandsHandler = ({
}
console.log("fetched area", row);

var redchannel;
var onoffchannel;

switch (bridges.area[area].channel[channelNumber].channel) {
case 'onoff':
onoffchannel = channelNumber;
break;
case 'red':
redchannel = channelNumber;
onoffchannel = channelNumber - 1;
break;
case 'green':
redchannel = channelNumber - 1;
onoffchannel = channelNumber - 2;
break;
case 'blue':
redchannel = channelNumber - 2;
onoffchannel = channelNumber - 3;
break;
case 'white':
redchannel = channelNumber - 3;
break;
case 'onoff':
redchannel = channelNumber - 4;
onoffchannel = channelNumber - 4;
break;
default:
console.error('wrong channel number');
Expand All @@ -248,9 +253,9 @@ export const commandsHandler = ({
console.log("updated entry from mqtt with", areaNumber, channelNumber, state, color['r'], color['g'], color['b'], color['w'], brightness);

//add onoff
fade = bridges.area[area].channel[redchannel + 4].fade * 10;
fade = bridges.area[area].channel[onoffchannel + 0].fade * 10;
channelLevel = 1;
let temparr = [[28, areaNumber, redchannel + 4 - 1, 113, channelLevel, fade, 255]];
let temparr = [[28, areaNumber, onoffchannel + 0 - 1, 113, channelLevel, fade, 255]];

//update the brightness
if (!(brightness === undefined)) {
Expand All @@ -267,9 +272,9 @@ export const commandsHandler = ({
row.red = color['r'];
}

fade = bridges.area[area].channel[redchannel].fade * 10;
fade = bridges.area[area].channel[onoffchannel + 1].fade * 10;
channelLevel = getchannellevel(parseInt(row.red), brightness);
temparr.push([28, areaNumber, redchannel + 0 - 1, 113, channelLevel, fade, 255]);
temparr.push([28, areaNumber, onoffchannel + 1 - 1, 113, channelLevel, fade, 255]);

//add green
if (!(color['g'] === undefined)) {
Expand All @@ -278,19 +283,19 @@ export const commandsHandler = ({
row.green = color['g'];
}

fade = bridges.area[area].channel[redchannel + 1].fade * 10;
fade = bridges.area[area].channel[onoffchannel + 2].fade * 10;
channelLevel = getchannellevel(parseInt(row.green), brightness);
temparr.push([28, areaNumber, redchannel + 1 - 1, 113, channelLevel, fade, 255]);
temparr.push([28, areaNumber, onoffchannel + 2 - 1, 113, channelLevel, fade, 255]);

//add blue
if (!(color['b'] === undefined)) {
//update the blue in the row
row.blue = color['b'];
}

fade = bridges.area[area].channel[redchannel + 2].fade * 10;
fade = bridges.area[area].channel[onoffchannel + 3].fade * 10;
channelLevel = getchannellevel(parseInt(row.blue), brightness);
temparr.push([28, areaNumber, redchannel + 2 - 1, 113, channelLevel, fade, 255]);
temparr.push([28, areaNumber, onoffchannel + 3 - 1, 113, channelLevel, fade, 255]);

//add white
if (!(color['w'] === undefined)) {
Expand All @@ -299,9 +304,9 @@ export const commandsHandler = ({
row.white = color['w'];
}

fade = bridges.area[area].channel[redchannel + 3].fade * 10;
fade = bridges.area[area].channel[onoffchannel + 4].fade * 10;
channelLevel = getchannellevel(parseInt(row.white), brightness);
temparr.push([28, areaNumber, redchannel + 3 - 1, 113, channelLevel, fade, 255]);
temparr.push([28, areaNumber, onoffchannel + 4 - 1, 113, channelLevel, fade, 255]);

var len = temparr.length;
var i = 0;
Expand Down Expand Up @@ -331,10 +336,10 @@ export const commandsHandler = ({
} else if (state === "OFF") {
dbmanager.dbinsertorupdate((err) => {

fade = bridges.area[area].channel[redchannel + 4].fade * 10;
fade = bridges.area[area].channel[onoffchannel + 0].fade * 10;
console.log("updated entry from mqtt with", areaNumber, channelNumber, state);
channelLevel = 255;
const buffer = util.createBuffer([28, areaNumber, redchannel + 4 - 1, 113, channelLevel, fade, 255]);
const buffer = util.createBuffer([28, areaNumber, onoffchannel + 0 - 1, 113, channelLevel, fade, 255]);
dynaliteClient.write(Buffer.from(buffer), (err) => {
sendMqttMessageRgbw(_topic, null, state);
});
Expand Down

0 comments on commit 191ddb9

Please sign in to comment.