Govee Home Products / Dreamcolor LED strip

Looks likenyou can apply for API test with 3.5.0 app under about us user section.

1 Like

Just requested and instantly received an API key. User Guide if anyone is interested:

https://drive.google.com/file/d/1MNQOxvOlieT_MAUt9N9YDaI6PJz-Sd7h/view?usp=sharing

Yep I have API access now too. Requested via the app and got my key instantly. Pretty simple API to use too

2 Likes

Now that the API is out, hopefully someone smarter than me can create a custom template for it. I received my api key but it will probably take me a while to decipher how to use it cause I’m lazy.

1 Like

Just bought a couple of these, would be awesome to get them integrated natively into HA, now that the API is available.

OK. This took longer than I like, but it’s working with the Govee API, which itself seems to be broken. I wanted to get this working out of the box, initially, without any extra moving parts.

Im using a Govee H6188.

Using my API Token and GET for querying my device:

{
    "data": {
        "device": "mac_address",
        "model": "model",
        "properties": [
            {
                "online": true
            },
            {
                "powerState": "on"
            },
            {
                "brightness": 254
            },
            {
                "color": {
                    "r": 0,
                    "b": 0,
                    "g": 0
                }
            }
        ]
    },
    "message": "Success",
    "code": 200
}

So, thinking logically, 255 would match up with the light card sliders. Hashtag FakeNews. It responds with up to 254 for value, but you can only PUT up to 100, so you have to do stupid math back and forth.

Here is my working sensor.

sensor:
  - platform: rest
    name: office_led_sensor
    method: GET
    resource: https://developer-api.govee.com/v1/devices/state?device=[device_mac]&model=[device_model]
    headers:
      Govee-API-Key: 8675309
      Content-Type: application/json
      User-Agent: Home Assistant REST sensor
    scan_interval: 60
    json_attributes_path: '$.data'
    json_attributes: 
      - properties
    value_template: '{{ value_json.data.properties[0].online }}'
  - platform: template
    sensors:
      office_led_state:
        value_template: "{{ state_attr('sensor.office_led_sensor', 'properties')[1].powerState }}"
        entity_id: sensor.office_led_sensor
      office_led_brightness:
        value_template: "{{ state_attr('sensor.office_led_sensor', 'properties')[2].brightness }}"
        entity_id: sensor.office_led_sensor
      office_led_color:
        value_template: "{{ state_attr('sensor.office_led_sensor', 'properties')[3].color }}"
        entity_id: sensor.office_led_sensor```

And my light:
```yaml
light:
  - platform: template
    lights:
      office_led_strip:
        friendly_name: "Office LED"
        value_template: >-
          {% if is_state('sensor.office_led_state', 'on') %}
            {% if states('sensor.office_led_brightness') | int < 1 %}
              off
            {% else %}
              on
            {% endif %}
          {% else %}
            off
          {% endif %}
        level_template: >-
          {% if is_state('sensor.office_led_state', 'on') %}
            {{ (((states('sensor.office_led_brightness') | int) / 255) * 100) | round(0) }}
          {% else %}
            0
          {% endif %}
        turn_on:
          service: rest_command.office_led_power
          entity_id: light.office_led_strip
          data:
            value: "on"
        turn_off:
          service: rest_command.office_led_power
          entity_id: light.office_led_strip
          data:
            value: "off"
        set_level:
          service: rest_command.office_led_brightness
          entity_id: light.office_led_strip
          data_template:
            brightness: >
              {{ (brightness /255*100) | int | round(0) }}

And then my rest_commands. Only thing is the Color set wont work right now.

rest_command:
  office_led_power:
    url: https://developer-api.govee.com/v1/devices/control
    method: PUT
    content_type:  'application/json'
    headers:
      Content_Type:  application/json
      Govee-API-Key: 8675309
      User-Agent: Home Assistant REST sensor
    payload: '{ "device": "mac_address", "model": "model", "cmd": { "name": "turn", "value": "{{value}}" } }'
  office_led_color:
    url: https://developer-api.govee.com/v1/devices/control
    method: PUT
    content_type:  'application/json'
    headers:
      Content_Type:  application/json
      Govee-API-Key: 8675309
      User-Agent: Home Assistant REST sensor
    payload: '{ "device": "mac_address", "model": "model", "cmd": { "name": "color", "value": {"r": 255, "g": 255, "b": 255}} }'
  office_led_brightness:
    url: https://developer-api.govee.com/v1/devices/control
    method: PUT
    content_type:  'application/json'
    headers:
      Content_Type:  application/json
      Govee-API-Key: 8675309
      User-Agent: Home Assistant REST sensor
    payload: >
      { "device": "mac_address", "model": "model", "cmd": { "name": "brightness", "value": {{ brightness }}  } }

And that seems to be working.

2 Likes

Thanks for sharing this Mike. So if I want to get this working in my HA, I have to add the rest commands, light template, and sensors into my config.yaml (and change my entities and Govee API key as appropriate)?

1 Like

Yup. It could probably still use some polish to tighten it up, add color options, etc. But that does the trick.

I used Postman to test the queries, then it took forever to get the templates right. But it should almost be copy and paste.

I had no idea it could be done this way in Home Assistant. I was in the middle of writing a Python plugin to do all the leg work, but this seems much simpler. Thanks for sharing @Mikej81

1 Like

This is excellent work.

I’m using H6104 and only need to turn it on or off.

Should I be substituting in:

payload: '{ "device": "mac_address", "model": "model", "cmd": { "name": "turn", "value": "{{value}}" } }'

If so, what with?

Should it be like this:

payload: '{ "device": "10:ab:34:dc:0a:12", "model": "H6014", "cmd": { "name": "turn", "value": "{{value}}" } }'

What is “name”, “turn” and “value”?

Looks correct. Name is the name of the Command you can pass. Make sure to apply for your API token. They send an API guide with the token, took me about 30 seconds after application to recieve.

Per the guide:

{"online": "false"}
{"powerState" : “off"}
{"brightness" : 60}
{"color": {"r": 255, "g" : 255, "b", 255}}
{"colorTem": 5000}

data.devices.supportCmds Commands supported by the device. Valid Values in the array: “turn”, “brightness”, “color”, “colorTem” Type: array Required: Yes

@adamj a plugin is probably the better long term solution, but this works, and now I can work on other things. LOL

1 Like

I decided to do this in Node Red in the end. I don’t really control the Govee strips, I have them match the state of a hue bulb so it made sense to set up a few nodes in Node Red and save myself the hassle of writing the plugin.

1 Like

Thank you for this, works great! Bonus points for your API Key. :wink:

PS. Incase it helps anyone else, I had to use Postman to list the devices on my account first. The MAC address they have for my light is COMPLETELY different from what my router reports it as.

1 Like

Hi,
then to your work I’m now able turn on and off my device via rest api.

If the device is on and I query the state I get always powerState off:

this is the result:

{“data”:{“device”:"[MY_MAC_ADDRESS]",“model”:“H6104”,“properties”:[{“online”:true},{“powerState”:“off”},{“brightness”:110},{}]},“message”:“Success”,“code”:200}

maybe it’s a bug?

The result is that HA cannot switch off the LED; the state switch immediatly back to off.

@lupick what is your scan interval set to? the status will only update whenever that hits. In the code posted above, I have it set at 60, just because I didn’t want API calls leaving my house every 3/5/10/30 seconds, and I wasn’t sure if Govee had throttling turned on.

yep I’ve set it to 60 too ( I’ve just copied your code):

scan_interval: 60

I’ve the same result using Postman on a single status query. I’ve cheked and my rate limits looks ok:

~ $ curl -i https://developer-api.govee.com/ping
HTTP/2 200
date: Thu, 13 Aug 2020 13:51:24 GMT
content-type: text/plain; charset=utf-8
content-length: 4
rate-limit-remaining: 98
rate-limit-reset: 1597326721.011729
rate-limit-total: 100
vary: Origin
access-control-allow-origin: *
x-response-time: 1ms
x-traceid: 13a727f0-dd6c-11ea-8efa-d39d769182e5

On Govee Doc they report 100 result per minute. Maybe it’s a bug on the api?

And it doesn’t update after a minute? Give a full minute to refresh on the scan interval, this is where an actual plugin would come in handy, at least an API proxy to maintain local state. Seems to be working for me on Home Assistant 0.113.3, ignore my Dyson integration…

Yes if I switch on the light the devices remain on but the HA state is set to off immediatly

no matter if I wait

Could be a bug in their API. I dont think they put a lot of effort into it.