[SOLVED] Hue brightness and color temperature, on / off rule

Hi I have a Hue light bulb with a brightness and a color temperature channel
Control with the OH android app works fine.
When I control it with a switch (via Rule) I have to press the button (Xiaomi hardware switch) a few times to get it to work.

Rule:

//Bedroom  switch
rule "bedlamp on/off"
when
    Channel "mihome:86sw2:158d0001641c68:ch1" triggered 
then
    if (E2Lbedlamp_dimmer.getStateAs(OnOffType) == OFF) {E2Lbedlamp_dimmer.sendCommand(100)} 
    if (E2Lbedlamp_dimmer.getStateAs(OnOffType) == ON) {E2Lbedlamp_dimmer.sendCommand(0)} 
 end

the event.log shows:

mihome:86sw2:158d0001641c68:ch1 triggered SHORT_PRESSED
2019-02-15 23:46:27.564 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 100
2019-02-15 23:46:27.568 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 100
2019-02-15 23:46:27.573 [vent.ItemStateChangedEvent] - E2Lbedlamp_dimmer changed from 0 to 100
2019-02-15 23:46:27.580 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 0
2019-02-15 23:46:27.583 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 0
2019-02-15 23:46:27.584 [vent.ItemStateChangedEvent] - E2Lbedlamp_dimmer changed from 100 to 0
2019-02-15 23:46:29.619 [vent.ChannelTriggeredEvent] - mihome:86sw2:158d0001641c68:ch1 triggered SHORT_PRESSED
2019-02-15 23:46:29.630 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 100
2019-02-15 23:46:29.631 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 100
2019-02-15 23:46:29.635 [vent.ItemStateChangedEvent] - E2Lbedlamp_dimmer changed from 0 to 100
2019-02-15 23:46:32.692 [vent.ChannelTriggeredEvent] - mihome:86sw2:158d0001641c68:ch1 triggered SHORT_PRESSED
2019-02-15 23:46:32.708 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 0
2019-02-15 23:46:32.710 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 0
2019-02-15 23:46:32.713 [vent.ItemStateChangedEvent] - E2Lbedlamp_dimmer changed from 100 to 0
2019-02-15 23:46:34.304 [vent.ChannelTriggeredEvent] - mihome:86sw2:158d0001641c68:ch1 triggered SHORT_PRESSED
2019-02-15 23:46:34.312 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 100
2019-02-15 23:46:34.323 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 100
2019-02-15 23:46:34.328 [vent.ItemStateChangedEvent] - E2Lbedlamp_dimmer changed from 0 to 100
2019-02-15 23:46:34.331 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 0
2019-02-15 23:46:34.333 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 0
2019-02-15 23:46:34.334 [vent.ItemStateChangedEvent] - E2Lbedlamp_dimmer changed from 100 to 0
2019-02-15 23:46:36.143 [vent.ChannelTriggeredEvent] - mihome:86sw2:158d0001641c68:ch1 triggered SHORT_PRESSED
2019-02-15 23:46:36.153 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 100
2019-02-15 23:46:36.154 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 100
2019-02-15 23:46:36.155 [vent.ItemStateChangedEvent] - E2Lbedlamp_dimmer changed from 0 to 100
2019-02-15 23:46:36.165 [ome.event.ItemCommandEvent] - Item 'E2Lbedlamp_dimmer' received command 0
2019-02-15 23:46:36.167 [nt.ItemStatePredictedEvent] - E2Lbedlamp_dimmer predicted to become 0

Can’t find where goes wrong.
If I send on/off instead of 0 or 100% I get the same result.

Update:
I added , autoupdate=“false” to my Item. Sill have to press the button multiple times

Use the karaf console to set the log level to DEBUG, maybe that will help identify the issue.

It may also help if you post your related items file, sometimes it’s the unexpected place that provides the answer.:wink:

Hi H102,
Thanks for you advice/input

I played a bit with autoupdate="false"

If i press a physical button on my switch, the light goes on in one click
when i wait for 5 to 10 seconds and press it again it goes off in one click/press
if I do this to quick it’s not working

Dimmer E2Lbedlamp_dimmer           "Bedlamp"                  <dimmablelight> (gSlaapkamer,gLampen,ALLE,gALLOFF)   ["Lighting"] {channel="hue:0220:00178840xxxx:6:brightness", autoupdate="false"} 
Dimmer E2Lbedlamp_dimmer_colortemp "Bedlamp kleurtemperatuur" <dimmablelight> (gSlaapkamer,gLampen,ALLE,gALLOFF)   ["Lighting"] {channel="hue:0220:00178840xxxx:6:color_temperature"}

For the moment i can live with this.
But I will dive deeper into this to find the root cause.
any input is welcome.

Hi Michiel,

Sending a brightness value of 100 % to the Dimmer channel is similar to send ON to it. Did you try to use if ... else ... in your rule instead of checking for OFF first and for ON afterwards.

Hi Christoph,

I’m familiar with the concept of on/off being more or less the same as 0 or 100%

I started out whit the if … else structure but that didn’t work correctly

Somewhere along the way someone showed me another way of doing it. (hence the two if statements)

That didn’t solve my problem at first, but then I found out that I mixup my dimmer and color temp channel in my items file.

Corrected that! But I was still working with two IF statement and autoupdate=false
Back to If … else … and removed autoupdate=“false”

Whala !!! it works and I learned something in the process

Thank you for your insight Christoph