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

Fix night/day light function #126

Open
zdenekbecka opened this issue Jan 30, 2025 · 0 comments
Open

Fix night/day light function #126

zdenekbecka opened this issue Jan 30, 2025 · 0 comments

Comments

@zdenekbecka
Copy link

Hi, would it be possible to modify the night/daylight function so that when I change this switch on the light, the light does not turn on? It just toggles the switch, without any further action.
For example:
params: ["on", "smooth", transition, state ? 1 : 0]

async setMoonlightMode(state) {
// Get transition time from config or use default 400ms
const { brightness: transition = 400 } = this.config.transitions || {};

// Log the mode change operation
this.log.debug(
Setting ${state ? 'moon' : 'day'}light mode on device ${this.did}
);

// Get current power state of the light
const [power] = await this.getProperty(['power']);
const isOn = power === 'on';

// Only send power command if the light is currently on
// This prevents the light from turning on when we just want to change the mode
if (isOn) {
await this.sendCmd({
method: 'set_power',
params: [
'on', // power state
'smooth', // effect type
transition, // transition duration in ms
state ? 1 : 0 // 1 for moonlight mode, 0 for daylight mode
],
});
}

// Store the active mode regardless of power state
// This ensures the correct mode is remembered when turning on next time
this.activeMode = state ? MOONLIGHT_MODE : DAYLIGHT_MODE;

// Log the result
this.log.debug(
Mode set to ${state ? 'moonlight' : 'daylight'}, light was ${isOn ? 'on' : 'off'}
);
}

This function will:
Change the mode without turning on the light if it's currently off
Change the mode and keep the light on if it's currently on
Remember the last mode setting for next time the light is turned on
Use proper mode values (1 for moonlight, 0 for daylight) as per Yeelight specification
Provide detailed debug logging

Thanks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant