OH3 Tradfri lightbulb color temperature "toggling" when widget has step property set

Hello everyone,
I just moved, installed Tradfi lightbulbs everywhere and were ready to get started with some home automation when OH3 was released, what a timing :slight_smile:

I’m running the official docker image for OH3 together with a few other services via docker-compose on a Raspberry PI 4B 8GB, using the RPi OS 64bit beta version. All of this seems to be working fine, but if you need more information regarding the setup I’d be happy to provide it.

Anyway, I followed through the OH beginner tutorial and discovery worked fine, all my lightbulbs, remote controls, motion sensors and power outlets are found. I’ve also created a semantic model, and read about the OH concepts (although I’m still getting used to all the different terms).

Now, as a next step, I’m trying to fill the overview page, and this is where I encountered my first problem. As searching these forums, issues on GitHub, and the rest of the internet via Google didn’t yield anything remotely useful, I’m now trying here, so let’s get to the actual issue.

I have the following thing, a lightbulb, configured via the UI:

UID: tradfri:0220:gw58d50ab33481:65549
label: Schreibtischlampe
thingTypeUID: tradfri:0220
  id: 65549
bridgeUID: tradfri:gateway:gw58d50ab33481

As specified in the Tradfri Binding documentation, it has two channels: brightness and color_temperature. As the title says, the issue is with the latter.

The color_temperature channel is linked with an item Schreibtischlampe_ColorTemperature (It seems I can’t access the textual specification via the UI, but the UI is all I’ve used so far).
The link uses the default profile (the problem doesn’t occur with the follow profile, it’ll become clear why).

In the overview page I added a widget to control Schreibtischlampe_ColorTemperature (doesn’t matter whether it’s a slider, stepper, or knob), here’s the slider:

component: oh-slider-card
  title: Schreibtisch
  footer: Wärme
  item: Schreibtischlampe_ColorTemperature
  min: 0
  max: 100
  label: true
  scale: true
  scaleSteps: 4
  unit: "%"

When I change the value, e.g, from 100 to 50, the color temperature actually changes to 50, but then back to 100, and then to 50, and so on and so forth, until it eventually stops somewhere.
So I’m thinking, that the default profile of the Channel<->Item link somehow simultaneously tries to set a new value, but also updates the item with the current value.
As mentioned above, this doesn’t occur with the follow profile, but that wouldn’t allow me to see when I change the color temperature outside of OH, e.g., via Google Home, because this profile doesn’t update the item with the current value (long-term I’m planning to rely on OH more and properly integrate Google Home/Assistant, but I’m obviously not there yet).
Here’s a log excerpt:

21:54:47.411 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 100
21:54:47.414 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 100
21:54:47.418 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 50 to 100
21:54:47.502 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 100 to 49
21:54:47.520 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 49 to 52
21:54:47.569 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 50
21:54:47.573 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 50
21:54:47.581 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 52 to 50
21:54:49.483 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 50 to 97
21:54:49.508 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 97 to 50
21:54:49.518 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 100
21:54:49.534 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 100
21:54:49.539 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 50 to 100
21:54:51.484 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 100 to 49
21:54:51.505 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 49 to 100
21:54:51.524 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 50
21:54:51.531 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 50
21:54:51.537 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 100 to 50
21:54:53.488 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 50 to 97
21:54:53.505 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 97 to 50
21:54:53.508 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 100
21:54:53.519 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 100
21:54:53.527 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 50 to 100
21:54:55.497 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 100 to 49
21:54:55.521 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 49 to 100
21:54:55.567 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 50
21:54:55.578 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 50
21:54:55.587 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 100 to 50
21:54:57.491 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 50 to 97
21:54:57.510 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 100
21:54:57.519 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 100
21:54:57.523 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 97 to 50
21:54:57.528 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 50 to 100
21:54:59.492 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 100 to 49
21:54:59.511 [INFO ] [openhab.event.ItemCommandEvent       ] - Item 'Schreibtischlampe_ColorTemperature' received command 50
21:54:59.522 [INFO ] [openhab.event.ItemStatePredictedEvent] - Item 'Schreibtischlampe_ColorTemperature' predicted to become 50
21:54:59.526 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 49 to 100
21:54:59.536 [INFO ] [openhab.event.ItemStateChangedEvent  ] - Item 'Schreibtischlampe_ColorTemperature' changed from 100 to 50

If someone knows how to resolve this - great!
But I’d also be happy about hints where to look further, or ways to narrow down the source of the problem.
Questions I’ve got in my head currently:

  • Is there a problem on my side, or is this a bug?
  • If it is a bug, is it somewhere on OH’s core, maybe the implementation of the default profile, or rather in the Tradfri binding?
  • What could be my next steps? Should I open an issue on GitHub?

Sorry for this wall of text, I just wanted to make sure everything relevant is included. If you need any more information I’ll gladly provide it, but currently I just don’t know how to continue.
Thanks in advance!

I don’t use Tradfri so am not sure, but perhaps the binding isn’t converting the Color Temperature value. To be more clear most bulbs measure color temperature as a value between 2000K and 6500K, I do know the HUE binding has logic which converts the values to a percentage.

I would try linking the channel as a number and then seeing what value the UI displays when viewing it via the items - you may need to set the default widget to a label.

Thanks for the input!

I did as you suggested and created another Item of type Number (or Number:Dimensionless, same outcome). I linked it to the color_temperature channel using the default profile again, then went to the Item’s page to observe the value (I did not have to set a default widget).
For the experiment, I used the Google Home app to change the color temperature, and on the Item page I could see it takes values in the interval [0, 1].
So from my perspective any potential conversions look fine.
However, when I created a widget in the Overview page to control the value of the new Item, the changes don’t propagate to the lightbulb. The other direction (change via Google Home) is working fine though, i.e., such external changes are shown by the widget. Altogether this is probably unrelated to the original issue so I didn’t investigate this much further.

On the other hand, I may have found some new information while doing this:
It seems the problem only occurs when I have the overview page open in my Browser.
Without it, when setting the color temperature via the slider on the Item page (I’m talking about the original Schreibtischlampe_ColorTemperature now), everything works as expected.
When I open the overview page in another tab, the lightbulb goes crazy again (admittedly, at least it looks funny).

As the original Schreibtischlampe_ColorTemperature slider works, I would think your issue is an issue with the widget on the overview page - I don’t have much experience with widgets yet (am just starting to get to those), but perhaps others will be able to help more if you post more details of the overview page configuration.

Thanks again for the suggestion :slight_smile:

So I tried creating a minimal “working” example (MWE) of my overview page to post here, and couldn’t reproduce the issue with the slider.
However, when using a stepper (which I’d prefer because I don’t need 100 warmth levels for my lights), the problem was back.
Now the difference in configuration between slider and stepper (apart from them being different things), was that for the stepper I configured the step property to 25 (because 4 different warmths suffice).
I then went on to configure a step of 25 for the slider, and here we go, problem’s back!

So, this is working (only posting the widget YAML because the rest seems irrelevant now):

component: oh-slider-card
  title: Schreibtisch
  footer: Wärme
  item: Schreibtischlampe_ColorTemperature
  min: 0
  max: 100
  label: true
  scale: true
  scaleSteps: 4
  unit: "%"

Color temperature toggling between old and new value (eventually stops at one or the other):

component: oh-slider-card
  title: Schreibtisch
  footer: Wärme
  item: Schreibtischlampe_ColorTemperature
  min: 0
  max: 100
  label: true
  scale: true
  scaleSteps: 4
  unit: "%"
  step: 25

I think that narrows it down pretty nicely to the step property!

My next step was to try and find the source code for the slider, and while OH has a huge codebase I don’t know anything about (yet), I managed to find this file.
It contains the following code, which may or may not be relevant to the issue:

toStepFixed (value) {
      // uses the number of decimals in the step config to round the provided number
      if (!this.config.step) return value
      const nbDecimals = Number(this.config.step).toString().replace(',', '.').split('.')[1]
      return parseFloat(Number(value).toFixed(nbDecimals))
    onChange (value) {
      const newValue = this.toStepFixed(value)
      if (newValue === this.value) return
      if (this.config.variable) {
        this.$set(this.context.vars, this.config.variable, value)
      } else if (this.config.item) {
        this.$store.dispatch('sendCommand', { itemName: this.config.item, cmd: newValue.toString() })

Assuming the code above has something to do with the issue (which is by no means certain), only the following two lines could have an impact (because of the if (!this.config.step) return value before):

const nbDecimals = Number(this.config.step).toString().replace(',', '.').split('.')[1]
return parseFloat(Number(value).toFixed(nbDecimals))

As can be seen above, my step value doesn’t have any decimal places, and the behavior is just the same when I use 25.0 or "25.0" (25,0 yields NaN in the label, and "25,0" is just automatically converted to the former by the built-in editor(?)).

I think there may be an error here, because if I’m not mistaken, the expression in the first line (which is supposed to calculate the number of decimal places) actually just yields the decimal places as a string, e.g, 1.234 -> “234”, also, if there are no decimals at all, the result is undefined.

Anyway, most of this is just speculation, I am no web developer and may just be overlooking something.
The code is written by @ysc, so now speaking directly to you:
First of all, I apologize if any of the above comes across as rude.
It’s not meant to be, I’m honestly just trying to help (well, myself, but also anyone who may encounter this issue as well).
Even if everything is fine with the code shown above, I’m certain you know more about the widgets, especially the slider, than most if not all other people.
Therefore, I’d kindly like to ask you to have a thought or two about this and share them if possible.

Finally, thanks to anyone who reads this :smiley:

Edit: I’ve edited thread title and tags to try and reflect what has been found out since its creation.
Edit2: Something similar happens when I define a step for my brightness sliders, so this is not limited to color temperature.

Sliders are the worst, even in HABPanel those never worked so great. Most of the time the issue is that the slider sends a command, or multiple commands for those widgets where you can drag a cursor and it updates as you do, then the runtime reacts and you get a delayed state update.

Sometimes you only get a little glitch, like if the update is a so delayed it comes after the “debounce” interval so the slider gets back to a previous position for a fraction of a second, and if the new state doesn’t happen to be the current state of the slider, it fires its own “changed” event and send the command again and you get in a loop. Or you got a floating point error. That’s why the code to deal with this stuff is so convoluted, especially when dealing with decimal steps… It was mosly trial and error with my Hue lights, and others, trying different techniques to try and alleviate these kinds of problems, until I got to something I was satisfied with.

But now you seem to have run into another one. So back to the drawing board I guess. Thanks for the detailed report, it’ll help.

I have seen rude many times these days, believe me, and you’re not!

Thanks for the explanation and for taking care of this.
If you need someone for testing, let me know.
For now I’m marking your reply as the solution.