Not understood behaviour from TRADFRI Light bulb

  • Platform information:
    • Hardware: RP 3B+
    • OS: RAsbian
    • Java Runtime Environment: _No Idea
    • openHAB version: 2.5
  • Issue of the topic: Dont understand item switching to NULL
  • Please post configurations (if applicable):
    • Items configuration related to the issue

I control a TRADFRI light bulb with:

Dimmer LB1_Dimmer {channel=“hue:0220:00212E04F655:1:brightness”}
Dimmer LB1_WhiteColor {channel=“hue:0220:00212E04F655:1:color_temperature”}
Switch LB1_Switch {channel=“hue:0220:00212E04F655:1:brightness”}

  • Sitemap configuration related to the issue

        Switch item=LB1_Switch label="Lamp nachtkastje"
        Text label="Instellingen" icon="settings"
        {
            Slider item=LB1_Dimmer       label="licht gedimd op [%d %%]" icon="light"     
            Slider item=LB1_WhiteColor   label="wit temperatuur [%d %%]" icon="colorwheel"
        }
    
  • Rules code related to the issue
    NONE

  • Services configuration related to the issue
    NONE

  • If logs where generated please post the here using code fences:

I am a beginner and experimenting with a TRADFRI light bulb, the lightbulb is connected throu a CONBEEII stick and the Dresden Elektronik deCONZ Binding and Philips Hue Binding
with Thing LB1 for the bulb, with channels (from the PAPER UI)
Color Temperature
hue:0220:00212E04F655:1:color_temperature
AND
Brightness
hue:0220:00212E04F655:1:brightness

ITEMS (From a text file):
Dimmer LB1_Dimmer {channel=“hue:0220:00212E04F655:1:brightness”}
Dimmer LB1_WhiteColor {channel=“hue:0220:00212E04F655:1:color_temperature”}
Switch LB1_Switch {channel=“hue:0220:00212E04F655:1:brightness”}

Dimmer
Dimme

When I change the slider from LB1_WhiteColor to 63 when LB1_Switch=ON then I see in the logs:
2020-02-01 17:12:28.177 [nt.ItemStatePredictedEvent] - LB1_WhiteColor predicted to become 68
2020-02-01 17:12:28.204 [vent.ItemStateChangedEvent] - LB1_WhiteColor changed from NULL to 68

When I switch the lights LB1_Switch=OFF , then I see
2020-02-01 17:15:02.536 [ome.event.ItemCommandEvent] - Item ‘LB1_Switch’ received command OFF
2020-02-01 17:15:02.579 [nt.ItemStatePredictedEvent] - LB1_Switch predicted to become OFF
2020-02-01 17:15:02.606 [vent.ItemStateChangedEvent] - LB1_Switch changed from ON to OFF
2020-02-01 17:15:08.910 [vent.ItemStateChangedEvent] - LB1_WhiteColor changed from 68 to NULL
2020-02-01 17:15:08.922 [vent.ItemStateChangedEvent] - LB1_Dimmer changed from 61 to 0

The question I have is:

  1. Why does LB1_WhiteColor goes to NULL and not to 0 like LB1_Dimmer does ?
  2. Why does do LB1_WhiteColor & LB1_Dimmer change ? and why after 6 seconds?

I observe that in the paper UI both channels have hue:0220:00212E04F655:1, is that correct ?

I hope someone can help me
Best regards,
Frank

You mentioned the Thing in PaperUI giving a channel for color and brightness, as dimmer item, but nothing about a switch item.

Where did the switch item come from?

Tradfri uses 0010 for switch (power) but that is not for a bulb. A bulb for brightness and color-temp should use 0220 only and be defined as dimmer item.

H102 Thanks very much for the suggestion I changed
Switch LB1_Switch {channel=“hue:0220:00212E04F655:1:brightness”} into
Switch LB1_Switch to not connect it to a channel,

I cerated a set of rules to use a switch item , two rules :slight_smile:

var Number LB1_last_value_dimmer =100
var Number LB1_Last_value_WhiteColor

rule “Aan/Uit LB1”
when
Item LB1_Switchx received command
then
if(LB1_last_value_dimmer == null){
logInfo("LB1 ", “LB1_last_value_dimmer = NULL”)
LB1_last_value_dimmer = 100
}
if(LB1_Last_value_WhiteColor == null){
logInfo("LB1 ", “LB1_Last_value_WhiteColor = NULL”)
LB1_Last_value_WhiteColor = 55
}
logInfo(“LB1 ON/OF=”, LB1_Switch.state.toString)
if (LB1_Switch.state == ON) {
logInfo(“LB1 IN IF ON-=”, “Check DIMMER=NULL”)
if (LB1_Dimmer.state == null){
logInfo(“LB1 IN IF ON-=”, “Found NULL”)
LB1_last_value_dimmer = 100
}
if(LB1_last_value_dimmer == null){
logInfo(“LB1 IN IF ON-=”, “LB1_last_value_dimmer = NULL”)
}
logInfo(“LB1 ON-LDV=”, LB1_last_value_dimmer.toString)
logInfo(“LB1 IN IF ON-=”, “Before sent to dimmer”)
LB1_Dimmer.sendCommand(LB1_last_value_dimmer)
LB1_WhiteColor.sendCommand(LB1_Last_value_WhiteColor)
logInfo(“LB1 IN IF ON-=”, “After sent to dimmer”)
logInfo(“LB1 ON-LDIMMER=”, LB1_Dimmer.state.toString)
} else {
logInfo(“LB1 OFF LVD”, LB1_last_value_dimmer.toString)
if (LB1_Dimmer.state !== null){
logInfo(“LB1 IN IF OFF”, “BL1-Dimmer!==NULL”)
logInfo(“LB1 OFF LB1_Dimmer STATE=”, LB1_Dimmer.state.toString)
LB1_last_value_dimmer = LB1_Dimmer.state as Number
LB1_Last_value_WhiteColor = LB1_WhiteColor.state as Number
logInfo(“LB1 LDIMMERNOT NULL=”, LB1_last_value_dimmer.toString)
} else {
logInfo(“LB1 IN IF OFF”, “BL1-Dimmer==NULL”)
LB1_last_value_dimmer = 100
logInfo(“LB1 LDIMMER-NULL=”, LB1_last_value_dimmer.toString)
}
LB1_Dimmer.sendCommand(0)
}
end

rule “Warm Wit LB1”
when
Item LB1_WhiteColorx changed
then
if (LB1_WhiteColor.state == null){
logInfo(“LB1 WC Change=”, "LB1_WhiteColor.state == NULL ")
//LB1_Last_value_WhiteColor = LB1_WhiteColor.state as Number
logInfo(“LB1 WWColor=”,LB1_Last_value_WhiteColor.toString)
//LB1_WhiteColor.sendCommand(LB1_Last_value_WhiteColor
else {
logInfo(“LB1 WC Change=”, "LB1_WhiteColor.state != NULL ")
LB1_Last_value_WhiteColor = LB1_WhiteColor.state as Number
logInfo(“LB1 WWColor=”,LB1_Last_value_WhiteColor.toString)
//LB1_WhiteColor.sendCommand(LB1_Last_value_WhiteColor)
}
LB1_WhiteColor.sendCommand(LB1_Last_value_WhiteColor)
end

Mind the logging its just for me to learn how the rules work.
Now switching ON/OFF of the dimmer works fine.
I switched the rule “Warm Wit LB1” off. now when i change the colour with the slide on the BASIC UI i see the following in the logs:
020-02-02 14:43:17.028 [ome.event.ItemCommandEvent] - Item ‘LB1_WhiteColor’ received command 52
2020-02-02 14:43:17.079 [nt.ItemStatePredictedEvent] - LB1_WhiteColor predicted to become 52
2020-02-02 14:43:17.117 [vent.ItemStateChangedEvent] - LB1_WhiteColor changed from 63 to 52
I see this value also on the BASIC UI
now when i switch the lights OFF the dimmer goes to 0 but i notice the following about the color in the logs:
2020-02-02 14:54:57.343 [ome.event.ItemCommandEvent] - Item ‘LB1_Dimmer’ received command 0
2020-02-02 14:54:57.366 [nt.ItemStatePredictedEvent] - LB1_Dimmer predicted to become 0
2020-02-02 14:54:57.387 [vent.ItemStateChangedEvent] - LB1_Dimmer changed from 57 to 0
2020-02-02 14:54:58.392 [vent.ItemStateChangedEvent] - LB1_WhiteColor changed from 55 to NULL

My Question is why does LB1_WhiteColor go to NULL why does it change is that a chracteristic from TRADFRI ?

First of all, try to use code fencing, so your rules and items are better readable.

I first notice that you have an extra switch item, remove it, you won’t need it. You can use a dimmer item as a switch item.
The NULL status is I think by design, it the light is off, the channel becomes NULL.

What happend if you switch off the light and then switch it back on? What will be the LB1_WhiteColor value?

“I first notice that you have an extra switch item, remove it, you won’t need it.”

I tried that in the past but it would not recover the values the were preset before it was switched off it goes either to 0 or to 100.

" What happend if you switch off the light and then switch it back on? What will be the LB1_WhiteColor value?"

020-02-02 16:25:25.404 [ome.event.ItemCommandEvent] - Item 'LB1_WhiteColor' received command 55
2020-02-02 16:25:25.423 [nt.ItemStatePredictedEvent] - LB1_Dimmer predicted to become 48
2020-02-02 16:25:25.445 [nt.ItemStatePredictedEvent] - LB1_WhiteColor predicted to become 55
202002-02 16:25:25.456 [vent.ItemStateChangedEvent] - LB1_Dimmer changed from 0 to 48
2020-02-02 16:25:33.502 [INFO ] [clipse.smarthome.model.script.LB1_WC] - NULL/null Detected
2020-02-02 16:25:33.510 [vent.ItemStateChangedEvent] - LB1_WhiteColor changed from 55 to NULL
2020-02-02 16:25:33.518 [ome.event.ItemCommandEvent] - Item 'LB1_WhiteColor' received command 55
2020-02-02 16:25:33.520 [INFO ] [del.script.LB1_WC current set to LWC] - NULL
2020-02-02 16:25:33.534 [nt.ItemStatePredictedEvent] - LB1_WhiteColor predicted to become 55
2020-02-02 16:25:33.557 [vent.ItemStateChangedEvent] - LB1_WhiteColor changed from NULL to 55

so when going to ON the color goes to ON but reset to NULL again, i created an additional rule 


```csv
rule "Warm Wit LB1 INIT"

when

    Item LB1_WhiteColor changed to NULL

then

    logInfo("LB1_WC", "NULL/null Detected")

    if (LB1_WhiteColor.previousState() !== null){

    logInfo("LB1_WC prebious", LB1_WhiteColor.previousState().toString)

    } 

    if (LB1_WhiteColor.state !== null)  {

        if (LB1_WhiteColor.state == NULL){

            LB1_WhiteColor.sendCommand(LB1_Last_value_WhiteColor)

            //LB1_WhiteColor.previousState(LB1_Last_value_WhiteColor)

            logInfo("LB1_WC current set to LWC", LB1_WhiteColor.state().toString) 

        } 

    }

end


to recover from that , question is why does the item switch back to NULL after it is commanded to set to the last value.


Comment - a binding setting an Item state to NULL would be “bad behaviour”.
NULL should only arise when an Item is created at boot time or perhaps recreated by editing).
The UNDEF state is provided for bindings to signal “I don’t know, or it makes no sense”

Something to keep in mind as you test rules and items:

NULL - indicates an Item is not yet initialized

null - part of the language, indicates that a variable does not have a value

So you may not want to mix these up in your logInfo as it may get confusing.

@H102 , the color is set to a value and then immediatly changes to NULL what could be the cause of that ?
I deleted the same items in the paper UI some time ago and replace them with a text file in the Paper UI they are still vidible but they have no content when i edit the item.

Could that be the cause of the switch to NULL ?
How could i find out what generated that NULL other then the event in the log file ?

Many thanks
Frank

Not quite - it is sent a command, which does not set the Item state directly.
By default, openHAB’s autoupdate feature listens for commands and predicts a state for the Item, on a best-guess basis.
Here the prediction is reasonable.
But bindings can overrule autoupdate, which I think is what is going on here.

By design, PaperUI will not let you edit Items created from xxx.items files (because the editing would not be reflected in the files)

@rossko57, see the logging items below , is that what you mean by “But bindings can overrule autoupdate, which I think is what is going on here.”

2020-02-05 19:23:28.161 [ome.event.ItemCommandEvent] - Item 'LB2_WhiteColor' received command 50
2020-02-05 19:23:28.196 [nt.ItemStatePredictedEvent] - LB2_WhiteColor predicted to become 50
2020-02-05 19:23:28.526 [vent.ItemStateChangedEvent] - LB2_WhiteColor changed from 50 to NULL

is there a way to avoid that ? 

When the lamo is switched off 
 2020-02-05 19:32:38.937 [vent.ItemStateChangedEvent] - LB2_WhiteColor changed from 50 to NULL

is that correct i would expect 0 ?

Thanks in advance,
Frank

As I said, I think the binding is misbehaving in setting NuLL.
That might be because of some configuration problem, but it should still set UNDEF not NULL.

If you want to eliminate autoupdate’s prediction so that you can see more clearly what is going on with your device, you can disable autoupdate on individual Items.