Control Sonoff Tasmota with Google Assistant

This guide will guide explain how to use and integrate your Tasmota devices (like Sonoffs, Shellys, etc.) with Google Assistant. Unlike other guides, you neither need Hue Emulation nor need to open any ports in your firewall (port forwarding) when using this method. You only need to follow these steps.

Create a gBridge Account is a service that basically bridges Google Assistant and a MQTT server. When a command is sent via Google Assisant, a MQTT message will be published. Just open the project page, click on register and enter your information. After clicking the confirmation link in the email you’ll receive, your account is ready to go!

Setup the local MQTT broker

You should only connect to gBridge over TLS encrypted MQTT, because this control data is transfered over the internet. However, tasmota does not support encrypted MQTT (due to constrainted hardware resources).
To overcome this problem, a local MQTT broker (e.g. Mosquitto) needs to be configured in your local network. This server could run on a small device that is already available in your network, like a NAS or a Raspberry Pi.

This setup will ensure encrypted communication to gBridge’s MQTT servers, while providing plain MQTT in your local network for the Tasmota devices.

Local MQTT proxying

Any data from gBridge is proxied by your local Mosquitto instance and then forwarded to your local devices. This works the other way around, too.

When registering for gBridge, information for connecting to its MQTT server (including hostname and username) will be written in the confirmation mail. You may always access these information in the gBridge dashboard under “My Account”.
The following config has been proven to work for Tasmota devices (edit the file /etc/mosquitto/mosquitto.conf). Your MQTT password is your account’s password by default, but it may be changed independently of it in the “My Account” panel (e.g. if you have separate IoT passwords)

connection gbridge-io
bridge_attempt_unsubscribe true
bridge_protocol_version mqttv311
cleansession true
remote_username gbridge-u{userid}
remote_password {mqtt-password}
remote_clientid gbridge-u{userid}-{random-alphanumeric-characters}

topic cmnd/# in 0 sonoff/ gBridge/u{userid}/
topic stat/# out 0 sonoff/ gBridge/u{userid}/
bridge_capath /etc/ssl/certs/
bridge_tls_version tlsv1.2

Enter your information there. For example, the config for the user with the username “gbridge-u7” should look similar to this:

connection gbridge-io
bridge_attempt_unsubscribe true
bridge_protocol_version mqttv311
cleansession true
remote_username gbridge-u7
remote_password mysupersecretpassword
remote_clientid gbridge-u7-qvy74EDmdWRGMkSa

topic gBridge/u7/+/+ both 0 "" ""
topic gBridge/u7/+/+/set both 0 "" ""
topic cmnd/# in 0 sonoff/ gBridge/u7/
topic stat/# out 0 sonoff/ gBridge/u7/
bridge_capath /etc/ssl/certs/
bridge_tls_version tlsv1.2

Restart mosquitto after editing the config (e.g. “sudo systemctl restart mosquitto”). Look out for these lines in the log file (e.g. /var/log/mosquitto.log or /var/log/mosquitto.log) after restarting – they indicate success:

[email protected]:~ $ sudo tail /var/log/mosquitto/mosquitto.log -n 20
1532876260: mosquitto version 1.4.10 (build date Fri, 22 Dec 2017 08:19:25 +0000) starting
1532876260: Config loaded from /etc/mosquitto/mosquitto.conf.
1532876260: Opening ipv4 listen socket on port 1883.
1532876260: Opening ipv6 listen socket on port 1883.
1532876260: Connecting bridge gbridge-io (

Configure Tasmota

Flash Tasmota to your Sonoff, Shelly or whatever. The guys from Tasmota are providing fairly extensive manuals for that purpose, thus I won’t go into any details here. For the following examples I’ve used an Sonoff S20, but it won’t be any different for most other devices.

The first step is to setup your wifi and give the device a name, if you like. Afterwards, go to “Configuration”, “Configure MQTT” and enter the following information:

  • Host: URL/ IP of your local MQTT broker that has been configured to work with gBridge
  • Port: Usually 1883, unless you’ve configured something different for your broker
  • Client: Leave default
  • Username/ Password: Leave empty, unless your local broker requires authentication (not the case for default mosquitto configuration)
  • Topic: An unique alphanumeric name for your Tasmota device. Note it, since it is going to be necessary later.
  • Full Topic: Use “sonoff/%prefix%/%topic%/”

Click save, your device should restart. Have a look at the tasmota log, these lines indicate success:

00:00:06 MQT: Attempting connection...
00:00:06 MQT: Connected

Create a virtual device

Almost done here! You now need to create a device in the gBridge account panel that is going to be shown in your Google Home app. Click on the “Add Device” button there, give a name you’d like Google to listen to. Select “Switch” or “Outlet” as the device type, while only selecting “On and Off” as the supported trait.

After creating the virtual device, click its “Edit” button again, to change the necessary MQTT topics. Use the following:

  • Use “cmnd/{tasmota-mqtt-name}/power” as the so called “Action topic”
  • Use “stat/{tasmota-mqtt-name}/POWER” as the “Status topic”. Not the necessary (and intended) case difference in the word “POWER” here.
I’ve entered these settings for my device “sonoff01”

Click on “Save Settings”.

Link gBridge to your Google Home

Now, open your Google Home app. There should be a button “Add Devices”. Select the category “Works with Google”, look out for “Kappelt gBridge” in the list.

Log into your account.

Now, the newly created device should appear in the Google Home app. You may assign it to a certain room for extended features.

Test it

Now, everything should work a treat! Say “Hey Google, turn on {your device name}”. If everything worked well, your Tasmota should now turn on.

Say the Google Home command…
… and your Tasmota device will be turned on!

There are other commands, too: You may always ask Google whether your outlet is turned on (“Hey Google, is {outlet name} turned on?”). This will always report the current state, even if your device has been turned off manually.

Always have a look at the documentation of gBridge, too. Up-to-date information is added there regularly.

4 Replies to “Control Sonoff Tasmota with Google Assistant”

  1. Very helpful article, thanks. One thing I dont understand is why you have the bridge topic statements:
    topic gBridge/u7/+/+ both 0 “” “”
    topic gBridge/u7/+/+/set both 0 “” “”
    They dont serve any purpose for the sonoff device pub/sub messages do they?

  2. Hi, thanks a lot for your article. I have a problem. I have a virtual machine in google cloud, with mosquitto and nodered and lets encrypt certbot system working.
    Borker’s 8883 port works perfectly.

    In my local openwrt router, I have installed mosquitto broker. Nothing about certificates neither lets encrypt.

    I want to bride my local broker to my cloud broker, as your article.

    My problem is that bridge_capath /etc/ssl/certs/ is empty in my local openwrt.

    I have checked bridge with 1883 port. Works.
    But with 8883 port doesnt work. This is what I get in my local broker:
    OpenSSL Error[0]: error:1416F086:lib(20):func(367):reason(134)

    Could you understand what is happening? Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.