homebridge-broadlink-rm: Dimmable light accessory doesn't turn on
I’m not sure if this is just weirdness in the way my light works, but the dimmable light sends brightness values or off. But if my light is in the off state, it won’t turn on and set the brightness values. It needs to receive an on code and then the brightness code. Here’s the code I changed to make it work:
async setBrightness (hexData) { const { data, host, log } = this; const { off } = data const { on } = data
if (this.brightness > 0) {
const allHexKeys = Object.keys(data);
// Create an array of value specified in the data config
const foundValues = [];
allHexKeys.forEach((key) => {
const parts = key.split('brightness');
if (parts.length !== 2) return;
foundValues.push(parts[1])
})
// Find brightness closest to the one requested
const closest = foundValues.reduce((prev, curr) => Math.abs(curr - this.brightness) < Math.abs(prev - this.brightness) ? curr : prev);
log(`setBrightness: (closest: ${closest})`);
// Get the closest brightness's hex data
hexData = on;
sendData({ host, hexData, log });
hexData = data[`brightness${closest}`];
} else {
log(`setLightState: off`);
hexData = off;
}
sendData({ host, hexData, log });
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (9 by maintainers)
Yes im with Dids! Because there is almost just light accessories with increase and decrease buttons and no specific ones for 25%/50%?and so on. Isn’t there a way to define how many steps the module/controller can go up and down. For example the controller can go 5 stepson different brightness. Then you configure that the Lights turn on to 100%(it sends when you say turn on, one time the turn on code and at least the amount of steps the controller can go up, to make sure its on 100%) and then If you tell the device to dim about 20 percent, it goes down one step(by sending the decrease code). if you tell it to dim 60 % it goes down 3 steps. If you want it to go up it sends the other code(that many times as needed).
I don’t know how hard it is to program that, but would be cool to realize that. And isn’t there a way to choose a specific color? so you can make atleast 4 preprogrammed colors to choose from under the slider of the brightness?
Thought I’d comment here instead of opening a new issue, but what about lights that have a single signal for on/off, while also having 25%/50%/100% brightness levels and having a brightness up/down feature as well? Should I be using both “on” and “off” data, or only one or the other? Or would this not fit my scenario since there’s no way to ensure that the light is on/off?
Also any chance of expanding the light accessory to support increasing/decreasing the brightness?
EDIT: In my case there are 9 steps when adjusting the brightness up/down, 1 being around 1% brightness and 9 being 100% brightness. Technically adding a required stepCount attribute should allow the accessory to set the brightness level based on the current step, right?