LaggAt / hacs-govee

A HACS repository for Govee light integration
MIT License
262 stars 60 forks source link

Setting device mode #38

Open codetheweb opened 3 years ago

codetheweb commented 3 years ago

Is your feature request related to a problem? Please describe. I have a TV backlight strip. I'd like to be able to change between solid color and video (sync to screen) modes, but Govee does not currently provide a field for this in their official API.

Describe the solution you'd like I contacted Govee to see if they'd be willing to add this but they said no:

I am sorry that we do not have any plans to release the scences and modes now. So it could not support mode control through API. Your udnerstanding is highly appreciated.

I figured it wouldn't hurt if you could reach out as well since you have ~500 users 😛.

Describe alternatives you've considered Sniffing Bluetooth traffic and just replaying the mode-setting packet.

Additional context Might be related to #36.

clod986 commented 3 years ago

@codetheweb I don't think this is done via BLE, I wanted to do this for a H6003 and that should use only WiFi.

Another approach could be to implement this integration to replicate the functions of the app. As we can find at https://govee-api.readthedocs.io/en/latest/usage.html

            if isinstance(dev, device.GoveeRgbLight):
                # Save initial color
                color_backup = dev.color

                # Set color temperature to 2100 kelvin (warm white)
                dev.color_temperature = 2100

                # Wait a second
                time.sleep(1)

                # Set color to green
                dev.color = colour.Color('green')

                # Wait a second
                time.sleep(1)

                # Set color to red
                dev.color = (255, 0, 0)

                # Wait a second
                time.sleep(1)

                # Set color to dodgerblue
                dev.color = colour.Color('dodgerblue')

                # Wait a second
                time.sleep(1)

                # Restore color
                if color_backup:
                    dev.color = color_backup

Maybe this could work like this: 1: create custom DIY, using simple dropdowns/text fields for colors and wait time 2: test the DIY 3: save the DIY with an ID

At this point, this could become a trigger where instead of setting the color on the lamp, HA runs the custom DIY

codetheweb commented 3 years ago

I'm not entirely clear on what you're saying but I don't think you can set scenes from the API.

I got it to work by replaying Bluetooth packets but it's a bit flaky.

clod986 commented 3 years ago

Have you tried with a WIFI light bulb? https://us.govee.com/products/wi-fi-led-bulb

It doesn't come with Bluetooth, therefore it must work via WiFi and the API will for sure send some packets to it. If you can suggest me a packet sniffer I could use maybe I can try to help

codetheweb commented 3 years ago

I unfortunately don't have a bulb to test with.

I suspect that the Govee API that this project uses is a sanitized subset of the full API the app uses, so I would be surprised if it was possible to set the mode / scene on that bulb with the current API.

clod986 commented 3 years ago

I checked the official documentation at https://govee-public.s3.amazonaws.com/developer-docs/GoveeAPIReference.pdf and it seems that officially it is not supported... so @codetheweb you are right.

What drives me mad is that Alexa can set the scene from its Govee skill, hence it is possible to achieve; any idea if we can read the skill code?

userMak commented 2 years ago

I am interesting for this option too.

Dielee commented 2 years ago

Hello guys,

someone tried to sniff traffic with Charles ? I will receive my govee ambilight in the next few days and try to check the govee app API. If Alexa works, there have to be an endpoint for this.

clod986 commented 2 years ago

@Dielee I tried rieaching out to them but the best I got was a simple I have passed along your suggestion to the tech team. which 3 days afterwards resulted in a simple customer service survey...

Since then (October 11th), the api reference hasn't been updated.

I guess packet sniffing is an option we should consider; did you say Charles is the software we should refer to?

Dielee commented 2 years ago

Yes, this would be possible with charles. If they are not using certificate pinning, it would be quiet easy. My govee immersion light arrives in the next few days. I will dig into their App API then!

Dielee commented 2 years ago

So, checked the app with carles.. First, they do not use certificate pinning, point for us! But... All changes (Brightness, Light mode, ...) are not captured with charles. Maybe they are using another protocol. Im sure it's not HTTP or HTTPS. Maybe WS....

EDIT: They are using secure-mqtt at port 8883. Maybe we can sniff this traffic, too.

EDIT 2: Does anybody know how to sniff mqtts traffic ? I have no idea jet..

tzapu commented 2 years ago

maybe with something like this? https://blog.nviso.eu/2020/07/06/introducing-ioxy-an-open-source-mqtt-intercepting-proxy/?amp

also interested in this, every time i turn it on via homekit > hass > govee it turns it to a solid color instead of video sync.. pointless

Dielee commented 2 years ago

Yes, I found this too, but don't know two things:

  1. How to route mqtts traffic through ioxy, as there is now option to set an proxy for mqtts connections
  2. How to get SSL/TLS Cert from groovys mqtts server, as this is required for mqtts connections

Maybe someone can help here!

AnthonyMaiorani commented 2 years ago

If anyone is interested in looking into this, the Homebridge Govee plugin supports setting scene/music/DIY modes. It would be great if that was supported in this integration too.

coun7zero commented 2 years ago

I found a substitute solution. It isn't perfect but it's better than nothing. I tried to make reverse engineering of the use-case with aws-iot-device-sdk-js from Homebridge Govee plugin but it was too convoluted for me and it was taking too much time.

Solution 1 - No Home Assistant Cloud

First, I decided to use alexa_media_player to change between music and video modes and that solution is fine if you don't use Home Assistant Cloud - execution takes between 3 and 4 seconds - sometimes it was taking a little bit longer in my case.

Video mode:

service: media_player.play_media
target:
  entity_id: media_player.this_device_2
data:
  media_content_type: custom
  media_content_id: set dreamview p1 to vivid

Vivid music mode:

service: media_player.play_media
target:
  entity_id: media_player.this_device_2
data:
  media_content_type: custom
  media_content_id: set dreamview p1 to vivid

Solution 2 - Home Assistant Cloud

After that, I found out I can use Home Assistant Cloud integration for Alexa and routines in the Alexa app:

  1. Create a helper e.g. input_boolean.music_video_switch_living_room
  2. Define a binary sensor in your configuration .yaml file:
    template:
    - binary_sensor:
      - name: "music_video_switch_living_room_alexa"
        state: '{{ is_state("input_boolean.music_video_switch_living_room","on") }}'
        device_class: 'door'
  3. Expose that music_video_switch_living_room_alexa binary sensor via Home Assistant Cloud
  4. Now you should see that sensor in the Alexa app. Add routines for close and open states for the added sensor
  5. Call the input_boolean services (turn_on and turn_off) to switch between modes:
    service: input_boolean.turn_on
    data: {}
    target:
    entity_id: input_boolean.music_video_switch_living_room

    The upside of that solution is that it is much faster because execution takes around 2 seconds.

AnthonyMaiorani commented 2 years ago

I’ve been using Alexa Media Player myself as a solution. The delay is definitely not ideal.

It is possible to directly run routines rather than simulating a voice command by using media_content_type: routine. I believe that somewhat improves the speed.

Your second solution also applies to manually setup Alexa integration and probably emulated hue as well.

The release notes of 2022.7 mentions “You can now trigger Alexa routines from switches, toggles, and buttons without the need to wrap them into a binary template sensor first”, but I haven’t been able to get that to work myself.

nsstreetlegal commented 1 year ago

I found a substitute solution. It isn't perfect but it's better than nothing. I tried to make reverse engineering of the use-case with aws-iot-device-sdk-js from Homebridge Govee plugin but it was too convoluted for me and it was taking too much time.

Solution 1 - No Home Assistant Cloud

First, I decided to use alexa_media_player to change between music and video modes and that solution is fine if you don't use Home Assistant Cloud - execution takes between 3 and 4 seconds - sometimes it was taking a little bit longer in my case.

Video mode:

service: media_player.play_media
target:
  entity_id: media_player.this_device_2
data:
  media_content_type: custom
  media_content_id: set dreamview p1 to vivid

Vivid music mode:

service: media_player.play_media
target:
  entity_id: media_player.this_device_2
data:
  media_content_type: custom
  media_content_id: set dreamview p1 to vivid

Solution 2 - Home Assistant Cloud

After that, I found out I can use Home Assistant Cloud integration for Alexa and routines in the Alexa app:

  1. Create a helper e.g. input_boolean.music_video_switch_living_room
  2. Define a binary sensor in your configuration .yaml file:
template:
  - binary_sensor:
      - name: "music_video_switch_living_room_alexa"
        state: '{{ is_state("input_boolean.music_video_switch_living_room","on") }}'
        device_class: 'door'
  1. Expose that music_video_switch_living_room_alexa binary sensor via Home Assistant Cloud
  2. Now you should see that sensor in the Alexa app. Add routines for close and open states for the added sensor
  3. Call the input_boolean services (turn_on and turn_off) to switch between modes:
service: input_boolean.turn_on
data: {}
target:
  entity_id: input_boolean.music_video_switch_living_room

The upside of that solution is that it is much faster because execution takes around 2 seconds.

Thanks for the info. I've been trying to accomplish this, and I've followed your instructions (Option 2), and although the helper is now visible in the Alexa app, it only shows me info about the device, it doesn't give me on/off toggles. If that makes sense. Not sure if I'm missing something.

I was sure to exclude and expose the entity just be on the safe side, but no luck.

Xnip2022-11-29_12-47-22 Xnip2022-11-29_12-48-33 IMG_D3A34656F86F-1

AnthonyMaiorani commented 1 year ago

it only shows me info about the device, it doesn't give me on/off toggles

You should be able to use the device as a routine trigger. I forget exactly how input booleans are exposed to Alexa, but I use input buttons. After exposing the buttons, I can choose to trigger a routine when the button "detects a person" in the Alexa app, then set the action to any Govee scene.

This includes any custom/"DIY" modes which can be exposed to Alexa through the "Command > Tap-to-run" section in the Govee app.

bearded22 commented 1 year ago

@coun7zero recently I found a 3th option to toggle between color and video mode. It's by making use of the in app automations of govee.

• In your govee app go to command • add an auto run command and make it trigger on "turn on" and give it a real time act of "turn on DreamView"

Movie mode: • Simply turn the T1 on via the api integration and the govee automation will automatically switch the lightstrip to Dreamview(movie) mode.

Color mode • Turn the T1 on via the api integration (govee will switch to dreamview mode), wait a couple of seconds (5 in my case) and then again via the API integration push a light.turn_on but this time also provide the desired color. This will again override the Movie mode and put it into color mode.

Want it to turn in to Movie mode again ? Simply turn the lightstrip off and on (via the integration) and the process starts all over again.

keniwilliams commented 5 months ago

Hello, I did some messing around with Postman. Apologies if there is some sort of standards for posting but I hope that this can help. I am able to switch to video mode from any mode by creating snapshots within the Govee app and then recalling the snapshot via postman. I can create a curl script and call it that way also within Hass.io

I hope this helps or maybe steer in a direction :)

Interrogate the device to get the snapshot enum and use it in the request

GET /router/api/v1/user/devices HTTP/1.1
Host: openapi.api.govee.com
Content-Type: application/json
Govee-API-Key: XXXX

Search in the response devices.capabilities.dynamic_scene for snapshot and use the value matching the snapshot name you saved e.g.

 {
    "type": "devices.capabilities.dynamic_scene",
    "instance": "snapshot",
    "parameters":
    {
        "dataType": "ENUM",
        "options":
        [
            {
                "name": "TV tracking",
                "value": 356654
            },
            {
                "name": "chill",
                "value": 467874
            },
            {
                "name": "relax tv",
                "value": 467875
            },
            {
                "name": "default day",
                "value": 1050228
            }
        ]
    }
}

And then send the request:

POST /router/api/v1/device/control HTTP/1.1
Host: openapi.api.govee.com
Content-Type: application/json
Govee-API-Key: XXXX
Content-Length: 233

{
  "requestId": "1",
  "payload": {
    "sku": "H605C",
    "device": "XA:XA:XA:XA:XA:XA:XA:XA",
    "capability": {
      "type": "devices.capabilities.dynamic_scene",
      "instance": "snapshot",
      "value": 356654
    }
  }
}