[SOLVED] ON/OFF value to Dimmer type?

Hi Everyone!

I have made some changes to my Google Assistant setup and now I had time to check it out. However one thing doesn’t really work.

I have set a tag to a Dimmer item (which controls one Wifiled Things Brightness channel if that matters), but if I want to turn on, it won’t work (looks like it doesn’t accept ON/OFF value on a Dimmer). Is this true? How can I setup this easily?


No, in general Dimmer Item supports ON and OFF command, but the linked channel has to support ON/OFF command, too. You could use a simple rule:

rule "send number in addition of ON/OFF"
    Item myDimmerItem received command
    switch (receivedCommand) {
        case ON       : myDimmerItem.sendCommand(100)
        case OFF      : myDimmerItem.sendCommand(0)
        case INCREASE : myDimmerItem.sendCommand((myDimmerItem.state as Number) + 5)
        case DECREASE : myDimmerItem.sendCommand((myDimmerItem.state as Number) - 5)

This will “translate” the commands ON, OFF, INCREASE and DECREASE to a set level command. In fact, INCREASE and DECREASE are often unused (but you will need them for classic UI)

Thanks for your help! I also thought of something like this but I would appriaciate that the binding would know this by default.

I have also made sure that there is nothing wrong on the myopenhab/google side, if I inject an ON command to a brightness channel, it wouldn’t want to turn on…

I don’t know the binding. Maybe there is a switch channel in addition? then simply link both channels to one dimmer item!

Yes it has a switch (with ON/OFF) also. Will it work with that?

How should I link both channels to an item (haven’t done this before)? like

{ channel="...", channel="..." } ?

Jep, this should work. openHAB should automagically send the commands to the suitable channel.

It seems it is working.
However I have two problems:

  • I get some mysql database error that it can’t fit this long value into the table. Should I clean the database to solve this?
  • Now if I turn it on, it always turns on at 100%, not at the last state. Can I somehow change this to remember the last state?
  • Also it is always updating it’s channel like this (the lamp is not changing state):
wifiled_livingroom changed from 0 to 100.000

and then back to 0…

Should the wifiled do this (or does this work when openHAB does not control the wifiled)?

If yes, then something is wrong with the configuration. Time to investigate…
If no, then yes, it’s possible to do this with some code:
the Item has to be persisted with some database, e.g. MySQL or influxDB. rrd4j may work. persistence setting would be at least everyChange.

rule "set last known brigthness"
    Item myWifiLed received command ON
    if(myWifiLed.state as Number == 0)

So when receiving the ON command, the Item will be set to the last level (before it was set to 0). As this will only work, if the ON-command did not switch on the light yet, the best way to achieve a relieable solution would be, to use a proxy Item.

Another option would be to store the last known state:

var Number nMyWifiLedLevel

rule "set last known brigthness"
    Item myWifiLed changed to 0
    nMyWifiLedLevel = previousState as Number

rule "set last known brigthness" // if set
    Item myWifiLed received command ON
    if(nMyWifiLedLevel instanceof Number)

No need for persistence here, but this will only work as long as openHAB was not (re)started recently.