Skip to content

Commit

Permalink
feat(transition):
Browse files Browse the repository at this point in the history
Adding transition attribute for better smoothness
  • Loading branch information
xaviml committed Nov 25, 2019
1 parent 31530a5 commit 979ec62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
12 changes: 7 additions & 5 deletions apps/z2m_ikea_controller/z2m_ikea_controller.py
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 979ec62

Please sign in to comment.