hass-circadian_lighting icon indicating copy to clipboard operation
hass-circadian_lighting copied to clipboard

HA 2021.12 - Error while setting up circadian_lighting platform for switch

Open TheGroundZero opened this issue 2 years ago • 4 comments

Logger: homeassistant.components.switch
Source: custom_components/circadian_lighting/switch.py:285
Integration: Switch (documentation, issues)
First occurred: 14:27:13 (2 occurrences)
Last logged: 14:27:13

    Error adding entities for domain switch with platform circadian_lighting
    Error while setting up circadian_lighting platform for switch

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 613, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 748, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 541, in _async_write_ha_state
    extra_state_attributes = self.extra_state_attributes
  File "/config/custom_components/circadian_lighting/switch.py", line 269, in extra_state_attributes
    return {"hs_color": self._hs_color, "brightness": self._brightness, "colortemp": self._color_temperature()}
  File "/config/custom_components/circadian_lighting/switch.py", line 291, in _color_temperature
    if not self._is_sleep()
  File "/config/custom_components/circadian_lighting/switch.py", line 285, in _is_sleep
    and self.hass.states.get(self._sleep_entity).state in self._sleep_state
AttributeError: 'NoneType' object has no attribute 'state'

TheGroundZero avatar Dec 14 '21 14:12 TheGroundZero

It looks like whatever entity you have configured in CL as sleep_entity is not available at the time CL tries to start up - can you share that configuration?

claytonjn avatar Dec 15 '21 00:12 claytonjn

I thought that was an issue with the 2021.12 upgrade, but the issue may actually be on my end?

My media_player sometimes goes unavailable in HA, so this may indeed be the reason of the issue. The fact that the circadian lighting switch magically seems to have re-appeared, seems to confirm this as well.

# Circadian lighting
# https://github.com/claytonjn/hass-circadian_lighting
- platform: circadian_lighting
  name: Living room circadian
  lights_ct:
    - light.living_lamp_1_level_light_color_on_off
    - light.living_lamp_2_level_light_color_on_off
  sleep_entity: media_player.tv_livingroom
  sleep_state: on
  sleep_brightness: 1
  sleep_colortemp: 10000

TheGroundZero avatar Dec 15 '21 10:12 TheGroundZero

Same problem here. Looks like CL is started before in my case boolean sleep entity which result in the same error

maxoss avatar Dec 15 '21 12:12 maxoss

Is there a workaround for this?

pakshuang avatar Apr 06 '22 05:04 pakshuang