diff --git a/README.md b/README.md index 2c62229d..1405b53c 100644 --- a/README.md +++ b/README.md @@ -57,5 +57,5 @@ _Note: This was tested with both devices, Zigbee2MQTT and IKEA lights, but the c | `sensor` | False | string \| list | - | `sensor.livingroom_controller_action` or `sensor.livingroom_sensor.livingroom_controller_action1, sensor.livingroom_controller_action2` | The sensor(s) entity id from HA. Note that for IKEA E1524/E1810 it finishes with "\_action" by default and for IKEA E1743 with "\_click". This can be also sent as list on the YAML (using "-") | | `light` | False | string | - | `group.livingroom_lights` or `light.kitchen` | The light (or group of lights) you want to control | | `manual_steps` | True | int | 10 | | Number of steps to go from min to max when clicking. If the value is 2 with one click you will set the light to 50% and with another one to 100%. | -| `automatic_steps` | True | int | 20 | | Number of steps to go from min to max when smoothing. If the value is 2 with one click you will set the light to 50% and with another one to 100%. | -| `delay` | True | int | 150 | | Delay in milliseconds that takes between sending the instructions to the light (for the smooth functionality). Note that the maximum value is 1000 and if leaving to 0, you might get uncommon behaviour. | +| `automatic_steps` | True | int | 10 | | Number of steps to go from min to max when smoothing. If the value is 2 with one click you will set the light to 50% and with another one to 100%. | +| `delay` | True | int | 350 | | Delay in milliseconds that takes between sending the instructions to the light (for the smooth functionality). Note that the maximum value is 1000 and if leaving to 0, you might get uncommon behaviour. | diff --git a/apps/z2m_ikea_controller/z2m_ikea_controller.py b/apps/z2m_ikea_controller/z2m_ikea_controller.py index e5839343..9fa0e230 100755 --- a/apps/z2m_ikea_controller/z2m_ikea_controller.py +++ b/apps/z2m_ikea_controller/z2m_ikea_controller.py @@ -1,14 +1,14 @@ """ Bring full functionality to IKEA light controllers -https://github.com/xaviml/ad-watchdog +https://github.com/xaviml/z2m_ikea_controller """ import appdaemon.plugins.hass.hassapi as hass import time DEFAULT_MANUAL_STEPS = 10 -DEFAULT_AUTOMATIC_STEPS = 20 -DEFAULT_DELAY = 150 +DEFAULT_AUTOMATIC_STEPS = 10 +DEFAULT_DELAY = 350 attribute_minmax = { "brightness": {"min": 1, "max": 255}, @@ -94,12 +94,14 @@ def turn_on_light(self, attribute, old, sign, steps): min_ = attribute_minmax[attribute]["min"] step = (max_ - min_) // steps new_state_attribute = old + sign * step + attributes = {attribute: new_state_attribute, "transition": self.delay / 1000} if min_ <= new_state_attribute <= max_: - self.turn_on(self.light, **{attribute: new_state_attribute}) + self.turn_on(self.light, **attributes) return new_state_attribute else: new_state_attribute = max(min_, min(new_state_attribute, max_)) - self.turn_on(self.light, **{attribute: new_state_attribute}) + attributes[attribute] = new_state_attribute + self.turn_on(self.light, **attributes) return None