Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle direction requires the button to be held twice #81

Closed
xaviml opened this issue May 30, 2020 · 13 comments
Closed

Toggle direction requires the button to be held twice #81

xaviml opened this issue May 30, 2020 · 13 comments
Assignees
Labels
bug Something isn't working

Comments

@xaviml
Copy link
Owner

xaviml commented May 30, 2020

Bug report

Description

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.

Solution

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.

Additional information

This bug was discovered by @htvekov. Thanks for spotting this out.

@xaviml xaviml added the bug Something isn't working label May 30, 2020
@xaviml xaviml self-assigned this May 30, 2020
@xaviml xaviml closed this as completed in 7477ebc May 31, 2020
@xaviml
Copy link
Owner Author

xaviml commented May 31, 2020

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 :)

@xaviml xaviml reopened this May 31, 2020
@htvekov
Copy link
Contributor

htvekov commented May 31, 2020

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.

@xaviml
Copy link
Owner Author

xaviml commented Jun 2, 2020

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!

@htvekov
Copy link
Contributor

htvekov commented Jun 2, 2020

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

@htvekov
Copy link
Contributor

htvekov commented Jun 2, 2020

Almost forgot...
Congrats on the new apartment by the way! 😃🍻

@xaviml
Copy link
Owner Author

xaviml commented Jun 5, 2020

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! :)

@htvekov
Copy link
Contributor

htvekov commented Jun 5, 2020

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 !

@xaviml
Copy link
Owner Author

xaviml commented Jun 6, 2020

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:

Screenshot from 2020-06-06 14-52-04

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.

@htvekov
Copy link
Contributor

htvekov commented Jun 6, 2020

Very strange, Xavi.

Must be a bug in some implementations... ?
Are you on Deconz at the moment ?

With z2m integration i get:

image

And same with Hue bridge as well:

image

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.

@xaviml xaviml closed this as completed in e9a1ba7 Jun 6, 2020
@xaviml
Copy link
Owner Author

xaviml commented Jun 6, 2020

Hi @htvekov,

Indeed, the configuration you saw before was from second, but I am also getting the same on z2m:

Screenshot from 2020-06-06 16-10-05

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:

  • Restart AppDaemon
  • Put the brightness to max (through HA). It got set to 254 in my case
  • Use toggle direction

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 :)

@xaviml xaviml reopened this Jun 6, 2020
@htvekov
Copy link
Contributor

htvekov commented Jun 7, 2020

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 !

@xaviml
Copy link
Owner Author

xaviml commented Jun 7, 2020

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!

@htvekov
Copy link
Contributor

htvekov commented Jun 7, 2020

My nextdoor neighbors have asked many times during the last months what I'm doing with the office lights most evenings ? 😁🤣

No worries, Xavi ! 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants