core: Sunset/Sunrise condition not working as per documentaion
The problem
The Sun integration has two conflicting conditions for night. As seen here:

The first condition
condition:
- condition: sun
after: sunset
before: sunrise
always returns false.
The second condition:
condition:
condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
Does return true at night.
I attempted to remove the first condition from the documentation in a PR but was told by Frenk that if the first condition is not returning true at night it is an issue with the sun integration. See: https://github.com/home-assistant/home-assistant.io/pull/22486
What version of Home Assistant Core has the issue?
core-2022.4.7
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Sun
Link to integration documentation on our website
https://www.home-assistant.io/docs/scripts/conditions/#sunsetsunrise-condition
Diagnostics information
No response
Example YAML snippet
- id: 52289855-75f5-437f-a28c-933e23446226
alias: 'Test Sun Condition' ### Does not operate as expected, input number is not incremented at night ###
trigger:
platform: time_pattern
minutes: "/1"
condition:
condition: sun
before: sunrise
after: sunset
action:
- service: input_number.increment
target:
entity_id: input_number.test
- id: 332125de-61c8-4c81-8c4c-3d0c4389617d
alias: 'Test Sun OR Condition' ### Operates as expected, increments input number at night ###
trigger:
platform: time_pattern
minutes: "/1"
condition:
condition: or
conditions:
- condition: sun
before: sunrise
- condition: sun
after: sunset
action:
- service: input_number.increment
target:
entity_id: input_number.test_or
Anything in the logs that might be useful for us?
No response
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 20 (7 by maintainers)
Commits related to this issue
- Fix Issue #70781 — committed to janick/core by janick 2 years ago
- Fix Issue #70781 — committed to janick/core by janick 2 years ago
This is definitely one of the most asked questions on the forums and the documentation does not help people because it contradicts itself.
The proposed change to the documentation was rejected and the rejecter suggested to create an issue to fix the first condition as he believes it’s a bug. I tend to agree with him.
If we can fix the first condition, the question will not come up on the forums and we will have a more concise way to check for ‘night’.