Show sunrise and sunset time in FHEM

In this tutorial I will guide you how to show the sunrise time in FHEM

Prerequesites: – a working FHEM version

FHEM Sunrise Sunset Sundown Time

  1. Open the FHEM configuration file (fhem.cfg) under Edit files.
  2. Add the following global attributes to set your location.
    attr global latitude 51.345753
    attr global longitude 12.38213
    

    Replace the latitude and longitude values with your desired location. The decimal values of your location can be determined here.

  3. To save the values for sunrise and sunset we are going to create two dummies
    define Sunrise dummy
    define Sunset dummy
    
  4. As the values need to be generated every day after 12 pm we define the following function
    define sun_riseSet_timer at *03:00:00 { my $s = sunrise();; fhem("set Sunrise $s");; $s = sunset();; fhem("set Sunset $s");; }
    

    This way, the next time of sunrise and sunsets will be set every day at 0.05 am to the dummies.

  5. Now we need to assign the room “Weather” to the dummies
    attr Sonnenaufgang room Weather
    attr Sonnenuntergang room Weather
    

Finally, your code should look like this:


attr global latitude 51.339695
attr global longitude 12.373075

############## Sunrise/Sunset ###################

define Sunrise dummy
attr Sunrise room Weather

define Sunset dummy
attr Sunset room Weather

define sun_riseSet_timer at *00:05:00 { my $s = sunrise();; fhem("set Sunrise $s");; $s = sunset();; fhem("set Sunset $s");; }

You can use the following commands if you want to know the brightness of the sunrise or sundown

sunrise("REAL"); #Sun rises or sets at horizon
sunrise("CIVIL"); #The sun is behind the horizon but it is still bright
sunrise("NAUTIC") #Shapes can be still distinguished against the horizon (e.g. on the sea)
sunrise("ASTRONOMIC") #It is completely dark

More information to sunrise() can be found on the Commandref page.

Please leave a comment if you have questions or ideas.

Leave your vote

9 points
Upvote Downvote

Total votes: 2

Upvotes: 2

Upvotes percentage: 100.000000%

Downvotes: 0

Downvotes percentage: 0.000000%

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.