# \[SOLVED\] Turn on light in the morning, if sun is down

**URL:** <https://community.openhab.org/t/solved-turn-on-light-in-the-morning-if-sun-is-down/66427>\
**Category:** Scripts & Rules\
**Created:** [February 2, 2019, 5:28pm UTC](https://community.openhab.org/t/solved-turn-on-light-in-the-morning-if-sun-is-down/66427 "2019-02-02T17:28:51Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [November 28, 2019, 10:35pm UTC](https://community.openhab.org/t/solved-turn-on-light-in-the-morning-if-sun-is-down/66427/21 "2019-11-28T22:35:41Z")

</div>

> [@mrMeyer](#):
>
> DateTime Sunrise\_Time “Sunrise [%1$tH:%1$tM]” { channel=“astro:sun:local:rise#start” } D

This item’s name is **Sunrise\_Time**  
The Item is linked to an Astro channel.

To use that Item in a rule, you would refer to it by its name. Same way as you refer to your lights by Item name to send commands in the same rule.

Generally you’d be interested in the Item’s **state**.

`Sunrise_Time.state`

---

<div class="post-metadata">

**Author:** ![mrMeyer](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@mrMeyer](https://community.openhab.org/u/mrMeyer)\
**Post date:** [November 28, 2019, 10:54pm UTC](https://community.openhab.org/t/solved-turn-on-light-in-the-morning-if-sun-is-down/66427/22 "2019-11-28T22:54:10Z")

</div>

Thank you, Thank you, Thank you - it works!  
I believe I started all out by using Sunrise\_time, but I have tried so many different things I don’t remember any longer.

For anybody who would be in the same situation - here is my config.

Openhab 2.4  
Astrow Binding Installed and configured.

default.items

```csv
/* Astro */
DateTime Sunrise_Time "Sunrise [%1$tH:%1$tM]" { channel="astro:sun:local:rise#start" }
DateTime Sunset_Time "Sunset [%1$tH:%1$tM]" { channel="astro:sun:local:set#start" }

```

timer.rules

```csv
rule "Tænd spot facade når det er mørkt"
	when
		
        Time cron "0 47 23 ? * MON-FRI *"
	then
		if (now.isAfter((Sunrise_Time.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli)){
                       
                    Spot_Facade.sendCommand(ON) 
                    Spot_Terrasse.sendCommand(ON)
        }
end

```

Now I just have to find the best sunrise vs sunset and IsBefore or isAfter.

Thanks again 😃

[Previous page](https://community.openhab.org/t/solved-turn-on-light-in-the-morning-if-sun-is-down/66427.md?page=1)
