hacs-govee
hacs-govee copied to clipboard
Setting device mode
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.
@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
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.
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
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.
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?
I am interesting for this option too.
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.
@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?
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!
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..
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
Yes, I found this too, but don't know two things:
- How to route mqtts traffic through ioxy, as there is now option to set an proxy for mqtts connections
- How to get SSL/TLS Cert from groovys mqtts server, as this is required for mqtts connections
Maybe someone can help here!
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.
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:
- Create a helper e.g.
input_boolean.music_video_switch_living_room
- 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'
- Expose that
music_video_switch_living_room_alexa
binary sensor via Home Assistant Cloud - Now you should see that sensor in the Alexa app. Add routines for
close
andopen
states for the added sensor - Call the
input_boolean
services (turn_on
andturn_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.
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.
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:
- Create a helper e.g.
input_boolean.music_video_switch_living_room
- 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'
- Expose that
music_video_switch_living_room_alexa
binary sensor via Home Assistant Cloud- Now you should see that sensor in the Alexa app. Add routines for
close
andopen
states for the added sensor- Call the
input_boolean
services (turn_on
andturn_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.
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.
@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.
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
}
}
}