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.
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:
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>
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. )
I also found a bug which I’ll fix, too, and release a new version soon.
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.
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
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.
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.
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
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
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
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: