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"
when
Item myDimmerItem received command
then
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)
}
end
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…
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"
when
Item myWifiLed received command ON
then
if(myWifiLed.state as Number == 0)
myWifiLed.sendCommand(myWifiLed.previousState(true).state)
end
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"
when
Item myWifiLed changed to 0
then
nMyWifiLedLevel = previousState as Number
end
rule "set last known brigthness" // if set
when
Item myWifiLed received command ON
then
if(nMyWifiLedLevel instanceof Number)
myWifiLed.sendCommand(nMyWifiLedLevel)
end
No need for persistence here, but this will only work as long as openHAB was not (re)started recently.