One of the options to change the brightness or color temperature is to have a "toggle direction". This allows users to use a single hold-release button to change brightness up and down. As for now, if the light was set to 100% with ControllerX, then the direction changes to go down next time the button is held. However, the brightness might have been changed externally through HA or other integration. Then, the user will need to hold twice to dim down the brightness.
The proposed solution is to detect in runtime the brightness (or other attribute's state) if it is at its maximum or minimum level. If so, then we can determine the direction automatically.
This bug was discovered by @htvekov. Thanks for spotting this out.
Hi @htvekov,
I have fixed this bug already. The change is on the dev branch. The only way for me to test this is with my unitary tests, which they all pass, but I currently cannot test this myself on my setup since I moved out and I need to set everything up in my new apartment.
Feel free to switch to the dev branch version from HACS and check if this has been fixed and you can use your setup as you normally do, with no unexpected behaviors. If you are not able to test this out, I will be testing it out once I have the setup installed back again. I will not release this until this is tested.
Thank you for your help in advance :)
Hi' Xavi.
Great! 馃憤馃槑
I've tested dev version and dimming direction appears to be correct first time, no matter if at lowest or highest allowed brightness level. I've tested with min_brightness and max_brightness attributes in app as well and all appeared to work 100%
Only one minor detail about this bug fix. on INITIAL start of app (restart appdeamon eg.) dimming direction apparently is NOT set correctly ?. Still has to press button a second time, before dimming up/down starts. But this only happens ONCE. if app is reconfigured and restarted or appdeamon itself is restarted.
Hi @htvekov,
I tested this on a friend's setup and I could not make it work (maybe I did not install it properly or something). Glad to hear you see the fix on your side.
I ordered already a new Raspberry Pi that I will be getting soon, so I will be able again to test this again by myself. Then I will check the issue you are mentioning, although it is interesting because it should not matter if you restart AppDaemon or not since it gets the value and does the checking at the moment you press the button.
I will keep you updated, thanks!
Yep, the fix works perfectly here! 馃槑
Strange that you can't get it to work ?
Equally strange that on appdeamon restart or change in apps.yaml (reload of apps) then initial hold command doesn't start to dim lights as expected.
If you see appdeamon log below the first hold after sync doesn't start dimming. On second hold dimming starts ?
2020-06-02 23:05:46.952686 INFO AppDaemon: /config/appdaemon/apps/apps.yaml added or modified
2020-06-02 23:05:46.953611 INFO AppDaemon: Found 17 total apps
2020-06-02 23:05:57.881880 INFO controller_switchmode11_off_office: 馃幃 Button event triggered: `inc-dec`
2020-06-02 23:05:57.885173 INFO controller_switchmode11_off_office: 馃弮 Running `sync` now
2020-06-02 23:05:57.891624 INFO controller_switchmode11_off_office: 馃 Service: light.turn_on
2020-06-02 23:05:57.896126 INFO controller_switchmode11_off_office: - entity_id: light.0xec1bbdfffed45c3b_light
2020-06-02 23:05:57.900383 INFO controller_switchmode11_off_office: - color_temp: 370
2020-06-02 23:05:57.904509 INFO controller_switchmode11_off_office: - brightness: 255
2020-06-02 23:05:57.908696 INFO controller_switchmode11_off_office: - transition: 0.30
2020-06-02 23:05:59.305029 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `clear`
2020-06-02 23:05:59.308359 INFO controller_switchmode11_on_office: 馃弮 Running `release` now
First 'hold' does nothing ?
2020-06-02 23:06:01.931139 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `inc-dec`
2020-06-02 23:06:01.934442 INFO controller_switchmode11_on_office: 馃弮 Running `hold_brightness_toggle` now
2020-06-02 23:06:01.978495 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-06-02 23:06:01.983476 INFO controller_switchmode11_on_office: - entity_id: light.0xec1bbdfffed45c3b_light
2020-06-02 23:06:01.988291 INFO controller_switchmode11_on_office: - brightness: 255
2020-06-02 23:06:01.993153 INFO controller_switchmode11_on_office: - transition: 0.40
2020-06-02 23:06:05.549690 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `clear`
2020-06-02 23:06:05.552961 INFO controller_switchmode11_on_office: 馃弮 Running `release` now
Second 'hold' starts the dimming
2020-06-02 23:06:59.778129 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `inc-dec`
2020-06-02 23:06:59.781465 INFO controller_switchmode11_on_office: 馃弮 Running `hold_brightness_toggle` now
2020-06-02 23:06:59.825958 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-06-02 23:06:59.830945 INFO controller_switchmode11_on_office: - entity_id: light.0xec1bbdfffed45c3b_light
2020-06-02 23:06:59.835772 INFO controller_switchmode11_on_office: - brightness: 223.25
2020-06-02 23:06:59.840636 INFO controller_switchmode11_on_office: - transition: 0.40
2020-06-02 23:07:00.357825 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-06-02 23:07:00.365170 INFO controller_switchmode11_on_office: - entity_id: light.0xec1bbdfffed45c3b_light
2020-06-02 23:07:00.370028 INFO controller_switchmode11_on_office: - brightness: 191.50
2020-06-02 23:07:00.374901 INFO controller_switchmode11_on_office: - transition: 0.40
2020-06-02 23:07:00.822960 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-06-02 23:07:00.828102 INFO controller_switchmode11_on_office: - entity_id: light.0xec1bbdfffed45c3b_light
2020-06-02 23:07:00.833080 INFO controller_switchmode11_on_office: - brightness: 159.75
2020-06-02 23:07:00.838067 INFO controller_switchmode11_on_office: - transition: 0.40
2020-06-02 23:07:01.159392 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `clear`
2020-06-02 23:07:01.162755 INFO controller_switchmode11_on_office: 馃弮 Running `release` now
Almost forgot...
Congrats on the new apartment by the way! 馃槂馃嵒
Thanks for the logs @htvekov, I will be looking into it and I will let you know. Now I got my setup up and running again, so I will check it out in my setup.
Congrats on the new apartment by the way!
Cheers! :)
No worries, Xavi 馃槑
Just strange that I experience this behavior on initial appdeamon startup, when code is as you've described ?
In daily use problem is non-existent 馃槉
Ciao !
Hi @htvekov,
I have been exploring this issue and apparently it was not working from me just when the light was in maximum brightness and not in minimum. Now it works well in both and it should work well when starting AppDaemon. However, I would like to confirm that you got the same problem as me. The problem came from HA, because as much as I try to put the brightness to maximum value (255), it bounces to 254:

You can observe the brightness bar is to the maximum point, but the value is 254. What I did is to change the maximum brightness value to 254 and now it works. Not sure if that is a good solution (no that anyone would notice the difference between 254 and 255), but for the moment I will keep it like this.
Let me know if you got the same behavior.
Very strange, Xavi.
Must be a bug in some implementations... ?
Are you on Deconz at the moment ?
With z2m integration i get:

And same with Hue bridge as well:

And it's the same on all type of bulbs I have. Ikea dimmable only, White Spectrum, Colour bulb, Hue colour bulbs and Hue WS bulbs.
All showing 255 as max. brightness.
Hi @htvekov,
Indeed, the configuration you saw before was from second, but I am also getting the same on z2m:

I did not go in research whose fault it is, for this reason I am leaving the max brightness to 254 for the moment.
Also I just tried the following:
Then, the brightness goes down (when first move would be to go up if the brightness is in between 1 and 254). Code is on dev if you want to try.
Thank you @htvekov :)
Hi' Xavi.
I've tested numerous times, and dimming direction is always correct now on appdeamon restart 馃憤
Still don't get the brightness 254/255 issue 馃 - But hey - it works ! 馃榿馃槑
Ciao !
Perfect! Thank you for the thorough testing :) I don't about you, but I got my light near the window and people from the street see my light going on and off constantly due to all the tests I do with it haha
I am not sure about the 254 brightness issue, but I asked a friend of mine and he also had this issue馃 As you say, it works, so I will keep it like this for the meantime
Thanks again!
My nextdoor neighbors have asked many times during the last months what I'm doing with the office lights most evenings ? 馃榿馃ぃ
No worries, Xavi ! 馃槑