Hassio, Mosquitto Add-on, Gbridge and Google Assistant, switching a Sonoff TH16 - It works kind of

Hi All

I have managed to put the pieces in place and have a Sonoff TH16 switching both locally in Hassio and remotely in Google Assistant using gBridge.

Thing is the state of the switch is not updated properly.
The Google Assistant command “on or off” does what it should however not knowing the state is a pain. Any ideas?

As the doco on this is fragmented here is the working code you need to make it happen.

Hassio Mosquitto Gbridge Sonoff

Mosquitto Config for Hassio Add-on


{
  "logins": [],
  "anonymous": false,
  "customize": {
    "active": true,
    "folder": "mosquitto"
  },
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"
}

A new directory was created at
/share/mosquitto/mosquitto.conf

Substitute u0000 with your own user name

connection gbridge-io
address mqtt.gbridge.io:8883
bridge_attempt_unsubscribe true
bridge_protocol_version mqttv311
cleansession true
remote_username gbridge-u0000
remote_password mypassword
remote_clientid gbridge-u0000-longcomplexrandomstring
topic gBridge/u0000/+/+ both 0 "" ""
topic gBridge/u0000/+/+/set both 0 "" ""
topic cmnd/# in 0 sonoff01/ gBridge/u0000/
topic stat/# out 0 sonoff01/ gBridge/u0000/
bridge_capath /etc/ssl/certs/
bridge_tls_version tlsv1.2

Tasmota Sonoff MQTT is configured with a local user name and password.
The device is called sonoff01 in the name configuration in MQTT

Gbridge Virtual Device Config

gBridge/u0000/cmnd/sonoff01/power
gBridge/u0000/cmnd/sonoff01/POWER

Google Assistant
Link Service Kappelt gBridge

Why are you using bridge for that? Just install the Google Assistant component in Home Assistant or use Nabu Casa… mine all work fine with state correct.

Haha good question.

I have the Google API set up already if you think that is the better way happy to revisit it.

I read somewhere the Google Assistant API periodically needed to be rebuilt.

Truth or fiction?

It was more the challenge of getting the gBridge to work more than anything.

I can confirm it was a challenge.

Regards

Ross

I bet!

The manual integration I use… the simulator @ google needs to be re-enabled every 30 days BUT only if you re-sync your devices. If you don’t add/subtract anything it will go for months.

You’re just overly complicating it for no benefit IMO.

All my switches update when I issue voice commands. It works perfectly.

Thanks

I agree, the gBridge route was painful.
Checked my Google API and it is a wreck so will need to redo that.
I have a duckdns domain set up their end but guessing that needs to be integrated into Hassio with the Duck DNS addon…somehow.

Enough experimenting for the day, getting that relay to click took a lot out of me :slightly_smiling_face:

Regards
Ross

It doesn’t have to be… my duckdns is updated by a shell script… I’m running Debian/docker/hass.io but yeah… you heed a https endpoint for google to be able to talk to Home Assistant… but if you setup that bridge you can do that without breaking a sweat lol!

Regarding your gBridge setup, I found this link a useful example to work from.
Something I noticed with your setup is you have topic and prefix reversed in your sonoff device (to enable auto discovery?). So your gBridge Action and Status topics should be reversed to match this:

gBridge/u0000/sonoff01/cmnd/power
gBridge/u0000/sonoff01/stat/POWER

Also, the topic definitions in your mosquitto.conf file:

topic cmnd/# in 0 sonoff01/ gBridge/u0000/sonoff01/
topic stat/# out 0 sonoff01/ gBridge/u0000/sonoff01/

I am in the process of setting up gBridge with my tasmota devices and still learning about topic mappings, so dont take the suggestions above as gospel.