Govee to MQTT

repository·main·Indexed 21 days ago

https://github.com/wez/govee2mqtt

A bridge that connects Govee smart devices to Home Assistant via MQTT. It prioritizes LAN control for low latency and offline capability, with fallbacks via AWS IoT and the official Govee Platform API. The bridge translates Govee device states and commands into MQTT messages for use with the Home Assistant MQTT Integration.

Tokens
11.2K
Snippets
7
Records
73
Agent score
80%

What's inside govee2mqtt

  1. Understand Govee2MQTT data privacy and local storage

    main

    Govee2MQTT is designed to keep your data local. No usage data or device information is sent to the maintainers. All data remains on your device, with the exception of data required by Govee's cloud servers (AWS) to control your devices.

    Key Privacy Points:

    • Credentials: Any credentials configured in govee2mqtt are used exclusively for authentication with Govee's cloud servers.
    • Local Caching: To prevent hitting Govee API rate limits, information regarding your Govee device list and their configurations is cached locally on your filesystem.
  2. Understand Segment control limitations

    main

    Control over device segments is subject to the limitations of the Govee API and the specific hardware:

    • Power State: The Govee API for segments only supports brightness and color, not power state. While Home Assistant shows a power control for segments (as it assumes all lights have one), clicking it will do nothing.
    • Control Flexibility: Govee to MQTT acts as a bridge; it cannot override device-specific behaviors. For example, some devices may not allow setting a segment brightness to 0, or may bind segment brightness to the overall light brightness.
  3. Clarification on Govee Device IDs vs MAC addresses

    main
    The device IDs shown in the logs are not network MAC addresses. While some device IDs may appear to be a superset of the BLE MAC, the device ID is typically larger than a standard MAC address.
  4. How Govee device discovery works

    main

    Govee devices with the LAN protocol enabled listen for discovery packets on UDP port 4001. They participate in the multicast group 239.255.255.250.

    Because multicast-UDP is often poorly supported by routers (especially on Wi-Fi), Govee2MQTT provides alternative discovery methods to bypass multicast issues:

    1. Direct IP Scanning: You can specify a list of IP addresses to which discovery packets are sent directly (unicast).
    2. UDP Broadcast Variations: You can enable options that use standard UDP broadcasts instead of multicast.

    For a device to be successfully discovered and usable, UDP ports 4001 and 4003 must be reachable from the Govee2MQTT instance.

  5. Enable Video Effects for a Light in Home Assistant

    main

    Because the Govee API does not return video effects, they are not automatically listed in Home Assistant. To make them available, you must create a workaround using the Govee Home App:

    1. In the Govee Home App, create either a "Tap-to-Run" shortcut or a saved "Snapshot" that activates the desired video effect.
    2. In Home Assistant, navigate to the "Govee to MQTT" device within the MQTT integration.
    3. Click the "Purge Caches" button.

    Results:

    • Tap-to-Run shortcuts will be mapped as Scene entities in Home Assistant.
    • Snapshots will appear in the list of Effects on the device itself.
  6. How to install and run govee2mqtt

    main

    Depending on your Home Assistant setup, use one of the following methods to install the bridge:

    • Home Assistant Add-On: For HAOS and Supervised HASS users. See docs/ADDON.md.
    • Docker: For users running Home Assistant in containers. See docs/DOCKER.md.
    • Configuration: To set up your credentials and device settings. See docs/CONFIG.md.
  7. Install Govee2MQTT as a Home Assistant Add-On

    main

    If you are running HAOS (Home Assistant Operating System) or Supervised Home Assistant, you can install Govee2MQTT as an Add-On. This requires setting up an MQTT broker and adding the project repository to your Add-On store.

    Prerequisites

    1. Enable Advanced Mode: Click your profile icon (bottom left) and toggle on Advanced Mode.
    2. Set up MQTT:
      • Install and start the Mosquitto Broker add-on from the Add-On Store.
      • Go to Settings > Devices & Services and enable the MQTT integration.

    Installation Steps

    1. Navigate to the Add-Ons section in Settings.
    2. Open the Add-On Store.
    3. Click the three vertical dots (top right) and select Repositories.
    4. Add https://github.com/wez/govee2mqtt and click Add.
    5. Locate Govee2MQTT in the store, click it, and select Install.
    6. Go to the Configuration tab.
    7. Enable Show unused optional configuration options.
    8. Provide the required credentials: govee email, password, and api key.
    9. Click Save.
    10. Go to the Info tab and click Start.

    Verification

    • Check the Logs tab for diagnostics.
    • Once running, Govee devices should be discovered and appear under your MQTT integration.
  8. Requirements for Govee LAN API control

    main

    To use the Govee LAN API via Govee2MQTT, the following network and device requirements must be met:

    Device Requirements

    • Enable LAN API: Each Govee device must have its LAN API access enabled manually within the settings of the Govee Home App.
    • Open Ports: UDP ports 4001 and 4003 must be reachable on each Govee device.

    Govee2MQTT Requirements

    • UDP Port Binding: Govee2MQTT must be able to bind to UDP port 4002 on the host machine.
    • Network Routing: Your network must allow UDP replies to route back to Govee2MQTT. Note that while Govee devices respond to the source IP of the packets, they will use UDP port 4002 instead of the originating port for the reply.
  9. Persist govee2mqtt data on the host

    main

    By default, govee2mqtt uses a Docker volume to persist data. If you prefer to mount the data directory directly to a specific path on your host machine, add a volumes section to your docker-compose.yml service definition.

    # Example volume mounting
    services:
      govee2mqtt:
        # ... other config ...
        volumes:
          - '/path/to/data:/data'
  10. Deploy govee2mqtt using Docker Compose

    main

    To deploy govee2mqtt in Docker, follow these steps:

    1. Configure MQTT: Ensure the MQTT integration is already configured in Home Assistant.
    2. Create a .env file: Populate a .env file with your environment-specific values (see the environment variables section for details).
    3. Configure docker-compose.yml: Create a compose file using the ghcr.io/wez/govee2mqtt:latest image. Note: network_mode: host is required.
    4. Launch: Run docker compose up -d to start the container in detached mode.
    5. Monitor: Use docker logs govee2mqtt --follow to view real-time logs.
    name: govee2mqtt
    services:
      govee2mqtt:
        image: ghcr.io/wez/govee2mqtt:latest
        container_name: govee2mqtt
        restart: unless-stopped
        env_file:
          - .env
        # Host networking is required
        network_mode: host
  11. Configure MQTT for Home Assistant Integration

    main

    To make Govee devices appear in Home Assistant, govee2mqtt must be configured to connect to the same MQTT broker used by your Home Assistant instance.

    Use the following options to specify your broker connection details: