Controllerx: Toggle direction requires the button to be held twice - reintroduced

Created on 14 Aug 2020  路  9Comments  路  Source: xaviml/controllerx

Hi' Xavi

Bug from issue https://github.com/xaviml/controllerx/issues/81 unfortunately has reappeared in latest beta.

Description

Second HOLD press is needed to start dimming down after on_full_brightness or sync has been called.
Same behaviour on my Xiaomi button on same light if on_full_brightness is called via double click.

If light is toggled / turned on to full brightness from HA or another automation, dimming direction is OK on first hold.

Additional information

  • Devices involved:

    • Model: Tasmota as Light Controller

  • Integration: z2m
  • AppDaemon version: v0.2.6
  • ControllerX version: v3.4.0b1
  • HACS version: v1.3.3
  • Home Assistant Core version: v0.112.3

AppDaemon app configuration

controller_switchmode11_on_office:

  module: controllerx
  class: LightController # E1810Controller
  controller: office_cmnd # Specify z2m friendly name
  integration:
    name: z2m
    listen_to: mqtt
    action_key: action # Defaults to action if not specified
  light: light.0xec1bbdfffed45c3b_light
  add_transition_turn_toggle: false
  mapping:
    #toggle: toggle
    inc-dec: hold_brightness_toggle
    clear: release
    double: on_full_brightness

Logs


Lights on at brightness:1
Then double press to run ON_FULL_BRIGHTNESS
Then HOLD to start dimming down - but no action on first HOLD ?

2020-08-14 22:37:28.117956 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-08-14 22:37:28.124098 INFO controller_switchmode11_on_office:   - entity_id: light.0xec1bbdfffed45c3b_light
2020-08-14 22:37:28.129182 INFO controller_switchmode11_on_office:   - brightness: 1
2020-08-14 22:37:28.134303 INFO controller_switchmode11_on_office:   - transition: 0.25
2020-08-14 22:37:28.574160 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `clear`
2020-08-14 22:37:28.577626 INFO controller_switchmode11_on_office: 馃弮 Running `release` now
2020-08-14 22:38:39.396823 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `double`
2020-08-14 22:38:39.400521 INFO controller_switchmode11_on_office: 馃弮 Running `on_full_brightness` now
2020-08-14 22:38:39.409238 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-08-14 22:38:39.414049 INFO controller_switchmode11_on_office:   - entity_id: light.0xec1bbdfffed45c3b_light
2020-08-14 22:38:39.419533 INFO controller_switchmode11_on_office:   - brightness: 254
2020-08-14 22:38:39.424289 INFO controller_switchmode11_on_office:   - transition: 0.30
2020-08-14 22:38:42.508253 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `inc-dec`
2020-08-14 22:38:42.513293 INFO controller_switchmode11_on_office: 馃弮 Running `hold_brightness_toggle` now
2020-08-14 22:38:42.535607 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-08-14 22:38:42.543310 INFO controller_switchmode11_on_office:   - entity_id: light.0xec1bbdfffed45c3b_light
2020-08-14 22:38:42.548531 INFO controller_switchmode11_on_office:   - brightness: 254
2020-08-14 22:38:42.553733 INFO controller_switchmode11_on_office:   - transition: 0.25
2020-08-14 22:38:46.057904 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `clear`
2020-08-14 22:38:46.062035 INFO controller_switchmode11_on_office: 馃弮 Running `release` now

Second HOLD and dim down starts

2020-08-14 22:40:16.440450 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `inc-dec`
2020-08-14 22:40:16.443879 INFO controller_switchmode11_on_office: 馃弮 Running `hold_brightness_toggle` now
2020-08-14 22:40:16.453591 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-08-14 22:40:16.460127 INFO controller_switchmode11_on_office:   - entity_id: light.0xec1bbdfffed45c3b_light
2020-08-14 22:40:16.465761 INFO controller_switchmode11_on_office:   - brightness: 221.38
2020-08-14 22:40:16.471117 INFO controller_switchmode11_on_office:   - transition: 0.25
2020-08-14 22:40:17.236384 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-08-14 22:40:17.241662 INFO controller_switchmode11_on_office:   - entity_id: light.0xec1bbdfffed45c3b_light
2020-08-14 22:40:17.246773 INFO controller_switchmode11_on_office:   - brightness: 189.75
2020-08-14 22:40:17.251911 INFO controller_switchmode11_on_office:   - transition: 0.25
2020-08-14 22:40:17.560026 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-08-14 22:40:17.565193 INFO controller_switchmode11_on_office:   - entity_id: light.0xec1bbdfffed45c3b_light
2020-08-14 22:40:17.570229 INFO controller_switchmode11_on_office:   - brightness: 158.12
2020-08-14 22:40:17.575231 INFO controller_switchmode11_on_office:   - transition: 0.25
2020-08-14 22:40:17.878652 INFO controller_switchmode11_on_office: 馃 Service: light.turn_on
2020-08-14 22:40:17.885301 INFO controller_switchmode11_on_office:   - entity_id: light.0xec1bbdfffed45c3b_light
2020-08-14 22:40:17.890429 INFO controller_switchmode11_on_office:   - brightness: 126.50
2020-08-14 22:40:17.895505 INFO controller_switchmode11_on_office:   - transition: 0.25
2020-08-14 22:40:18.008523 INFO controller_switchmode11_on_office: 馃幃 Button event triggered: `clear`
2020-08-14 22:40:18.017036 INFO controller_switchmode11_on_office: 馃弮 Running `release` now
bug

All 9 comments

Hi @htvekov,

Thank you for spotting this out. Apparently, this error is not coming from ControllerX like last time. I tried to reproduce what you specified and indeed, it does not work. The problem comes form the "on_full_brightness" or "sync" actions. You can see in the time 2020-08-14 22:38:39.419533 that brightness is set to 254 (the maximum value for brightness that I established to fix the previous bug). However, if you check the brightness attribute at that point, you will see is 253 in HA. I don't know if this is a problem from AppDaemon or from HA. The thing is that when running the toggle direction since the value is 253, it goes up to make it 254, which you can see in the service from 2020-08-14 22:38:42.535607.

To fix this once and for all, I will established a 5 or 10% boundary that will define if the direction should go down or not. For example:

  • If the brightness is within a 5% margin from the maximum brightness, then the brightness will go down
  • If the brightness is not within the 5% margin from the maximum brightness and the previous direction was up, then the brightness goes down.
  • If the brightness is not within the 5% margin from the maximum brightness and the previous direction was down, then the brightness goes up.

I hope with this, we will be able to not get this problem again.

Thanks for reporting this.
Xavi M.

Hi @htvekov,

This bug has been solved in ControllerX v3.4.0b2. I put this under test now and I also tried it out. However, if you could try it out, I would appreciate it. As I mentioned before, everything that is inside the minimum or maximum area (5% margin), counts as minimum or maximum. So if the brightness is 1 minimum and 255 maximum, a 5% margin would be ~12, so everything from [243, 255] should count as it is in a max value so it will trigger the brightness to go down. The same would be applied to the minumum.

Thanks,
Xavi M.

Hi' @xaviml

Didn't really notice (until now) that z2m lights actually maxed out at 253 in HA even though they should be at 254 ??
Problem must be HA's z2m integration, as my Hue bridge lights max out at 254 - as expected with your current max setting.
This made me google (again 馃槈) and I actually found something interesting from Koenkk https://github.com/Koenkk/zigbee2mqtt/issues/4035
Issue has recent posts and has just been closed some 3 days ago, so this is something that Koenkk has been working on lately in edge version. I'm on stable z2m version atm., so I'm not affected by any recent code change.

It seems that correct max brightness for numerous (all ??) bulbs is actually 254 and not 255. 255 is a reserved (default) value.
I believe that many (but not all) of Koenkk's z2m converters 'fiddle' with the brightness value recieved to cope with brightness 0 to turn off bulb etc.

So with v3.4.0b1 ControllerX max. brightness stops at at 254 and HA brightness value for z2m Ikea bulb is 253
with latest v3.4.0b2 ControllerX max. brightness now stops at 255 and HA brightness value for z2m Ikea bulb is now 254 ??
It seems like z2m sets brightness at level received -1 no matter what or.... ??

Anyway, dimming direction is working perfectly now using sync and on_full_brightness via z2m 馃憤馃榿
Haven't tested on bulbs via Hue integration yet though.

Ciao !

So with v3.4.0b1 ControllerX max. brightness stops at at 254 and HA brightness value for z2m Ikea bulb is 253
with latest v3.4.0b2 ControllerX max. brightness now stops at 255 and HA brightness value for z2m Ikea bulb is now 254 ??

Correct for the v3.4.0b1 since it is what I found out. Now in v3.4.0b2 the max brightness is back again to 255 as it already was a couple of releases ago. Now that the max brightness is 255, not sure if the max brightness in HA is still at 253 when running on_full_brightness, I didn't check that. However, it does call the service with a 255 which is what I tested as well as checking that the toggle direction works on the 5% margin. This will help reduce problems in the future with this matter.

Cheers,
Xavi M.

It seems that correct max brightness for numerous (all ??) bulbs is actually 254 and not 255. 255 is a reserved (default) value.
I believe that many (but not all) of Koenkk's z2m converters 'fiddle' with the brightness value recieved to cope with brightness 0 to turn off bulb etc.

I left the max brightness back to 255 since it is the maximum value accepted by Home Assistant: https://developers.home-assistant.io/docs/core/entity/light/ There is also no difference to the human eye between 253, 254 and 255 level of brightness.

Both sync and on_full_brightness with z2m integration results in HA brightness at 254
And you're right abought brightness 253-255. You can't visually observe any difference

Indeed, they might already clip the value to not be higher than 254 then.

Anyway, thank you for reporting this error @htvekov :)

Edit: I will close the ticket once it is shipped to v3.4.0

Just had a quick test with Hue integration.
HA reports brightness at 255 after both sync and on_full_brightness has been issued.
Dimming direction also correct at first press 馃憤馃榿馃槑

This issue has been fixed in ControllerX v3.4.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

silbats picture silbats  路  10Comments

fribse picture fribse  路  6Comments

EPMatt picture EPMatt  路  5Comments

Crocmagnon picture Crocmagnon  路  11Comments

bobbynobble picture bobbynobble  路  5Comments