core: Errors when calling turn_on service for switch/flux with HA 0.94

Home Assistant release with the issue: 0.94

Last working Home Assistant release (if known): 0.93.2

Operating environment (Hass.io/Docker/Windows/etc.): Raspbian/Python 3.7.2/venv

Component/platform: switch/flux

Description of problem: When calling service switch.turn_on for switch.flux entity there is error in log:

2019-06-06 08:38:45 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/flux/switch.py", line 209, in async_flux_update
    if stop_time <= start_time:
TypeError: '<=' not supported between instances of 'NoneType' and 'datetime.datetime'

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

- platform: flux
  lights:
    - light.bulbs_salon
    - light.lamp_salon
  name: 'Flux'
  start_colortemp: 4400
  sunset_colortemp: 3850
  stop_colortemp: 3300
  mode: mired
  brightness: 255
  transition: 30
interval: 600

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 20 (15 by maintainers)

Commits related to this issue

Most upvoted comments

OK have figured it out. Pushed a PR that fixes the issue.

This has uncovered an issue in flux, it won’t properly handle latitudes where the Sun either doesn’t set, or doesn’t reach twilight. An elevation based approach where the colour temp is based on the elevation of the sun would be more appropriate.

If anyone needs a temporary fix in the meantime, here is an automation I’ve made that does the legwork of the flux switch - however, you need one automation per device to flux. Edit values as needed:

  - alias: Flux
    initial_state: True
    trigger:
      - platform: state
        entity_id: light.bedside_lamp
        from: 'off'
        to: 'on'
      - platform: numeric_state
        entity_id: sun.sun
        value_template: "{{ state.attributes.elevation }}"
        above: 0
      - platform: numeric_state
        entity_id: sun.sun
        value_template: "{{ state.attributes.elevation }}"
        above: -6
        below: 0
      - platform: numeric_state
        entity_id: sun.sun
        value_template: "{{ state.attributes.elevation }}"
        below: -6
    condition:
      condition: or
      conditions:
        - condition: state
          entity_id: light.bedside_lamp
          state: 'on'
    action:
      service: light.turn_on
      data_template:
        entity_id: light.bedside_lamp
        color_temp: "{% if states.sun.sun.attributes.elevation > 0 %}300{% elif -6 <= states.sun.sun.attributes.elevation <= 0 %}400{% else %}450{% endif %}"
        transition: 10

I got what appears to be the same error. Added below over multiple lines so we have one that is easier to read 😃

2019-06-06 20:28:59 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1150, in async_call
    self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1172, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 194, in handle_service
    required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 316, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 337, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/src/homeassistant/homeassistant/components/flux/switch.py", line 186, in async_turn_on
    await self.async_flux_update()
  File "/usr/src/homeassistant/homeassistant/components/flux/switch.py", line 209, in async_flux_update
    if stop_time <= start_time:
TypeError: '<=' not supported between instances of 'NoneType' and 'datetime.datetime'