Govee integration

Hi guys,

I did a integration for the Govee API. This is using the official Govee cloud service. Internet needed.


(Thanks @Scope666 for the screenshot form here).

Installation

Using HACS (recommended):

Manual installation:

Further steps for both variants:

  • On the integrations page, add the “govee” integration in the UI.
    You’ll need an API key, which you can get from the ‘Govee Home’ App:
    User - About Us - Request API Key. The key is delivered by mail within seconds.

@EverythingSmartHome also featured the Govee Lights and this integration in a helpful video:

Here is another video by @larsklint, which explains installation prodedure in HACS and using color in automations:

Links
How to work around wrong state values received from Govee API (Forum Post explaining a special feature)

Further steps
Usually configuration is done here - in most cases no further manual steps are necessary.
Over the time I added some options you can configure, if you have some glitches or special needs please review the documentation page here first:

README.md on GitHub

Future

  • We decided, to walk the BLE (bluetooth low energy) path. So there will be basic support for BLE-devices (and devices supporting WIFI and BLE). As this is an hobby project, this will take a bit.
  • You may always express your opinion what should be implemented. To do this post here in the forum, or file an issue on github.

Is it stable?
We think so. It is used often, and the support thread is active.
installation count per version

CAUTION: picture is cached here, if you want to see the current usage graph click here.

Usage Data is taken from Home Assistant analytics, and plotted over time by us. You need to enable analytics if you want to show here.

Is the API up?
We also have you covered here, again by a graph wich is testing two main functions: get device list, and get state for these devices. This is updated every 30 minutes.
If this reports an error, this may be an issue by the library we use and code, but more likely the Govee API has an issue and someone may want to write them a mail.

Govee API working?

CAUTION: picture is cached here, if you want to see the current usage graph click here.

Code is here:
Lib: https://github.com/LaggAt/python-govee-api published here https://pypi.org/project/govee-api-laggat
Integration: https://github.com/LaggAt/hacs-govee

Support
This was a lot of effort, so I decided to add this:

Buy Me A Coffee

If you are a coder you may also support by extending the library and integration, If your aren’t you can help with good/detailed bug and feature requests and by helping other users.

Device Compatibility:

Please tell me what is working, and what is not! I cannot guarantee anything, I just manage a list based on user voices.
Buetooth-devices do not work, see here if your are a coder and want to jump in. I could help with refactoring to give the user a unified experience.

  Model   Working?   State    Notes, links
* H6163   Yes        Yes      This is my led strip, the reason I developed this.
* H6159   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/88?u=laggat
* H6117   Yes        ?        https://community.home-assistant.io/t/govee-led-strips-integration/228516/114?u=laggat
* H6195   Yes        ?        For state support we have two reports, with different results:
                     Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/287?u=laggat
                     local    https://community.home-assistant.io/t/govee-led-strips-integration/228516/130?u=laggat
* H6160   Partly     ?        Color Temperature not supported. https://community.home-assistant.io/t/govee-led-strips-integration/228516/110?u=laggat
* H6104   Partly     local    Color Temperature not supported. https://community.home-assistant.io/t/govee-led-strips-integration/228516/63?u=laggat
                              Also setting brightness doesn't turn these on, I made a workaround for this, see 
                              https://community.home-assistant.io/t/govee-led-strips-integration/228516/141?u=laggat
* H6110   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/168?u=laggat
* H6141   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/179?u=laggat
* H6182   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/184?u=laggat
* H5081   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/272?u=laggat
* H6142   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/287?u=laggat
* H6003   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/287?u=laggat
* H6054   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/287?u=laggat
* H6052   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/287?u=laggat
* H6199   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/287?u=laggat
* H6188   Yes        Yes      https://community.home-assistant.io/t/govee-led-strips-integration/228516/303?u=laggat
* H7020   Unknown/Partly      "At least on/off." https://community.home-assistant.io/t/govee-integration/228516/540?u=laggat
* H6143   Yes        Yes      https://community.home-assistant.io/t/govee-integration/228516/592?u=laggat
Govee API docs say, these below should work too. 
As this is half of the story (integration must be right too) 
PLEASE tell us how well they work if you own one.

H6109, H7021, H7022, H6086, H6089, H6085, H7014, H6135, H6137, H6196, H7005, 
H6083, H6002, H6148, H7050, H6051, H6056, H6061, H6058, H6073, H6076, H619A,
H619C, H618A, H618C, H6008, H6071, H6075 , H614A, H614B, H614E, H618E, H619E

“State” column:

  • API: we manage state when setting something, and as soon as we get a State from API we use that.
  • local: the API does not support requesting a State here, we just manage state locally by remembering the latest set values.
  • ?: I don’t know - feedback welcome.

Reporting Bugs
If something doesn’t work please provide log details. To do so put this in your configuration.yaml:

logger:
  default: warning
  logs:
    homeassistant.components.govee: debug
    custom_components.govee: debug
    govee_api_laggat: debug

Then on Settings - Logs click on “full logs” button.Comment that with your actions, and what the led/bulb is doing at which point. Take care to override private details in logs (e.g. MAC-address).

Have fun :smiley:

42 Likes

Continuing from the other thread.

I had no luck with it. This is the result of almost all my attempts:
curl -X -H “Content-Type: application/json” -d ‘{“Govee-API-Key”:“my_api_key_was_here”}’ https://developer-api.govee.com/v1/devices
curl: (3) Port number ended with ’ ’

Something is probably formatted wrong but I could not determine what.

Even with the above I could still determine my MAC for the device from the router and the model from the app but I could not format the on command. I am by no means an expert with cURL.
For checking the state:
curl -X PUT -H “Content-Type: application/json” -d ‘{“Govee-API-Key”:“my_api_key_was_here”}’ https://developer-api.govee.com/v1/devices/state?device=34:20:xx:xx:xx:xx&model=H6104
The result is "Miss API Key:
I am doing everything via ssh in the terminal.
I would love to be able to help, which in turn ends up helping me.

1 Like

Thanks @GlennHA for answering, I really want to know why your H6104 isn’t working.

I’ve no mac, but curl should be similar, so I give it a try. Usually I use Postman which is very easy to fiddle with API’s. Thankfully, Postman can export curl code :slight_smile:

Get device list (and therefore your device id’s):

curl --location --request GET 'https://developer-api.govee.com/v1/devices' \
--header 'Govee-API-Key: YOUR-API-KEY'

To get the device state:

curl --location --request GET 'https://developer-api.govee.com/v1/devices/state?device=40:83:00:00:00:00:00:00&model=H6104' \
--header 'Govee-API-Key: YOUR-API-KEY' \
--data-raw ''

Try to turn it on:

curl --location --request PUT 'https://developer-api.govee.com/v1/devices/control' \
--header 'Govee-API-Key: YOUR-API-KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "device": "40:83:00:00:00:00:00:00",
    "model": "H6104",
    "cmd": {
        "name": "turn",
        "value": "on"
    }

Again - replace your API Key, and your private ID’s in requests and responses you post here.

1 Like

I’d definitely recommend using Postman to make the API requests, it makes it a lot easier. Also in my earlier testing before this integration, I found out that the Govee API has the MAC address of my device completely wrong compared to what’s reported in my router. I had to use the one listed in the API.

1 Like

Ok, my formatting was off, this worked and Scope666’s comment that the MAC address is not what is reported also helped.

{“data”:{“devices”:[{“device”:“99:F8:XX:XX:XX:XX:XX:XX”,“model”:“H6104”,“deviceName”:“H6104_22DC”,“controllable”:true,“retrievable”:false,“supportCmds”:[“turn”,“brightness”,“color”,“colorTem”]}]},“message”:“Success”,“code”:200}

2 Likes

Thanks, so the difference is “retrievable”: false - which according to the docs means: querying the device state is not supported.

Here is probably the issue: I ignored this flag in the api code.

What do you get when you try to get the device state anyway? I want to pack this result in a unit test.
Also: were you able to turn the device on?

I’m off for today, I’ll try to provide you a zip file tomorrow.
Please post the other two responses (and your triple-backticks to format as code if possible)

Good night.

Result for state query:
This device model does not support query device state

As for the turning on, I have a formatting using that gets a
400 Bad request

1 Like

ok, I am able to turn on once I included an extra set of brackets:

{
"device": "99:F8:XX:XX:XX:XX:XX:XX",
"model": "H6104",
"cmd": {
        "name": "turn",
        "value": "on"
}
}

The lights do turn on and indicate in the phone APP but I only get:
200 OK
as a response.

I do only need it to turn on/off since I leave it in the camera mode. Since I have more than one Samsung TV and they do not give unique IDs so I can’t tell which is on, it looks like I will need to put the TV on a smart plug that monitors current draw and turn on lights when above a certain current level. I did end up using Postman since I could install it easily on my windows 10 laptop. I have not figured out how to format and get any json payload via cURL.

2 Likes

What I did is set up an automation where the trigger is TV power from off to on, it tells the Govee to turn on. I have the reverse as well… gets the job done. :wink:

Ok, it is the little things that get you…

curl --location --request PUT 'https://developer-api.govee.com/v1/devices/control' \

--header 'Govee-API-Key: API_KEY' \

--header 'Content-Type: application/json' \

--data-raw '{

"device": "99:F8:XX:XX:XX:XX:XX:XX",

"model": "H6104",

"cmd": {

        "name": "turn",

        "value": "on"

}

}'

This works via curl.

or single line
curl --location --request PUT 'https://developer-api.govee.com/v1/devices/control' --header 'Govee-API-Key: API_KEY' --header 'Content-Type: application/json' --data-raw '{"device": "99:F8:XX:XX:XX:XX:XX:XX","model": "H6104","cmd": {"name": "turn", "value": "on"}}'

The “off” command works also

1 Like

Unfortunately, both my TVs are Samsung and they do not have unique IDs so I can’t differentiate in Home Assistant with the media player tag.

There should be a way to make them unique, perhaps through the SmartThings integration. (you don’t need a hub to use it)

image

I tried the SmartThings integration and then remembered that I had tried before but I could never get webhooks working right in order to use the integration.

How do you add the integration to the UI? I have the files unziped under /custom_components/govee but I don’t see the integration.

EDIT: Never mind - it took a long to time to finally show up. I am getting this error on startup though:

2020-09-21 11:50:08 ERROR (MainThread) [custom_components.govee.light] Could not connect to Govee API: API-Error 429: Rate limit exceeded, retry in 10 seconds.

But I don’t think it retried.

FINAL EDIT: A second restart seemed to work. All good and working now - thank you!

2 Likes

Hello, and nice you sorted it out.

Yes, it takes some time to install the lib package on my RPi too, but it usually works after some time.

About Rate Limiting: The package does rate limiting, and should not hit the API when there are only 5 requests left. I choose 5 because there may be other apps connecting to the API, and I wanted to keep this safe. Is it possible you had other apps using the API from the same IP address?

Anyhow: this ERR message could only happen during init, and there I currently give up if the connection wasn’t possible.
This retry message “API-Error 429: Rate limit exceeded, retry in 10 seconds.” is just the message i print from the API, so there really is no retry from the component, I thought home assistant would call me again. I’ll try this out in https://github.com/LaggAt/home-assistant-core/issues/1

Do you need me to test any other commands?

1 Like

Hi, I don’t think so, I’ve a good idea what should work.

I am coding on the next version with your and @pmd5700’s inputs, some input from the excellent govee api support guys. More than I could do today :laughing:

Right now i did some changes to be able to reload, and I addressed the issue the integration isn’t loading if it fails at first by 429 too many requests, or internet issues, or whatever (which are related). Right now I’l addressing this jumping issue, when you e.g. turn on and it is jumping back to off, before it jumps to on again. Next is your issue, and this should be a release for today.

edit: well, tomorrow. lib is almost done, need to test a bit more on the itegration.

So are you going to assume the state for the H6104 and base it off the last on or off command from Home Assistant?

I was thinking about a template binary sensor based on the current draw of the LEDs being on. Should be doable, I just haven’t done it yet. I have only three items on the power strip for this TV (only one TV has the Govee lights…so far), the TV, the Govee, and a Rpi running KODI. I just need to put it on a monitoring plug and see what all my loads are. The Rpi is on all the time. I don’t plan on using the smart plug to turn anything on or off, just to monitor current draw. I might as well use this plug for something; it has been hanging out just as a Z-wave repeater up to this point.

So will be able to use your add-on to implement my automatons to turn on the Govee once you done or will I still need to resort to cURL to turn Govee on and off?

1 Like

Whoa, what? :smiley:

I try to mimic a state as much as I know. so e.g. if you turn it on i assume it is on, until you turn it off. I do not go for perfection right now, so e.g. turning off will not reset brightness or color. Such things could be done later. What is needed for this is keeping a local state.

I don’t know what you want to do with the draw of any device, but this should enable you to control the led’s, and see the current state in a basic manner. No updating of state, because we know it isn’t supported.

Did this help?

Please try the latest file:
https://drive.google.com/drive/folders/1f2yVik5n-3-_1Hwxgywn1TlExyau5TxM?usp=sharing

1 Like