Sun integration make update-interval configurable

The current sun-integration has in https://github.com/home-assistant/core/blob/8a144d16f58e452c100bcd8acb602176eaaf5d16/homeassistant/components/sun/entity.py lines 71-78 hardcoded update-intervals.

Since I would like to fine-tune the moment when my shutter-automation closes the shutters, I would prefer a much finer time-resolution around sun-set. And during the day I use my shutters for a shadowing-function, so even there I would prefer to configure shorter update intervals. Others might want to define shorter (or larger) intervals for other reasons throughout the day/night.

So my proposal is to have these 6 time-intervals as a configuration option, so everyone can set them according to the needs of the connected automations.

You can already do this with an automation and homeassistant.update_entity service.

Could you explain this a little more in detail? I wasn’t aware of this and it does not seem to work the way I try it.

I guess you mean having a time_pattern trigger running e.g. every second that executes homeassistant.update_entity with the sun-elevation and sun-azimuth entities as targets? I can see the automation gets executed, but azimuth and elevation does not update.

Here’s my code:

service: homeassistant.update_entity
metadata: {}
data: {}
target:
  entity_id:
    - sensor.sun_solar_elevation
    - sensor.sun_solar_azimuth

you’d call

service: homeassistant.update_entity
target:
  entity_id: sun.sun

If you’re not using the built in home assistant integration for sun, why are you creating a feature request here?

EDIT: I see those are new(er) entities when sun moved to the UI.

If they aren’t updating, that means the calculation doesn’t have any source information.

Of course I did try “sun.sun” also, but it does not cause an update either.

What do you mean with “it doesn’t have any source information”?
The only source a sun-position calculation needs is the time, so I guess/hope the integration has access to the system-time?

The sensor entities only update when sun.sun does a calculation. If update_entity isn’t working then the sun.sun entity does not employ a method to allow it to update.

I doubt this FR will ever be added, I could see an update allowed on sun.sun though to make update_entity work. You may want to switch to sun2 a custom integration instead.

I just looked into Sun2 and it looks like it is following somewhat the same update times.

Line 141-151

Sun2 have a pretty active developer though, so you might be able to get an update there.

1 Like

well the entities have an _update on them, so update_entity will work

Thanks a lot for these information, I will have a look into sun2.

Just for reference and completeness to this FR, I read the discussion on the merge request https://github.com/home-assistant/core/pull/23832
So the whole motivation behind reducing the 30-seconds update interval that the sun integration had before was obviously to reduce the number of log-entries caused by this.

I totally disagree with the whole reasoning behind that change.

If log-entries cause problems, then this should be fixed, not the guy who writes to the logs. The log-level of the entity could be adopted, the logging could be disabled, filtered or in any other suitable way adopted. But the assumption, that position updates are “useless” is quite arbitrary, because it judges over “legitimate” or “useless” uses of sun’s position. A normal user of a sun-device wants exactly this, a regular, fine-granular and accurate update of the position of the sun – not more and not less, but no assumption by the author of that device what uses are “useless” and what are not.

So I guess in fact, I’m questioning the whole change of this merge request.

Whether this changes anything here or not is a different story, but I thought to document at least my point of view.

1 Like

Which is why I said:

followed by a way to give you the ability to do your own updates