In this tutorial I will guide you how to show the sunrise time in FHEM
Prerequesites: – a working FHEM version
- Open the FHEM configuration file (fhem.cfg) under Edit files.
- 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.
- To save the values for sunrise and sunset we are going to create two dummies
define Sunrise dummy define Sunset dummy
- 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.
- 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.