Control two openHAB items with just one Google Assistens Item

I have a dimmable light that is split into two things because the modbus implementation for this device is set this way:

AU.Sauna Licht Kabine (switch)
AU.Sauna Licht Kabine Helligkeit (dimmer)

I linked those to some items:

// Modbus
Group	g_AU_Sauna_Licht_Kabine_Wrapper		"Sauna Kabine"																				{ homekit="Lighting" }
Switch	AU_Sauna_Licht_Kabine				"Sauna Kabine"				(g_AU_Sauna_Licht_Kabine_Wrapper, g_AU_Licht, g_AU_Sauna)		{ ga="Light", alexa="PowerController.powerState" [category="LIGHT"], homekit="Lighting.OnState", autoupdate="false"}
Dimmer	AU_Sauna_Licht_Kabine_Helligkeit	"Sauna Kabine Helligkeit"	(g_AU_Sauna_Licht_Kabine_Wrapper)								{ homekit="Lighting.Brightness", autoupdate="false" }
String	AU_Sauna_Licht_Kabine_Name										(g_AU_Sauna_Licht_Kabine_Wrapper, g_Persist_Restore)			{ homekit="Lighting.Name" } // FĂŒr Homekit Binding, setzen per Konsole

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?

Dimming to zero does not turn the item off?

If it does you are done, if not you need to expose two things to google assistant.

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

  1. I turn it off by setting the brightness to zero
  2. I turn it on with the physical button
  3. 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.

You might be able to use a proxy item and rule like:
Item:

Dimmer	AU_Sauna_Licht_Kabine_GA				"Sauna Kabine" { ga="Light" }

Rule:

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.

2 Likes

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.

1 Like

Thank you! I’ll try these suggestions and post my final solution here :slight_smile:

1 Like

Ok, I think I have it working now with the proxy approach:

Proxy item:

Dimmer		AU_Sauna_Licht_Kabine_Proxy_GA		"Sauna Kabine"																				{ ga="Light" }

Rules:

  1. Translate commands FROM Assistant TO the real items
    1b) Fix value in GA displaying 100% after “Turn on” command sent to Assistant
  2. 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 :slight_smile:

Thanks for your help guys!

1 Like