wez / govee2mqtt

Govee2MQTT: Connect Govee lights and devices to Home Assistant
MIT License
342 stars 19 forks source link

After HA restart devices become unavailable #110

Open morrisb74 opened 5 months ago

morrisb74 commented 5 months ago

Govee Device SKU

NA

Govee2MQTT Version

2024.01.24-ea3cd430

Describe the issue

Several times after a restart i noticed that the Govee devices became unavailable (also the local API ones)

Startup Diagnostics

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
GOVEE_API_KEY=REDACTED
GOVEE_MQTT_HOST=a0d7b954-emqx
GOVEE_TEMPERATURE_SCALE=C
GOVEE_EMAIL=REDACTED
GOVEE_PASSWORD=REDACTED
GOVEE_MQTT_PASSWORD=REDACTED
GOVEE_MQTT_USER=govee2mqtt
GOVEE_MQTT_PORT=1883
++ cd /app
++ exec /app/govee serve
[2024-01-25T16:25:11 INFO  govee::commands::serve] Starting service. version 2024.01.24-ea3cd430
[2024-01-25T16:25:11 INFO  govee::commands::serve] Querying platform API for device list
[2024-01-25T16:25:12 INFO  govee::commands::serve] Querying undocumented API for device + room list
[2024-01-25T16:25:13 INFO  govee::service::iot] Connected to IoT: CONNACK code 0: Connection Accepted.
[2024-01-25T16:25:13 INFO  govee::commands::serve] Starting LAN discovery
[2024-01-25T16:25:13 INFO  govee::service::iot] IoT (re)connected with status CONNACK code 0: Connection Accepted.
[2024-01-25T16:25:13 INFO  govee::commands::serve] Waiting 10 seconds for LAN API discovery
[2024-01-25T16:25:23 INFO  govee::commands::serve] Devices returned from Govee's APIs
[2024-01-25T16:25:23 INFO  govee::commands::serve] Office Heater (6B:9B:60:74:xx:xx:xx:xxH713A)
[2024-01-25T16:25:23 INFO  govee::commands::serve]   Platform API: devices.types.heater. supports_rgb=false supports_brightness=false
[2024-01-25T16:25:23 INFO  govee::commands::serve]                 color_temp=None segment_rgb=None
[2024-01-25T16:25:23 INFO  govee::commands::serve]   Undoc: room=None supports_iot=true ble_only=false
[2024-01-25T16:25:23 INFO  govee::commands::serve]   Quirk { sku: "H713A", icon: "mdi:heat-wave", supports_rgb: false, supports_brightness: false, color_temp_range: None, avoid_platform_api: false, ble_only: false, lan_api_capable: false, device_type: Heater, platform_temperature_sensor_units: Some(Farenheit), platform_humidity_sensor_units: None, iot_api_supported: false, show_as_preset_buttons: None }
[2024-01-25T16:25:23 INFO  govee::commands::serve] 
[2024-01-25T16:25:23 INFO  govee::commands::serve] Aura Lamp (3C:DD:C2:32:xx:xx:xx:xxH6052)
[2024-01-25T16:25:23 INFO  govee::commands::serve]   LAN API: ip=x.y.z.c
[2024-01-25T16:25:23 INFO  govee::commands::serve]   Platform API: devices.types.light. supports_rgb=true supports_brightness=true
[2024-01-25T16:25:23 INFO  govee::commands::serve]                 color_temp=Some((2000, 9000)) segment_rgb=Some(0..15)
[2024-01-25T16:25:23 INFO  govee::commands::serve]   Undoc: room=Some("Second Bedroom") supports_iot=true ble_only=false
[2024-01-25T16:25:23 INFO  govee::commands::serve]   Quirk { sku: "H6052", icon: "mdi:light-bulb", supports_rgb: true, supports_brightness: true, color_temp_range: Some((2000, 9000)), avoid_platform_api: false, ble_only: false, lan_api_capable: true, device_type: Light, platform_temperature_sensor_units: None, platform_humidity_sensor_units: None, iot_api_supported: true, show_as_preset_buttons: None }
[2024-01-25T16:25:23 INFO  govee::commands::serve] 
[2024-01-25T16:25:23 INFO  govee::service::http] http server addr is 0.0.0.0:8056
[2024-01-25T16:25:28 INFO  govee::service::hass] Wait 1.65s for hass to settle on 33 entity configs
[2024-01-25T16:25:30 INFO  govee::service::hass] MQTT connected with status=CONNACK code 0: Connection Accepted.
[2024-01-25T16:25:43 INFO  govee::service::state] requesting update via Platform API Office Heater (6B:9B:60:74:F4:35:37:9E

Additional Logs

No response

Home Assistant Logs

No response

Anything else?

After a restart of the addon the become available again

wez commented 5 months ago

Maybe that "Wait X s for hass" delay should be longer? Try setting the debug level to mosquitto_rs=trace,info so that you can see what is being sent. The critical mqtt message is sent to gv2mqtt/availability to tell hass that the addon is online and available. If you see that being sent by the addon but hass doesn't think things are online, then it is possible that it is a timing issue with hass.

Another interesting message is homeassistant/status which is hass telling everybody else that it is online. govee2mqtt should re-publish its availability when hass sends that message.

morrisb74 commented 5 months ago

b9845f46_govee2mqtt_2024-01-25T16-55-08.162Z.log

Here you go

wez commented 5 months ago
INFO  govee::service::hass Wait 1.65s for hass to settle on 33 entity configs
DEBUG mosquitto_rs::lowlevel Client govee2mqtt/a50707b4e51347e184e513bd63c534ba sending PUBLISH (d0, q0, r0, m99, 'gv2mqtt/availability', ... (6 bytes))
DEBUG mosquitto_rs::lowlevel Client govee2mqtt/a50707b4e51347e184e513bd63c534ba received PUBLISH (d0, q0, r0, m0, 'homeassistant/status', ... (6 bytes))
INFO  govee::service::hass Home Assistant status changed: online
INFO  govee::service::hass Wait 1.65s for hass to settle on 33 entity configs
DEBUG mosquitto_rs::lowlevel Client govee2mqtt/a50707b4e51347e184e513bd63c534ba sending PUBLISH (d0, q0, r0, m153, 'gv2mqtt/availability', ... (6 bytes))

looks like govee2mqtt is sending the right things at the right times; the issue must be local to your install somehow. Is there a problem with your broker? Is there a problem with hass?

morrisb74 commented 5 months ago

Broker is EMQX and Hass is working properly (HA-Green)

lesgrebe commented 5 months ago

Hello, first of all thx. for your time and effort for this cool addon!

Same here on my environment (Raspi4 8GB), sometimes after Hass restart my lamp (H6072) ist not available. After restart the addon if Hass is alive a couple of minutes, everything works like a charm. Using Mosquitto broker (v6.4.0)...

Version Hass:

image

Logging: b9845f46_govee2mqtt_2024-01-27T08-18-47.870Z.log

wez commented 5 months ago

is there anything in home assistant's mqtt integration logs that might explain what is happening?

Idaho947 commented 5 months ago

Same here on a VM with HAOS. I'll check the log but don't see anything. I'll chek more next time.

Idaho947 commented 5 months ago

I don't see anything in log :

Mosquito : image

Govee2Mqtt : image

Restarte HA à 11:50:45

github-actions[bot] commented 5 months ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

Krocko commented 5 months ago

I have the same problem.

morrisb74 commented 5 months ago

I have the same problem.

I use an automation to restart govee2mqtt after a HA restart to “fix” the problem.

bbrks commented 5 months ago

I have the same problem.

I use an automation to restart govee2mqtt after a HA restart to “fix” the problem.

Me too. This might help some people:

alias: Reload MQTT if Govee Unavailable
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.coving_rgb_light_status
    to: unavailable
  - platform: homeassistant
    event: start
condition: []
action:
  - service: homeassistant.reload_config_entry
    metadata: {}
    data:
      entry_id: 01eb971ec0960879de5840ac238200df # mqtt device entry id
mode: single
morrisb74 commented 5 months ago

Here is mine, which just restarts it 30 secs after HA: (So you can pick and choose your poison :D )

alias: Restart Govee2MQTT
description: "Restart Govee2MQTT after HA Restart"
trigger:
  - platform: homeassistant
    event: start
condition:
  - condition: state
    entity_id: binary_sensor.govee_to_mqtt_bridge_running
    state: "on"
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: hassio.addon_restart
    data:
      addon: b9845f46_govee2mqtt
mode: single
vascozorrinho commented 4 months ago

same problem here! thanks for the automation suggestions

i4mr000t commented 4 months ago

Same problem here

anthonyjhicks commented 4 months ago

I too have the same problem and resolved this by creating an automation to restart Govee2mqtt after HA starts.

There must be a Home Assistant service dependency somewhere in the Govee2mqtt start up that is not being met immediately after HA restart but I also cannot glean it from the logs to help troubleshoot this Issue.

lux4rd0 commented 4 months ago

Same problem here, but I'm running this in its Docker container. I love this integration - except when it doesn't work and I have to restart it. Do you know if there is anything to look for here?

morrisb74 commented 4 months ago

There hasn’t been an update for a while. A few automations have been posted here, you might be able to use those.

lux4rd0 commented 4 months ago

There hasn’t been an update for a while. A few automations have been posted here, you might be able to use those.

Those only work with HAOS... happy to continue logs or other testing...

wild-a commented 3 months ago

I have the same issue. After a month of working perfectly, now going unavailable frequently.

TarheelGrad1998 commented 1 month ago

Same issue here, running core on docker. I've always resolved it by manually restarting the MQTT integration, but that got old so I decided to log a bug and found this. Good idea with the automations, I'll try that.

lux4rd0 commented 1 month ago

I ended up going down the path of using this:

https://github.com/AlexxIT/SSHCommand

Since I'm running in Docker, it does what I need it to do. It keeps the "partner" factor happy, so I don't lose control over the Govee automations. :)

TarheelGrad1998 commented 1 month ago

Glad that works for you, but I am also in Docker, and I don't have to touch g2mqtt, just the mqtt integration. Which is....odd, but works without those kind of shenanigans.

dpeite commented 1 month ago

Same problem with docker container. When launching the docker compose file with all my services, the govee2mqtt service is still unavailable from HA after the start up.

My workaround is to force the launch of the container when HA docker is up and running using depends_on and a healthcheck. Example of my docker-compose.yml:

  homeassistant:
    container_name: home-assistant
    depends_on:
      - mosquitto
      - postgres
    image: homeassistant/home-assistant:stable
    restart: always
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost/manifest.json"]
      interval: 40s
      timeout: 10s
      retries: 2
    network_mode: host

  govee2mqtt:
    image: ghcr.io/wez/govee2mqtt:latest
    container_name: govee2mqtt
    restart: always
    depends_on:
      homeassistant:
        condition: service_healthy
    environment:
     - GOVEE_MQTT_HOST=127.0.0.1
     - GOVEE_MQTT_PORT=1883
     - GOVEE_TEMPERATURE_SCALE=C
     - RUST_LOG_STYLE=always
     - TZ=Europe/Madrid
    network_mode: host

I use an interval of 40s in the healthcheck, but maybe it's necessary to increase or decrease the value