My goal is to be able to control this light with one item in Google Assistant. Currently I can only turn it on / off (which makes sense of cource because I have the tag on the switch item).
For homekit I can achieve this just fine because the characteristics (on/off, dimmer level) can be set to different items in a group, but the Google Assistant binding does not seem to support something like that.
How can I control these two openHAB items with just one Google Assistent item?
It does turn it off, but on the physical light switch there ist a âpower on/offâ button that restores to the latest brightness. Thatâs the main reason I want to keep things seperated. Sorry I forgot to mention this.
So
I turn it off by setting the brightness to zero
I turn it on with the physical button
Nothing happens, itâs âonâ now at 0 percent brightness
There must be some fancy workaround using proxy items and/or rules but I canât wrap my head around that yet.
rule "Google assistant sauna light"
when
Item AU_Sauna_Licht_Kabine_GA received command
then
if (receivedCommand instanceof OnOffType) {
AU_Sauna_Licht_Kabine.sendCommand(receivedCommand)
} else {
AU_Sauna_Licht_Kabine_Helligkeit.sendCommand(receivedCommand)
}
end
I havenât tested, so might need tweaking, but something like this should work I believe.
You might be able to use the previousState extension to restore the dimmer value whenever the dimmer value is set to 0 by Google Assistant. You would use the dimmer item as your GA item, and whenever it goes to zero you have a rule set the switch item to OFF and restore the previous brightness.
Alternatively, you could have a rule that when your switch turns to ON (because you pressed the button), openHAB restores brightness to the previous state.
I like that the first rule does the work immediately, but your hardware might work better with the second rule.
Translate commands FROM Assistant TO the real items
1b) Fix value in GA displaying 100% after âTurn onâ command sent to Assistant
Translate ON/OFF or brightness changes FROM real item TO Assistant
Maybe some edge cases (null items etc.) are still missing.
rule "Sauna Kabine Proxy Google Assistant - FROM proxy TO real item" // 1
when
Item AU_Sauna_Licht_Kabine_Proxy_GA received command
then
if (receivedCommand instanceof OnOffType) {
AU_Sauna_Licht_Kabine.sendCommand(receivedCommand)
} else if (receivedCommand.toString == "0") {
AU_Sauna_Licht_Kabine.sendCommand("OFF")
} else {
AU_Sauna_Licht_Kabine.sendCommand("ON")
AU_Sauna_Licht_Kabine_Helligkeit.sendCommand(receivedCommand)
}
end
// Fix value in GA displaying 100% after "Turn on" command sent to GA
rule "Sauna Kabine Proxy Google Assistant - FROM proxy TO real item (fix)" // 1b
when
Item AU_Sauna_Licht_Kabine_Proxy_GA received update
then
if (AU_Sauna_Licht_Kabine.state.toString == "ON" &&
AU_Sauna_Licht_Kabine_Proxy_GA.state.toString != AU_Sauna_Licht_Kabine_Helligkeit.state.toString) {
if (AU_Sauna_Licht_Kabine_Helligkeit.state == NULL) {
logWarning("Licht", "AU_Sauna_Licht_Kabine_Helligkeit NULL")
return;
}
AU_Sauna_Licht_Kabine_Proxy_GA.postUpdate(AU_Sauna_Licht_Kabine_Helligkeit.state.toString)
}
end
rule "Sauna Kabine Proxy Google Assistant - FROM real item TO proxy" // 2
when
Item AU_Sauna_Licht_Kabine changed or
Item AU_Sauna_Licht_Kabine_Helligkeit changed
then
if (AU_Sauna_Licht_Kabine.state == NULL) {
logWarning("Licht", "AU_Sauna_Licht_Kabine NULL")
return;
}
if (AU_Sauna_Licht_Kabine.state.toString == "ON") {
if (AU_Sauna_Licht_Kabine_Helligkeit.state == NULL) {
logWarning("Licht", "AU_Sauna_Licht_Kabine_Helligkeit NULL")
return;
}
AU_Sauna_Licht_Kabine_Proxy_GA.postUpdate(AU_Sauna_Licht_Kabine_Helligkeit.state.toString)
} else {
AU_Sauna_Licht_Kabine_Proxy_GA.postUpdate("OFF")
}
end
So now everything is working but I needed 3 rules for it. I have a feeling that there might be a simpler approach, so if anybody knows how to simplify this Iâm quite interested