Custom Govee Bluetooth to Wifi Hub -Works with Node-RED and Alexa

I didn’t directly make this for HomeAssistant but I figure I’d share it here since I didn’t know a better place to share home automation stuff like this. But you can add it into home assistant.

I recently inherited a Govee RGBIC LED Strip (Govee H617C - https://www.amazon.com/gp/product/B099S9DXT7/) and I wanted to control it with Alexa through Node-RED,

I tried looking for any available hubs that would convert wifi signals to bluetooth signals but the only one I came across didn’t work with Govee Lights.(https://www.amazon.com/MOES-Fingerbot-Compatible-Multiple-Fingerbots/dp/B09TVX3QX3).

So I decided to make my own.

I didn’t have a lot of background knowledge on how BLE devices communicate so I had to do some research. I’ll share some of the resources that helped me with this endeavor.

Prerequisites:

  1. Working Node-RED installation
  2. Working Mosquitto installation
  3. Mqtt-launcher (GitHub - jpmens/mqtt-launcher: Execute shell commands triggered by published MQTT messages) installed on the hub device you choose
  4. A cheap device capable of connecting to bluetooth low energy devices to use as a dedicated hub. A Raspberry Pi will work or in my case I had an Intel Compute Stick STCK1A8LFC laying around doing nothing and I installed xubuntu on it.

On your device of choice you will want to create a directory in your home dictortory to store the control scripts.

Create the following files and chmod them to be executable. Except the text file which should be readable and writable.

~/Documents/bluetooth

  • keepalive.sh
  • writelightsoff.sh
  • writelightson.sh
  • lights.txt

The contents of each file are below.

keepalive.sh - Change XX:XX:XX:XX:XX:XX to the Mac Address of your govee lights.

#!/bin/bash

reapeat=true
value="aa010000000000000000000000000000000000ab" 
alive=$(gatttool -i hci0 -t random -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x0014 -n $value) 


while [ "$reapeat" = true ]
do
	# device connected, keep alive and wait for on off command
	while [ "$alive" = "Characteristic value was written successfully" ]
	do
		# check if lights.txt has content
		if [ -s lights.txt ]
		then
		# read value
		value=$(<lights.txt)
		# make file blank
		>lights.txt
		else
		value="aa010000000000000000000000000000000000ab"
		fi

		# excute command
		alive=$(gatttool -i hci0 -t random -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x0014 -n $value)
		value="aa010000000000000000000000000000000000ab"

		sleep 1

	done

	# keep trying to connect to device
        alive=$(gatttool -i hci0 -t random -b XX:XX:XX:XX:XX:XX --char-write-req -a 0x0014 -n $value)

done

writelightsoff.sh - Be sure to change the path to point to your appropriate directory.

#!/bin/bash

echo "3301000000000000000000000000000000000032" > /home/CHANGEME/Documents/bluetooth//lights.txt

writelightson.sh - Be sure to change the path to point to your appropriate directory.

#!/bin/bash
echo "3301010000000000000000000000000000000033" > /home/CHANGEME/Documents/bluetooth//lights.txt

lights.txt - Should be empty, don’t forget to make it readable and writable.

At this point you can test if it’s working for you. You can run the script keepalive.sh then run the script writelightsoff.sh to turn off the light and writelightson.sh to turn on the light. There are other commands you can send to do other stuff as well like change color and brightness etc but for me all I wanted to do was to turn it off and on via Alexa.

Next comes the service bit. This will start the keepalive.sh automatically.

We need to create this file

sudo nano /lib/systemd/system/govee.service

And copy paste in the following (BE SURE TO CHANGE THE PATHS TO THE SCRIPTS):

[Unit]
Description=goove service
After=display-manager.service network.target syslog.target

[Service]
Type=simple
ExecStart=/home/CHANGEME/Documents/bluetooth/keepalive.sh
WorkingDirectory=/home/CHANGEME/Documents/bluetooth
Restart=on-failure

[Install]
WantedBy=multi-user.target

Then run:

systemctl daemon-reload

systemctl enable govee.service

systemctl start govee.service

Once you have mqtt-launcher setup and working. You want your launcher.conf file to look like this.

launcher.conf - Make sure to change the Mosquitto login info and PATHS as well. You can create a service to run mqtt-launcher.py in the background or run “nohup /path/to/mqtt-launcher.py &”


logfile         = 'logfile'
mqtt_broker     = 'CHANGEME'       # default: 'localhost'. If using TLS, this must be set to the domain name signed by your TLS certificate.
mqtt_port       = 1883              # default: 1883
mqtt_clientid   = 'govee-mqtt'
mqtt_username   = CHANGEME
mqtt_password   = CHANGEME
mqtt_tls        = None              # default: No TLS
mqtt_tls_verify = None              # Configure verification of the server hostname in the server certificate, None means to not vorifying Hostname and should not be used in production
mqtt_transport_type = 'tcp'         # alternative: 'websocket', default: 'tcp'

topiclist = {

    # topic                     payload value       program & arguments
    "govee/power"       :   {
                                'off'        :   [ '/home/CHANGEME/Documents/bluetooth/writelightsoff.sh' ],
                                'on'         :   [ '/home/CHANGEME/Documents/bluetooth/writelightson.sh'  ],
                            },
}

At this point you can test that your mqtt messages can control you govee light by sending an “off” or “on” message payload to the topic “govee/power”

Everything else from now on is setting up Node-RED to send Mqtt commands and install the Alexa plugin.

The Alexa plugin for Node-RED I use is node-red-contrib-amazon-echo (node-red-contrib-amazon-echo (node) - Node-RED). There are many posts and tutorials on how to set this up so I won’t go into details. I will say that for my specific case where I have my Alexa devices on a separate IOT vlan, I had to put one of the alexa devices on the same vlan as my node-red install in order to discover the device (which I called chair in the image below) and then put it back on the IOT network.

hass

The payload message from the “chair” device is already either on or off depending on your command to Alexa so just pipe that into a node-red mqtt-out network node that send messages over “govee/power” and you are all set.

You can rename your device and set up routines from within the Alexa app.

If you have any questions I’ll try my best to respond.

1 Like

Great work! I hate using Cloud/HTTP APIs to interface with my devices since they usually slow down the execution or place arbitrary call limits (like Govee did this year). I’m looking to use your work on my rPi, which is running Home Assistant Core. As such, I have no idea how to actually install these scripts. I’ve not seen any way to create and run my own bash scripts with such a setup (but I’m still new/learning, so there might be). Any ideas on how to get this running?

Hi!

Happy to assist you where I can. The first step I would say is to get a working Node-RED and Mosquitto installation. Mosquitto handles the MQTT calls and Node-Red is used to send the MQTT commands. There are a lot of tutorials on youtube, but I would recommend a channel called https://www.youtube.com/c/TheHookUp He has some easy to follow tutorials for both.

Is a separate bluetooth device required as a ‘hub’? Would this work using the internal bluetooth on the home assistant host… a raspberry pi 4b in my case.

I think this is similar to what madmartigan was getting at from how I read it.

Quick and easy (hopefully) question - how were you able to find the mac address of the LED strip? I cannot find it anywhere in the app…