Hi,
I have a regular lamp, which can be turned on and off by pressing a button. Additionally I can hold down the button, which at first dims the light step by step, and at the darkest point the direction flips and brightness is incremented.
To me this seems like a simple approach to control dimmable lights with just one button available (given it supports differentiating between a single press and a held down press, which mine does), and I would like to recreate this using the events of a button I have.
Here’s a simplistic Python-class which provides this functionality by calling its state-property as an example of what exactly I mean.
class Rotator(object):
def __init__(self, start, end, step):
self.start = start
self.end = end
self.step = step
self.current = self.start
self.direction = 1
@property
def state(self):
if self.direction:
if (self.current + self.step) <= self.end:
self.current += self.step
else:
self.direction = 0
self.current -= self.step
else:
if (self.current - self.step) >= self.start:
self.current -= self.step
else:
self.direction = 1
self.current += self.step
return self.current
If you create an instance with tmp = Rotator(0,255,50), the state rotates like this: 0, 50, 100, 150, 200, 250, 200, 150, 100, 50, 0, 50, 100… etc…
So if this somehow would be available in HASS, a single press would toggle a light on and off, and keeping it pressed would set the brightness of a turned on light to the value return by the rotator with each event.
Is this already somehow possible and I just haven’t looked at the right place?