diff --git a/rules/waterButtonLearnAndCall.js b/rules/waterButtonLearnAndCall.js index af93b84..ecc6db2 100644 --- a/rules/waterButtonLearnAndCall.js +++ b/rules/waterButtonLearnAndCall.js @@ -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; }