feat: Add double flash indication for water button on remote switch connection and auto-off for remote switch upon connection.
This commit is contained in:
@@ -75,6 +75,33 @@ export default {
|
||||
if (ctx.trigger.mac === '08A6F773510C' && ctx.trigger.field === 'connected' && ctx.trigger.value === true) {
|
||||
ctx.log('Water button connected - turning light on');
|
||||
await setLight(ctx, ctx.trigger.mac, true, 20);
|
||||
|
||||
// Double flash if remote switch is already connected
|
||||
const remoteSwitchConnected = await ctx.getState(REMOTE_SWITCH_MAC, 'sys', 'connected');
|
||||
if (remoteSwitchConnected === true) {
|
||||
ctx.log('Remote switch already connected - double flashing');
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await ctx.sendRPC('08A6F773510C', 'Light.Set', { id: 0, on: true, brightness: 20 });
|
||||
await sleep(200);
|
||||
await ctx.sendRPC('08A6F773510C', 'Light.Set', { id: 0, on: false, brightness: 0 });
|
||||
await sleep(200);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-off for remote switch when it connects
|
||||
if (ctx.trigger.mac === REMOTE_SWITCH_MAC && ctx.trigger.field === 'connected' && ctx.trigger.value === true) {
|
||||
ctx.log('Remote switch connected - turning off and flashing light');
|
||||
await ctx.sendRPC(REMOTE_SWITCH_MAC, 'Switch.Set', { id: 0, on: false });
|
||||
|
||||
// Double flash the light
|
||||
for (let i = 0; i < 2; i++) {
|
||||
await ctx.sendRPC('08A6F773510C', 'Light.Set', { id: 0, on: true, brightness: 20 });
|
||||
await sleep(200);
|
||||
await ctx.sendRPC('08A6F773510C', 'Light.Set', { id: 0, on: false, brightness: 0 });
|
||||
await sleep(200);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user