Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESPHome RGBCCT causes repeated "Connection error occurred: division by zero" disconnections #89846

Closed
kylegordon opened this issue Mar 17, 2023 · 8 comments · Fixed by #91424
Closed

Comments

@kylegordon
Copy link

The problem

When using an ESPHome H801 dimmer device with the following configuration, turning the device outputs on causes it to be repeatedly disconnected from the Home-Assistant instance.

What version of Home Assistant Core has the issue?

core-2023.3.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

ESPHome

Link to integration documentation on our website

https://www.home-assistant.io/integrations/esphome/

Diagnostics information

config_entry-esphome-483d73c2800fe33a60f4fa16f6a951f5.json.txt

Example YAML snippet

This is the configuration of the device, a common 5 channel H801 LED dimmer, for RGB, Cold White and Warm White.

---
substitutions:
  device_name: tin_hut_shelf_lights_bench
  device_description: Tin Hut Shelf Light Bench
  friendly_name: Tin Hut Shelf Lights Bench

api:

ota:

wifi:
  ssid: MyWifi
  password: YourWifi

esphome:
  name: ${device_name}
  comment: ${device_description}
  platform: ESP8266
  board: esp01_1m

# Enable logging
logger:

# captive_portal:

web_server:
  port: 80

# RGB
output:
  - platform: esp8266_pwm
    pin: 12
    frequency: 1000 Hz
    id: pwm_b
  - platform: esp8266_pwm
    pin: GPIO13
    frequency: 1000 Hz
    id: pwm_g
  - platform: esp8266_pwm
    pin: GPIO15
    frequency: 1000 Hz
    id: pwm_r
  - platform: esp8266_pwm
    pin: GPIO14
    frequency: 1000 Hz
    id: pwm_w2
  - platform: esp8266_pwm
    pin: GPIO04
    frequency: 1000 Hz
    id: pwm_w1

# RGB, RGBW, RGBWW also available
light:
  - platform: rgbww
    name: ${friendly_name}
    red: pwm_r
    green: pwm_g
    blue: pwm_b
    cold_white: pwm_w1
    warm_white: pwm_w2
    id: thelight
    effects:
      - random:
      - strobe:
      - flicker:
          alpha: 50%  # The percentage that the last color value should affect the light. More or less the “forget-factor” of an exponential moving average. Defaults to 95%.
          intensity: 50%  # The intensity of the flickering, basically the maximum amplitude of the random offsets. Defaults to 1.5%.
      - lambda:
          name: Throb
          update_interval: 1s
          lambda: |-
            static int state = 0;
            auto call = id(thelight).turn_on();
            // Transtion of 1000ms = 1s
            call.set_transition_length(1000);
            if (state == 0) {
              call.set_brightness(1.0);
            } else {
              call.set_brightness(0.01);
            }
            call.perform();
            state += 1;
            if (state == 2)
              state = 0;

Anything in the logs that might be useful for us?

2023-03-17 08:02:41.662 ERROR (MainThread) [homeassistant] Error doing job: Fatal error: protocol.data_received() call failed.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 876, in _read_ready__data_received
    self._protocol.data_received(data)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/_frame_helper.py", line 195, in data_received
    self._callback_packet(msg_type_int, bytes(packet_data))
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/_frame_helper.py", line 110, in _callback_packet
    self._on_pkt(Packet(type_, data))
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/connection.py", line 683, in _process_packet
    handler(msg)
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 376, in on_msg
    on_state(cls.from_pb(msg))
  File "/usr/src/homeassistant/homeassistant/components/esphome/entry_data.py", line 210, in async_update_state
    self.state_subscriptions[subscription_key]()
  File "/usr/src/homeassistant/homeassistant/components/esphome/__init__.py", line 777, in _on_state_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 559, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 602, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 1018, in state_attributes
    data.update(self._light_internal_convert_color(color_mode))
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 966, in _light_internal_convert_color
    *rgbww_color, self.min_color_temp_kelvin, self.max_color_temp_kelvin
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 888, in min_color_temp_kelvin
    return color_util.color_temperature_mired_to_kelvin(self.max_mireds)
  File "/usr/src/homeassistant/homeassistant/util/color.py", line 621, in color_temperature_mired_to_kelvin
    return math.floor(1000000 / mired_temperature)
ZeroDivisionError: division by zero
2023-03-17 08:02:41.681 WARNING (MainThread) [aioesphomeapi.connection] tin_hut_shelf_lights_bench @ 172.24.32.86: Connection error occurred: division by zero

Additional information

Some logs from the device itself

08:09:44 [D] [light:035] 'Tin Hut Shelf Lights Bench' Setting:
08:09:44 [D] [light:046] State: ON
08:09:44 [D] [light:084] Transition length: 1.0s
08:09:44 [W] [api.connection:083] Home Assistant 2023.3.4 (172.24.32.13): Connection closed
08:09:44 [D] [api:102] Accepted 172.24.32.13
08:09:44 [D] [api.connection:920] Home Assistant 2023.3.4 (172.24.32.13): Connected successfully
08:09:44 [W] [api.connection:083] Home Assistant 2023.3.4 (172.24.32.13): Connection closed
08:09:44 [D] [api:102] Accepted 172.24.32.13
08:09:44 [D] [api.connection:920] Home Assistant 2023.3.4 (172.24.32.13): Connected successfully
08:09:44 [D] [api:102] Accepted 172.24.32.13
08:09:44 [W] [api.connection:083] Home Assistant 2023.3.4 (172.24.32.13): Connection closed
08:09:44 [D] [api.connection:920] Home Assistant 2023.3.4 (172.24.32.13): Connected successfully
08:09:44 [D] [api:102] Accepted 172.24.32.13
...
@home-assistant
Copy link

Hey there @OttoWinter, @jesserockz, mind taking a look at this issue as it has been labeled with an integration (esphome) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of esphome can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign esphome Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


esphome documentation
esphome source
(message by IssueLinks)

@kylegordon
Copy link
Author

Additionally, the devices are running ESPHome 2023.3.0

@kylegordon
Copy link
Author

Still seems to be an issue with Home Assistant 2023.5.2 and ESPHome 2023.4.4

kylegordon added a commit to kylegordon/home-assistant-config that referenced this issue May 8, 2023
@jcollie
Copy link

jcollie commented May 25, 2023

I just got a CF-LBC from cloudfree.shop and am running into the same problem. ESPHome 2023.5.3, Home Assistant 2023.5.4.

@jcollie
Copy link

jcollie commented May 25, 2023

Setting the color temperatures of the white LEDs seems to be required in ESPHome, even though the ESPHome documentation says that it's optional. I don't know if these color temperatures are correct for my bulb but at least Home Assistant doesn't get a divide by zero error.

light:
  - platform: rgbww
    name: ${friendly_name}
    id: ${device_name}
    default_transition_length: 0s
    red: output_red
    green: output_green
    blue: output_blue
    cold_white: output_cw
    warm_white: output_ww
    cold_white_color_temperature: 6536 K
    warm_white_color_temperature: 2000 K

@bdraco
Copy link
Member

bdraco commented Jun 21, 2023

Likely fixed by #91424 but that PR isn't moving forward right now

@bdraco
Copy link
Member

bdraco commented Jun 21, 2023

similar issue with disconnections #93722

I think its better to fix via moving to kelvin though.

If #91424 doesn't move forward after I'll take a look after I finish with #94930 and the other platforms

@bdraco
Copy link
Member

bdraco commented Jun 21, 2023

As soon as #94960 is merged, I'll take a crack at fixing this one

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.