Hello everyone, I’m excited to share my latest project and seek some guidance. I’ve been working on creating a rule for my living room lights that allows me to control both the on/off state and brightness using a single physical button. While the concept seems straightforward, I’m encountering a few hurdles that I hope the community can help me overcome.
Here’s what I’m aiming for: pressing the button once toggles the lights on or off. If I press it multiple times quickly, it should increase the brightness by 20% each time. If the brightness reaches 100%, the light should turn off. I’ve set up a virtual dimmer called LivingRoomBrightness
to store the last brightness level, but I’m open to suggestions for a more efficient approach using persistence or the actual light state.
I’ve written some pseudo-code to outline the logic, but I’m aware it’s not perfect. Here’s a snippet of the rule I’m working on:
plaintext
when LR_button.state == updated then
if LR_light.state == OFF then
LR_light.state = LivingRoomBrightness
else if Now - LR_button.lastUpdate > 2.5 seconds then
LR_light.state = OFF
else if LivingRoomBrightness.state == 100% then
LR_light.state = OFF
else
LivingRoomBrightness.state = LivingRoomBrightness + 20%
LR_light.state = LivingRoomBrightness
While this logic seems solid, I’m encountering issues with timing and state management. For example, the brightness doesn’t always reset correctly when reaching 100%, and the timing mechanism isn’t as reliable as I’d like. I’m also considering whether wrapping around from 100% to 0% would be a better user experience, allowing for seamless control without needing to press the button multiple times to decrease brightness.
I’d greatly appreciate any insights or tips to refine this rule. Whether it’s correcting the syntax, improving the logic, or suggesting alternative approaches, your expertise would be invaluable. Additionally, if there’s a more efficient way to track the button presses or manage the brightness levels, I’m all ears!
Thank you in advance for your help. I’m looking forward to learning from your experiences and creating a smooth, user-friendly lighting control system!
Best regards,
[Your Name]