SOLVED: Dimmer Light on Google Assistant

Hello,
I integrated in my Home Automation a shelly Dimmer2 using MQTT.
Shelly Dimmer 2 has two MQTT for dimming/switching the light:
-) A switch command (on/off).
-) A dimming command (complex JSON: switch + dimming).

I configured in my sitemap, 2 items:
-)A switch (linked to Dimmer2 Switch command channel)
-)A dimmer (linked to dimmig command channel)

Using the sitemap all is working good. I also configured the Dimmer as visible only if the switch is On.

But the problem is on Google Assistant configuration. I tryed to add metadata “ga” (light), only to dimmer Item.
In this way i can dimm and switch on or off the light but the Google Assistant Icon, is still in “on” state, also if the dimmer is off. If I switch off the dimmer, the Google Home icon switch off up to the next update.
This is frustating…
Whats wrong?

Thanks.

I guess this has to do with the way the dimmer “ON” and “OFF” state are handled. While Shelly can switch ON and OFF the unit and remember the last brightness, the default dimmer item works like: OFF means dimmer level=0%
By switching off the Shelly by sending the OFF MQTT command but not setting the dimmer level to 0%, google assistant still finds the dimmer to be ON

@bartsnijder in my opinion that’s true. I check the mqtt command and status. Sending the dimmer command with the JSON (off,0%), the dimmer reply with status “off” but with the last dimming level.
Google Assistant can only see the dimmer level and it set value 0% for “Off” and 100% for “On”.
So, as you say Google Assistant Display the On/Off status based on dimming level.
I shall try a transformation function to return brightness value 0% in case of Shally dimmer is off.

How I’ve done it so far is create a dummy dimmer item that is communicating with GA. The real dimmer/switch items (similar as you have) that control the Shelly dimmer are set via rules based on this dummy dimmer.

1 Like

I created an input transformation function for the dimmer.
Now the dimmer item value, if the dimmer object is off, became 0.

(function(dataString) {
    var data = JSON.parse(dataString);
    var brightness = data.brightness;

    if (data.ison == false) 
        brightness=0;

    return brightness;
})(input)

Now It’s work!

Although this will properly sync the OFF status will GA, this solution will loose your last dimming setting, which I would consider unwanted.
Although there is no perfect solution I’d still go for the dummy dimmer item work-around stated before.

The solution loose the last dimming set only on OpenHab Dimmer Item and Google Assistant. But not on Shelly Device. If I switch on the Shelly using the MQTT Swtch command, the dimmer value return to the last set. For me is not a problem, in my sitemap, the dimmer Item is hidden if the switch status is off.
If I force a defined brightness value, the dimming value is set to this value and the Light switched on.
If I switch on the light, the dimmer becomes visible with the last brightness value saved by the dimmer device.
Google Assistant use 0% value to switch off and 100% value to switch on, if the dimmer value become 0% for Google Assistant the light is off.

But the dimmer is via mqtt linked to the shelly device. How can you separate the 0% brightness send to GA from the 0% brightness that is sent to the dimmer?

The 0% value is only returned to the OpenHab Item, not sent to the dimmer.
0% is used only to set the Items value if the dimmer is switch off. 0 value is not sent to dimmer device.
Shelly dimmer accept Brightness value from 1 to 100.

Ah, might wonder if Shelly did not intentionally block the 0% to solve this dimmer/GA issue. Will try this alternative workaround as well.

Yess, it’s intentionally, as reported in the MQTT API Documentation:
https://shelly-api-docs.shelly.cloud/#shelly-dimmer-sl-overview