ha-sun2: Sun_Phase Sensor not updating correctly

For a couple of days my sun phase sensor has been failing to update correctly in the morning.

It is just missing out some of the phases, I still get updates at noon and in the evening, but its staying at night until solar noon. Error log:

This error originated from a custom integration.

Logger: custom_components.sun2.sensor
Source: custom_components/sun2/sensor.py:125
Integration: sun2
First occurred: November 4, 2022 at 23:52:43 (6 occurrences)
Last logged: November 4, 2022 at 23:52:43

London Sun Phase: Failed to find the time at elev: -12.000
London Sun Phase: Failed to find the time at elev: -6.000
London Sun Phase: Failed to find the time at elev: -4.000
London Sun Phase: Failed to find the time at elev: -0.833
London Sun Phase: Failed to find the time at elev: 6.000

my .yaml configuration:


- platform: sun2
  entity_namespace: London
  latitude: #########
  longitude: ########
  time_zone: Europe/London
  elevation: 11
  monitored_conditions:
    - sunrise
    - sunset
    - sun_phase
    - dawn
    - dusk
    - solar_noon
    - solar_midnight
    - daylight
    - night

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Ok, looks like you fixed it:

Heres my logs:


2022-11-08 23:52:57.014 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: tL = 2022-11-08 23:52:57+00:00/-54.563, cur = 2022-11-08 23:52:57+00:00/-54.563, tR = 2022-11-09 11:52:54+00:00/20.895, rising = True
2022-11-08 23:52:57.015 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = -18.000: t0 = 2022-11-09 05:16:29+00:00/-18.763, t1 = 2022-11-09 05:26:29+00:00/-17.236 -> est = 2022-11-09 05:21:29+00:00/-17.999[ +0.001]
2022-11-08 23:52:57.016 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = -12.000: t0 = 2022-11-09 05:56:04+00:00/-12.752, t1 = 2022-11-09 06:06:04+00:00/-11.252 -> est = 2022-11-09 06:01:05+00:00/-11.998[ +0.002]
2022-11-08 23:52:57.017 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = -6.000: t0 = 2022-11-09 06:36:42+00:00/ -6.729, t1 = 2022-11-09 06:46:42+00:00/ -5.276 -> est = 2022-11-09 06:41:43+00:00/ -5.999[ +0.001]
2022-11-08 23:52:57.018 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = -4.000: t0 = 2022-11-09 06:50:32+00:00/ -4.722, t1 = 2022-11-09 07:00:32+00:00/ -3.280 -> est = 2022-11-09 06:55:33+00:00/ -3.999[ +0.001]
2022-11-08 23:52:57.019 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = -0.833: t0 = 2022-11-09 07:11:02+00:00/ -1.744, t1 = 2022-11-09 07:21:02+00:00/ +0.022 -> est = 2022-11-09 07:16:11+00:00/ -0.935[ -0.102]
2022-11-08 23:52:57.019 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = -0.833: t0 = 2022-11-09 07:16:11+00:00/ -0.935, t1 = 2022-11-09 07:21:02+00:00/ +0.022 -> est = 2022-11-09 07:16:42+00:00/ -0.847[ -0.014]
2022-11-08 23:52:57.019 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = -0.833: t0 = 2022-11-09 07:16:42+00:00/ -0.847, t1 = 2022-11-09 07:21:02+00:00/ +0.022 -> est = 2022-11-09 07:16:46+00:00/ -0.836[ -0.003]
2022-11-08 23:52:57.022 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: trg = +6.000: t0 = 2022-11-09 08:05:45+00:00/ +5.404, t1 = 2022-11-09 08:15:45+00:00/ +6.594 -> est = 2022-11-09 08:10:46+00:00/ +6.004[ +0.004]
2022-11-08 23:52:57.022 DEBUG (MainThread) [custom_components.sun2.sensor] London Sun Phase: _update time: 0:00:00.009470

Many thanks for sorting this out, it is a key part of all my lighting controls so is very important to me.

I found the problem. I’m working on a fix. I hope to release a beta version with the fix soon.