Skip to content

Major update & reorganization#152

Open
pnbruckner wants to merge 37 commits intomasterfrom
phase-take-2
Open

Major update & reorganization#152
pnbruckner wants to merge 37 commits intomasterfrom
phase-take-2

Conversation

@pnbruckner
Copy link
Copy Markdown
Owner

@pnbruckner pnbruckner commented Nov 9, 2025

Make sensors use observer elevation that should but haven't before

Simplify implementations using time_at_elevation instead of searching "elevation curve"

  • Phase & deCONZ Daylight sensors.
  • Elevation sensor.
  • Elevation binary sensor.

Miscellaneous changes

  • Make "point in time" sensors show next time event occurs in the future (up to one year) if it does not occur on the current day. Resolves High latitude Dawn and Dusk issue #145.
  • Make _update method async so potentially long running implementations (such as in Sun2ElevationBinarySensor and Sun2PointInTimeSensor) can be split up so as not to suck up too much CPU time.
  • Change sunrise & sunset elevation from -0.833 to -0.267 to account for change in astral package starting with release 2.0, which was first used in HA 2021.5.0b0.
  • Remove outdated manual entity name translations.
  • Fix atomic update mechanism by adding PARALLEL_UPDATES = 1 to binary_sensor.py & sensor.py.
  • Optimize sensors with yesterday, today & tomorrow attributes so that results are not calculated for the same date more than once.
  • Round timestamp states (and yesterday, today & tomorrow attributes) to the nearest second.
  • Add list of available time zone strings in config flow (like the Jewish Calendar built-in integration does.)
  • Fix bug that caused errors when trying to update disabled entities (e.g., when config entry was updated.)
  • Cache results of Location.midnight & Location.noon, since these results are (re)used by many entities. Also helps reduce configuration reload time.
  • Do not force remove suggesed_display_precision from PeriodOfTimeSensor entity registry entries, since core code just sets it back to 2. The force removal, that was added to work around a core issues, is no longer needed.
  • Make sure all sensor types handle the homeassistant.update_entity service/action correctly, or ignore it.
  • Do not use astral's local time conversion, but rather use HA's, since HA uses zoneinfo and astral uses pytz.
  • Drop support for HA versions before 2024.12.0.

Breaking Changes

  • Many sensors now take into account observer elevation where they did not before.
  • Some sensors, such as phase & elevation binary sensor, use a different threshold for the sunrise/sunset which can cause them to change at slightly different times they would have previously.
  • Point in time sensors may have a value of a time in a future date if the corresponding event does not occur in the current day, whereas they would have been unknown previously. The attributes (yesterday, today & tomorrow) still behave as they did before (i.e., their value will be None/null if the event does not occur on the given day.)
  • Elevation sensor no longer updates exactly at sunrise & sunset. Also, its state is no longer rounded to one decimal place. If previous behavior of (mostly) being a multiple of 0.5 degrees is still desired, this can be accomplished by leaving the display precision as one decimal place, and using a template with states(binary_sensor.xxx, rounded=True).

Previous implementations did not handle edge cases very well
and were still broken.
Change 0.833 to 0.267 for elevation of sun below horizon at sunrise & sunset. This changed when the astral package changed from 1.10.1 to 2.0 & later, which was used in HA starting w/ 2021.5.0b0.
@pnbruckner pnbruckner changed the title Make phase and deCONZ daylight sensors use observer elevation Make sensors use observer elevation that should but don't yet Dec 3, 2025
Split out most of Sun2EntityWithElvAdjs into Sun2EntityWithElvParams.
Add moving to nearest second back to elevation binary sensor.
Miscellaneous cleanup.
Differences between solar_elevation & time_at_elevation were causing
next elevation target to repeat for multiple updates. Using target
prevents this. And an analysis over several days shows that the
difference between target & actual were no more than about 0.25 degrees.
Also remove str from type of Sun2PointInTimeSensor class since it can
only result in a datetime (or None.) This was actually changed a long
time ago, but the type was not adjusted accordingly.
Sun2Entity class assumed async_update & anything called via async_request_call were
protected by a semaphore to make them atomic, but platform modules did not define the
required PARALLEL_UPDATES attribute. This change fixes that by adding it to
binary_sensor.py & sensor.py.

Elevation sensor uses "raw", unrounded elevation for state instead of "target" value.
This is potentially a breaking change since users/automations might depend on value
(mostly) being a multiple of 0.5 degrees. However, this can easily be compensated for
by using the states function w/ rounding=True in a template. This allows users to set
the display precision differently than the default value of one decimal place.

Change Sun2ElevationSensor in binary_sensor.py to Sun2ElevationBinarySensor
to differentiate from Sun2ElevationSensor in sensor.py.
Make Sun2ElevationBinarySensor._update and Sun2PointInTimeSensor._update
yield approximately every 50 milliseconds.
@pnbruckner pnbruckner changed the title Make sensors use observer elevation that should but don't yet Major update & reorganization Dec 11, 2025
…ethods

These methods were found to be calculating results for the same date multiple times.
Round timestamp states (and yesterday, today & tomorrow attributes) to nearest second.
Update every 2 min within 6 degrees of sunrise/sunset
and every 10 min otherwise.
 When config changes, only update entities that are enabled.
Do not force removal of suggested_display_precision from PeriodOfTimeSensor
entities because, 1) it's no longer needed, and 2) the core sensor logic
keeps changing it back to 2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

High latitude Dawn and Dusk issue Pace of entity updates Component goes a bit crazy around midnight Phase not reflecting altitude configuration

1 participant