Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Ensure sun conditions are using the right date #23664
When evaluating sun conditions, take care to ensure we are comparing current time with solar event times for the correct day.
The added test cases:
all fail without this patch because events from the wrong (already passed) day were compared with.
Fix by testing if we got solar events from the previous local day, and if we do, use events for the next local day.
However, the sun conditions are still unintuitive with this change,
This means this condition will not work:
condition: condition: or # 'when dark' condition: either after sunset or before sunrise - equivalent to a state condition on `sun.sun` of `below_horizon` conditions: - condition: sun after: sunset - condition: sun before: sunrise
This is very much related to the solar events using midnight in local time as a cutoff point instead of solar midnight (https://www.home-assistant.io/docs/scripts/conditions/#sun-condition).
@armills What was discussed on discord was to change the definition of the sun conditions to, for example, use astronomical midnight as cutoff point. I'll open an architecture issue for that.
Edit: Architecture issue suggesting changing cutoff point for the sun conditions: home-assistant/architecture#225
This PR intends to correct a bug where the wrong day is used when evaluating sun conditions. It would be great if the changes could be reviewed.
The discussion about if the sun conditions make sense or not are not related to the bug as such.
(Also, there is a warning in the docs against using the sun conditions: https://www.home-assistant.io/docs/scripts/conditions/#sunsetsunrise-condition )