Govee API to MQTT

Govee recently released a public API to control their WiFi light strips, among other things.

I’ve created govee2mqtt (with homeassistant discovery) to integrate these devices.

This is very early code with little documentation. However, if you’re interested, please give it a spin and feel free to submit PRs to help finish the feature set.

A few notes:

  • Govee’s API is SLOW. Not only does each request take longer than it should, it takes, sometimes, 3 to 4 seconds for the command to reach the light strip. Hopefully, they’ll speed this up as time goes on.

  • I only have model H6159. I’ve not tested with anything else though, in theory, it should work.

  • Support is there for power on/off, brightness, and rgb_color. White Temperature is next in my list.

  • Dockerfile is coming soon.

1 Like

Hello,

I’m trying to install this, but it’s not working. I’m trying to install this on a Windows 10 laptop with openhab integretion.

First of al, I installed Mosquitto, normaly it’s running, then I installed Python. Everything is fine I guess.
Then I changed the config file. And try to run the script app.py
This gives me some errors.

What do I wrong?

‘C:\Program Files\mosquitto\govee2mqtt-master>python ./app.py -c ./
Traceback (most recent call last):
File “C:\Program Files\mosquitto\govee2mqtt-master\app.py”, line 23, in
config = yaml.load(file, Loader=yaml.FullLoader)
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml_init_.py”, line 114, in load
return loader.get_single_data()
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\constructor.py”, line 49, in get_single_data
node = self.get_single_node()
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\composer.py”, line 36, in get_single_node
document = self.compose_document()
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\composer.py”, line 55, in compose_document
node = self.compose_node(None, None)
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\composer.py”, line 84, in compose_node
node = self.compose_mapping_node(anchor)
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\composer.py”, line 133, in compose_mapping_node
item_value = self.compose_node(node, item_key)
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\composer.py”, line 84, in compose_node
node = self.compose_mapping_node(anchor)
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\composer.py”, line 127, in compose_mapping_node
while not self.check_event(MappingEndEvent):
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\parser.py”, line 98, in check_event
self.current_event = self.state()
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\parser.py”, line 428, in parse_block_mapping_key
if self.check_token(KeyToken):
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\scanner.py”, line 116, in check_token
self.fetch_more_tokens()
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\scanner.py”, line 223, in fetch_more_tokens
return self.fetch_value()
File “C:\Users\piete\AppData\Local\Programs\Python\Python39-32\lib\site-packages\yaml\scanner.py”, line 577, in fetch_value
raise ScannerError(None, None,
yaml.scanner.ScannerError: mapping values are not allowed here
in “./config.yaml”, line 2, column 28’

It’s hard to tell from this. It looks like there’s something wrong with your YAML, but, I’d need to see it to be sure.

Note, however, govee2mqtt is untested on Windows, so it may not work at all.

I’m already a step futher.
It’s running, I see my device on the device list.
But when he is trying to get the state of the device, I get the Error: Bad response code.

When I try to search it, The Govee api is telling that maybe the url is not correct.

Can you give me the correct URL that you are using?
Maybe it’s not needed that this coding is needed, because Openhab can also handle HttpRequests?

If you can issue httprequests from openhab, then you can certainly do everything this does manually.

Thanks.
It is already working, with openhab. :slight_smile:
Without this script, but thanks for this script, I understand now how the API is working.

2 Likes

Hi Pieter,

Could you give me some information how you got that working in OpenHAB? I’m not able to get it running.

Thanks

Sorry for this late answer.
First of all you need to update some .jar file (see: https://community.openhab.org/t/solved-how-to-use-sendhttppostrequest-with-http-headers/104396)
Because only Openhab 3.0 can do HttpRequests.

After this you can set a rule with al the stuff undernead. Just change the ‘API-key’, device-IP(IPv6).

var url = “https://developer-api.govee.com/v1/devices/control

var headers = newHashMap("Govee-API-Key" -> "API-key")

var content = '{

                    "device": "device-IP",

                    "model": "H6104",

                    "cmd": {

                    "name": "turn",

                    "value": "on"

                    }

                    }'

    sendHttpPutRequest(url, 'application/json', content, headers, 3000)

Hi
I’ve done a direct install of this and it gets to the part where it opens the config.yaml in vi
What do I do then?
Do I just put my API key in and save?
Thanks

Hey,

I’ve tried installing this custom add-on, but it’s not very specific which login data it needs. I’ve tried feeding it the one I use in my app and the separate website one, both for the US and EU Store. None of them work, always giving me this: {“status”:451,“message”:“This email hasn’t been registered yet.”}

Does anybody have a solution?