Skip to content

Commit

Permalink
fix: Fix some IKEA lights turning ON when receiving OFF if already OFF
Browse files Browse the repository at this point in the history
  • Loading branch information
Koenkk committed Aug 13, 2024
1 parent e898f03 commit c619318
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/converters/toZigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,10 @@ const converters2 = {
// 'MoveToLevelWithOnOff' despite not supporting the cluster; others, like the LEDVANCE SMART+
// plug, do not.)
brightness = transition.specified || brightness === 0 ? 0 : undefined;
if (brightness !== undefined && !utils.getMetaValue(entity, meta.mapped, 'noOffTransition', 'first', false)) {
logger.debug(`Supressing OFF transition since entity has noOffTransition=true`, NS);
brightness = undefined;
}
if (meta.state.hasOwnProperty('brightness') && meta.state.state === 'ON') {
// The light's current level gets clobbered in two cases:
// 1. when 'Off' has a transition, in which case it is really 'MoveToLevelWithOnOff'
Expand Down
6 changes: 3 additions & 3 deletions src/devices/ikea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const definitions: Definition[] = [
model: 'LED2103G5',
vendor: 'IKEA',
description: 'TRADFRI bulb E26/E27, warm white, globe, 806 lumen',
extend: [addCustomClusterManuSpecificIkeaUnknown(), ikeaLight(), identify()],
extend: [addCustomClusterManuSpecificIkeaUnknown(), ikeaLight({noOffTransition: true}), identify()],
},
{
zigbeeModel: ['TRADFRIbulbE26WWglobeclear250lm'],
Expand Down Expand Up @@ -148,7 +148,7 @@ const definitions: Definition[] = [
model: 'LED1842G3',
vendor: 'IKEA',
description: 'TRADFRI bulb E26/E27, warm white, globe, clear, 250 lm',
extend: [addCustomClusterManuSpecificIkeaUnknown(), ikeaLight(), identify()],
extend: [addCustomClusterManuSpecificIkeaUnknown(), ikeaLight({noOffTransition: true}), identify()],
},
{
zigbeeModel: ['TRADFRIbulbE27WWclear250lm', 'TRADFRIbulbE26WWclear250lm'],
Expand Down Expand Up @@ -197,7 +197,7 @@ const definitions: Definition[] = [
model: 'LED2201G8',
vendor: 'IKEA',
description: 'TRADFRI bulb E26/27, white spectrum, globe, opal, 1055/1100 lm',
extend: [addCustomClusterManuSpecificIkeaUnknown(), ikeaLight({colorTemp: true}), identify()],
extend: [addCustomClusterManuSpecificIkeaUnknown(), ikeaLight({colorTemp: true, noOffTransition: true}), identify()],
},
{
zigbeeModel: ['TRADFRIbulbPAR38WS900lm'],
Expand Down
5 changes: 4 additions & 1 deletion src/lib/ikea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const bulbOnEvent: OnEvent = async (type, data, device, options, state: KeyValue
}
};

export function ikeaLight(args?: Omit<LightArgs, 'colorTemp'> & {colorTemp?: true | {range: Range; viaColor: true}}) {
export function ikeaLight(args?: Omit<LightArgs, 'colorTemp'> & {colorTemp?: true | {range: Range; viaColor: true}; noOffTransition?: true}) {
const colorTemp: {range: Range} = args?.colorTemp ? (args.colorTemp === true ? {range: [250, 454]} : args.colorTemp) : undefined;
const result = lightDontUse({...args, colorTemp});
result.ota = ikea;
Expand All @@ -97,6 +97,9 @@ export function ikeaLight(args?: Omit<LightArgs, 'colorTemp'> & {colorTemp?: tru
if (args?.colorTemp || args?.color) {
result.exposes.push(presets.light_color_options());
}
if (args?.noOffTransition) {
result.meta = {...result.meta, noOffTransition: true};
}
return result;
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export interface DefinitionMeta {
* Override the Home Assistant discovery payload using a custom function.
*/
overrideHaDiscoveryPayload?(payload: KeyValueAny): void;
/**
* Never use a transition when transitioning to off (even when specified)
*/
noOffTransition?: true;
}

export type Configure = (device: Zh.Device, coordinatorEndpoint: Zh.Endpoint, definition: Definition) => Promise<void>;
Expand Down

0 comments on commit c619318

Please sign in to comment.