The sync action only changes the brightness to the maximum level, however, we also want the light to be set at 2700K or in a white colour
Hi' Xavi.
Follow up on my 'special' ControlllerX apps to get sync working properly ๐
I'm convinced that the following suggested changes in code, would work for sync with light from both on andoffposition. Have made the last test now with Ikea white spectrum on Hue bridge. This also worked properly from both on and off positions.
Needed changes to code (I believe):
await self.on(add_transition=True, **attributes)transition: 0 in app works. Will accept higher transitions as well. Haven't tested though to find appx. max. useful value of transition attribute.toggle_hold from off HAS to be called with transition: 0 attribute (zero attribute works for sure)toggle_hold from on HAS to be made in two calls:transition: 0 (zero attribute works for sure)Below my 'revised' ControllerX apps that have been tested to work with:
transition attribute)_If we can get this to work in z2m networks and on Hue bridges, we will have to get the Deconz/ZHA guys to test as well. And also with other bulbs than Ikea and Philips Hue.
+++ REVISED cut from issue #45 +++
Using latest beta v2.4.0b3 (with a small patch), I've made some controllerX apps to 'emulate' toggle_hold from off when light is actually on ๐
It's completely 'quick and dirty' for test purposes, but it works with toggle_hold both from on and off light positions.
I just test if toggle_hold originally came from an light on position. If yes, turn on light again and call toggle_hold via mqtt
hallway_light_group_no_toggle:
# all actions, but toggle_hold for smooth operation with light groups on Hue Bridge
module: controllerx
class: E1810Controller
controller: sensor.0x90fd9ffffe17d796_action
integration: z2m
#transition: 500 # Optional but not needed to get `sync` function to work
smooth_power_on: true
light: light.mikkel_loft # Ikea White Spectrum bulb on Hue bridge
actions:
- arrow_left_hold
- arrow_left_release
- arrow_right_hold
- arrow_right_release
- arrow_right_click
- arrow_left_click
- brightness_up_click
- brightness_down_click
- brightness_up_release
- brightness_down_release
- brightness_up_hold
- brightness_down_hold
- toggle
hallway_light_group_toggle_hold_from_off:
module: controllerx
class: E1810Controller
controller: sensor.0x90fd9ffffe17d796_action
integration: z2m
transition: 0 #transition attribute works on Hue bridge. *** Needed for Ikea bulbs on Hue Bridge to change color AND brightness on sync !! Otherwise ONLY color will change !! ***
light: light.mikkel_loft
actions:
- toggle_hold
constrain_input_boolean: light.mikkel_loft,on #ensure that toggle_hold will only be called when lights was off and has just turned on (toggle_hold from off)
hallway_light_group_toggle_hold_from_on:
module: controllerx
class: CallServiceController
controller: sensor.0x90fd9ffffe17d796_action
integration: z2m
mapping:
toggle_hold:
- service: light.turn_on
data:
entity_id: light.mikkel_loft
#brightness: 255 # Optional but not needed to get `sync` function to work
#transition: 0 # Optional but not needed to get `sync` function to work
- service: mqtt.publish #publish the toggle_hold command again, now with lights on
data:
topic: 'zigbee2mqtt/Ikea hallway'
payload: '{"linkquality":80,"battery":80,"update_available":true,"action":"toggle_hold"}'
- service: mqtt.publish
data:
topic: 'zigbee2mqtt/Ikea hallway'
payload: '{"linkquality":80,"battery":80,"update_available":true,"action":""}'
constrain_input_boolean: light.mikkel_loft,off #ensure that toggle_hold will only be called when lights was on and was turned off by first toggle (toggle_hold from on)
Hi @htvekov
Thank you for that info! I am very busy lately, so I do not have time to keep with the development of this issue for this release. I will release v2.4.0 having sync to change just brightness. I will work on this issue for the next release.
Again, thank you for your collaboration!
No worries, Xavi ๐
This is by far not an issue that needs to be adressed urgently.
But it would be nice to have this issue sorted at some point.
Especially if you are thinking (or have requests ?) about some sort of scene handling from controllerX ?
That would actually be a really nice feature I believe most would have benefit from ๐ค
Ciao for now, Xavi ๐โโ๏ธ๐โโ๏ธ
Hi' Xavi.
Spend the evening bug hunting, even though I know absolutely nothing about Python's syntax or the commands ๐ But with some logic and a lot of 'trial and error' I found the following ๐
There seems to be a local variable error in code when sync is called from lights on condition ?
If I use following line as alternative to original code, appdeamon throws an error from light on, but code is working from lights off ?
ControllerX beta v2.4.0b3:
self.call_service("homeassistant/turn_on", entity_id=self.light["name"], xy_color=attributes[color_attribute], transition=2) # Only working from 'toggle_hold' from off. Otherwise variable error in appdeamon
appdeamon error:
020-03-13 00:19:30.248240 WARNING hallway_light_group_toggle_hold_from_off: ------------------------------------------------------------
2020-03-13 00:19:30.251726 WARNING hallway_light_group_toggle_hold_from_off: Traceback (most recent call last):
File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 709, in async_worker
await funcref(entity, attr, old_state, new_state, self.AD.state.sanitize_state_kwargs(app, args["kwargs"]))
File "/config/appdaemon/apps/controllerx/core/integration/state.py", line 15, in callback
await self.controller.handle_action(new)
File "/config/appdaemon/apps/controllerx/core/controller.py", line 120, in handle_action
await action(args)
File "/config/appdaemon/apps/controllerx/core/controller.py", line 28, in _action_impl
await method(self, *args, *kwargs)
File "/config/appdaemon/apps/controllerx/core/type/light_controller.py", line 303, in sync
self.call_service("homeassistant/turn_on", entity_id=self.light["name"], xy_color=attributes[color_attribute], transition=2)
UnboundLocalError: local variable 'color_attribute' referenced before assignment
2020-03-13 00:19:30.253403 WARNING hallway_light_group_toggle_hold_from_off: ------------------------------------------------------------
If I replace variable with 'hardcoded' xy_color attribute, it works perfectly from both light on and off position ๐
But with my very limited Python knowledge I can't figure out why variable is only valid called from off position and not from on ?
Following beta v2.4.0b3 patch works: (tested on Ikea color bulb on z2m network and Hue bulb on Hue Bridge. Ikea White Spectrum test on Hue bridge will follow tomorrow)
@action
async def sync(self):
self.call_service("homeassistant/turn_on", entity_id=self.light["name"], brightness=255, transition=0) #First turn on call needed with transition: 0 and brightness: 255 !!!
attributes = {LightController.ATTRIBUTE_BRIGHTNESS: self.max_brightness}
try:
color_attribute = await self.get_attribute(LightController.ATTRIBUTE_COLOR)
if color_attribute == LightController.ATTRIBUTE_COLOR_TEMP:
attributes[color_attribute] = 370 # 2700K light
else:
self.index_color = 12 # white colour
attributes[color_attribute] = self.colors[self.index_color]
except:
self.log("sync action will only change brightness", level="DEBUG")
#await self.on(add_transition=True, **attributes) # Working with 'toggle_hold' from off. Local variable 'color attribute' not read ??
#self.call_service("homeassistant/turn_on", entity_id=self.light["name"], xy_color=attributes[color_attribute], transition=2) # Only working with 'toggle_hold' from lights off. Otherwise variable error in appdeamon ??
self.call_service("homeassistant/turn_on", entity_id=self.light["name"], xy_color=[0.323, 0.329], transition=2) # Working with 'toggle_hold' from on and off !!! Transition can be anything !!!
I'll leave the 'professional' debugging to someone who actually knowns what he's doing ๐๐๐๐ท๐๐
Ciao !!
Hi' Xavi.
Just made the test with Ikea White Spectrum bulb on Hue bridge as well.
All working perfectly as expected with kelvin instead of xy_color in call off course ๐
self.call_service("homeassistant/turn_on", entity_id=self.light["name"], kelvin=2700, transition=2) # Working with 'toggle_hold' from on and off !!! Transition can be anything !!!
Ciao !
You are a legend @htvekov. I just tried what you said and it works from off and on and also it works for color_temp and xy_color. I also changed the way to detect the features of the light. Apparently there is an attribute that is always present called supported_features. This attribute is a bitfield with flags for different attributes. There was a bug that I only knew the type of light if it was on, but now reading the supported_features I can always know.
I just released v2.4.1b1 for you to test out. Thank you for your help!
Just tested the new beta, Xavi.
All working perfectly now at my end, with all three usual test scenarios at my end ๐๐
Wasn't aware of the supported_features attribute. Nice to know ๐
Also good to know the different 'needs' for various bulbs on different integrations.
That will come in handy, if you're to introduce scenes or anything else requiring both brightness and color changes to bulbs at same time.
Wish you a lovely weekend, Xavi.
Thanks for the fix and you effort !!
Ciao !
Most helpful comment
You are a legend @htvekov. I just tried what you said and it works from off and on and also it works for color_temp and xy_color. I also changed the way to detect the features of the light. Apparently there is an attribute that is always present called
supported_features. This attribute is a bitfield with flags for different attributes. There was a bug that I only knew the type of light if it was on, but now reading thesupported_featuresI can always know.I just released v2.4.1b1 for you to test out. Thank you for your help!