Enhanced Sun component

Hi there,
I was pointing to this thread, because I search for a possibility to create a value to below_horizon -30min. Sometimes it is really dark minimal before the sunset. And it seems to be a time difference between sunset and the value below horizon works.

Releated to Alternatives to below horizon

If I understand it right, I can use the elevation, but should my value above or under the default -0.833?

elevation:
  above: -0.833 #( more or less)
  name: before_sundown

Thanks Micha

I suggested a solution in your original topic which does not require the use of my custom sun2 integration.

But to answer your specific question, the binary elevation sensor does not have an option for below; it only accepts above, with the default value being -0.833. So, if you configure:

binary_sensor:
  - platform: sun2
    monitored_conditions:
      - elevation

You’ll get a sensor named binary_sensor.above_horizon that will be on between sunrise and sunset, and off otherwise.

Released 2.1.0

Add phase sensors

Add new sun phase sensors. One emulates the behavior of the deCONZ Daylight Sensor. The other has more common states and other useful attributes.

1 Like

Released 2.1.1

Fixed a typo that caused blue hour attribute to be wrong and rising attribute to be missing for the new sun_phase sensor.

1 Like

Hi Phil,

maybe I just didnt see it because of the time of year, but currently, the warning for Sun elevation in binary_sensor Astronomical Dawn shows 3 times during a regular startup sequence:

once at the very beginning, and twice at the very end:

<snip>
2022-06-17 17:40:37 WARNING (SyncWorker_5) [homeassistant.loader] We found a custom integration sun2 which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

<snip>


2022-06-17 17:40:41 WARNING (MainThread) [custom_components.sun2.binary_sensor] Astral Above Astronomical Dawn: Sun elevation will not reach -18.000000 again until 2022-07-22


<snip>


2022-06-17 17:43:00 WARNING (MainThread) [custom_components.sun2.binary_sensor] Astral Above Astronomical Dawn: Sun elevation will not reach -18.000000 again until 2022-07-22
2022-06-17 17:43:03 WARNING (MainThread) [custom_components.sun2.binary_sensor] Astral Above Astronomical Dawn: Sun elevation will not reach -18.000000 again until 2022-07-22
2022-06-17 17:43:10 INFO (MainThread) [homeassistant.setup] Setting up ffmpeg
2022-06-17 17:43:10 INFO (MainThread) [homeassistant.setup] Setup of domain ffmpeg took 0.2 seconds

<ready>

is this to be expected?

yaml:

binary_sensor:

  - platform: sun2
    entity_namespace: astral
    monitored_conditions:
      - elevation:
          above: -18
          name: Above Astronomical Dawn

The reason there are three warning messages is because the entity is being updated three times. The first one is when the entity initializes itself. The other two are due to the HA core firing the core_config_updated event twice during system startup:

2022-06-17 13:16:05 INFO (MainThread) [homeassistant.core] Starting Home Assistant
2022-06-17 13:16:05 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event core_config_updated[L]>
2022-06-17 13:16:05 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event homeassistant_start[L]>
2022-06-17 13:16:05 DEBUG (MainThread) [custom_components.sun2.binary_sensor] Astral Above 71.86: above = 71.860000, elevation = 71.252818
2022-06-17 13:16:05 WARNING (MainThread) [custom_components.sun2.binary_sensor] Astral Above 71.86: Sun elevation will not reach 71.860000 again until 2022-06-19
2022-06-17 13:16:05 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event core_config_updated[L]>
2022-06-17 13:16:05 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event homeassistant_started[L]>
2022-06-17 13:16:05 DEBUG (MainThread) [custom_components.sun2.binary_sensor] Astral Above 71.86: above = 71.860000, elevation = 71.252818
2022-06-17 13:16:05 WARNING (MainThread) [custom_components.sun2.binary_sensor] Astral Above 71.86: Sun elevation will not reach 71.860000 again until 2022-06-19

I don’t know why HA fires this event twice, but there’s not much I can do about it, since the entity needs to update if the core config (i.e., location) is updated. Now, of course, the config isn’t being updated, but for some reason the core fires this event two times anyway.

I suppose I might be able to filter out any messages that happen before the homeassistant_started event, but I’m not sure that wouldn’t hide potential other issues.

EDIT: I added code to filter out any errors or warnings until after the core is fully running. That filters out the first two occurrences of that message, and now it will only show up once (unless, of course, you do update the core config. :wink: )

I also found a bug which I’ll fix, too, and release a new version soon.

Released 2.1.2

Filters out binary sensor warning or error messages before HA core is fully running. Before this, as discussed above, these messages showed up three times in the log. Now they should only show up once.

Also fix bug in elevation binary sensor if threshold is never reached.

2 Likes

Let’s ask @bdraco . Nick pardon the tag, but since we/you’re in the process of optimizing the startup, it seemed quickest to copy you in this .
If nothing please ignore

Its been a while, but I think when we added it in Make the frontend available sooner (Part 1 of 2) by bdraco · Pull Request #36263 · home-assistant/core · GitHub, its for:

So, it seems it was something to get the frontend to respond to core state changes (even if the actual “config” hasn’t changed.) Hmm, seems like there should be two different events then: one just for actual config changes (that would most likely be used just in the backend), and a state changed event (that maybe??? includes config changes as well as actual state changes.) Hmm. Seems kind of disruptive to fire an event multiple times for “config” changes when the config isn’t actually changing, causing possibly many entities to update for no reason. But, I suspect it might be more complicated than that. :slightly_smiling_face:

It could definitely be made more efficient. Since there is long list of things that are far less efficient ahead of it, I expect it may be a while before we get there. The good news is that we have been making great progess in this area recently so the list is shrinking instead of growing which is a nice change.

2 Likes

hehe, we all know you’re on top of it.

so should we make an issue of sorts: or is it on your list now :wink:
no hurry, just dont forget…
please.

Probably something to remind me about in 3-4 months once we are through this cycle of optimizations

sure!
note to self (“dont forget”) I am terrible at that.
especially now Phil filters the messages…
great

Trying to get this as a sensor… since i have my sensors in my config like this…

sensor: !include_dir_merge_list includes/sensors/

I can’t just put the straight config in my config file so I have to actually create a sensor in the sensors dir…
Keep getting errors…

- platform: sun2
  sensors:
    sun2:
      monitored_conditions:
        - solar_midnight

Invalid config for [sensor.sun2]: [sensor] is an invalid option for [sensor.sun2]. Check: sensor.sun2->sensor. (See ?, line ?).

It’s setup correctly but where’s the error I’m not seeing it…

That is because you put in extra sensor: and sun2: levels that should not be there if I look at the docs. remove those and decrease the indentation of the parts below it accordingly. monitored conditions: should be the first level below platform: sun2

Hi Phil,

Fyi: the warning at startup is no longer displayed, but the 2 at the end are still 2:

2022-06-20 10:08:25 WARNING (MainThread) [custom_components.sun2.binary_sensor] Astral Above Astronomical Dawn: Sun elevation will not reach -18.000000 again until 2022-07-22
2022-06-20 10:08:26 WARNING (MainThread) [custom_components.sun2.binary_sensor] Astral Above Astronomical Dawn: Sun elevation will not reach -18.000000 again until 2022-07-22

check this:

sensor:

  - platform: sun2
    monitored_conditions:

      - solar_midnight

this is in a standalone package.
If you have it under the sensor: key already, with those include_dir_merge, just take out the - sensor: here, and make it

 - platform: sun2
   monitored_conditions:
     - solar_midnight

directly

No sir that will not work I get this and it throws a config error… and it will because of the entire line above it. Suggestions how to fix that?

sun2

You said it yourself: you can’t just put it in the config like that, it needs to be in a separate file in the sensors dir, with the .yaml extension. Also, as compared to the sun2 integration documentation, you need to remove the line “sensor:” and decrease all indentation by 2 spaces because of that. The first - should be in the first column.

So create a sun2sensors.yaml in the sensors directory, containing:

- platform: sun2
  monitored_conditions:
    - solar_midnight

Of course you can add more sensors if it works.

1 Like