bisquit2003
(Alexey Savelev)
August 27, 2022, 10:07pm
1
I wanted to make an automation in which the light is turned on by a motion trigger and in the condition the work from sunset to sunrise.
But at 00:00 this condition “broke” because the day has changed and the system is waiting for a new sunset.
I suggest adding the option “sunrise of the next day” or “sunset of the previous day”.
at the moment, I solved the problem like this: 2 time intervals and the “or” condition from sunset to 23:59:59 and from 00:00:00 to sunrise
tom_l
August 27, 2022, 10:53pm
2
This works as a condition for sunset to sunrise:
condition:
condition: or
conditions:
- condition: sun
after: sunset
- condition: sun
before: sunrise
As does this:
condition:
- condition: state
entity_id: sun.sun
state: below_horizon
According to the developers the following should work but does not :
condition:
- condition: sun
after: sunset
before: sunrise
There is an issue open to fix this particular case.
opened 12:10PM - 26 Apr 22 UTC
integration: sun
### The problem
The Sun integration has two conflicting conditions for night.… As seen here:
![Screenshot 2022-04-26 at 22-00-20 Conditions](https://user-images.githubusercontent.com/10679300/165295450-9ac229e9-26cc-4486-b5cc-8a368953b91d.png)
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
```yaml
- 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_
3 Likes