This is just one example on how you can use the Astro binding to present a few elements on your custom sitemap. The sitemap has some visibility logic, showing only the elements important right now, e.g. sunset by day, sunrise at night. Overall it is a nice example to learn some basics about the connection between Items and Sitemaps and the possibilities of a sitemap definition.
Attention: This tutorial is a wiki article, meaning You can improve it. Please do!
Unicode characters:
This example uses Unicode symbols to make the presentation a bit more colorful. Be aware, that some moon unicode characters are not supported by the Basic UI font (Helvetica) but by other UIs e.g. the Android App. You can remove them, having this limitation in the example is also part of the learning curve
Installation
This tutorial addresses the following add-ons you need to install prior to the below configuration steps. Please install:
- The Astro Binding
- The NTP Binding (optional, needed for the Item
Current_DateTime
) - The MAP Transformation service
Configuration
Define things and items for the Astro Binding. Use Paper UI or config files as you prefer. Check the binding README for more details.
In this tutorial we are going with config files. Copy the following files to your configuration folder.
things/astro.things:
astro:sun:home [ geolocation="50.00000,10.00000", interval=300]
astro:moon:home [ geolocation="50.00000,10.00000", interval=300]
//Find your coordinates: http://www.gps-coordinates.net
items/astro.items:
Group Astro <sun_clouds> (W66a)
//
DateTime Current_DateTime "Today [%1$tA, %1$td.%1$tm.%1$tY]" <clock> (Astro) {channel="ntp:ntp:local:dateTime"}
//
DateTime Sunset_Time "Sunset [%1$tH:%1$tM]" <sun> (Astro) {channel="astro:sun:home:set#start"}
DateTime Sunrise_Time "Sunrise [%1$tH:%1$tM]" <sun> (Astro) {channel="astro:sun:home:rise#end"}
DateTime Evening_Time "Evening [%1$tH:%1$tM]" (Astro) {channel="astro:sun:minus90:set#start"}
//
String Day_Phase "Phase of Day [MAP(astro.map):%s]" (Astro) {channel="astro:sun:home:phase#name"}
Switch Night_State "Night" (Astro)
//
String Season_Name "Season [MAP(astro.map):%s]" (Astro) {channel="astro:sun:home:season#name"}
String Zodiac_Sign "Zodiac [MAP(astro.map):%s]" <zodiac> (Astro) {channel="astro:sun:home:zodiac#sign"}
Number Sun_Elevation "Sun Elevation [%.1f °]" <sun> (Astro) {channel="astro:sun:home:position#elevation"}
Number Moon_Elevation "Moon Elevation [%.1f °]" <moon> (Astro) {channel="astro:moon:home:position#elevation"}
String Moon_Phase "Moon Phase [MAP(astro.map):%s]" <moon> (Astro) {channel="astro:moon:home:phase#name"}
DateTime Moon_Next_Full "Next Full Moon [%1$td.%1$tm.%1$tY, %1$tH:%1$tM]" <moon> (Astro) {channel="astro:moon:home:phase#full"}
DateTime Moon_Next_New "Next New Moon [%1$td.%1$tm.%1$tY, %1$tH:%1$tM]" <moon> (Astro) {channel="astro:moon:home:phase#new"}
Night_State
:
The Item called Night_State
is a simple switch Item to indicate that the sun is down. The Item has to be set and that can happen via a rule, see: Sun (raised / set) indicator
Please be aware that a better solution should be possible using the “sun:phase” channel: http://docs.openhab.org/addons/bindings/astro/readme.html#channels - Please post a solution if you build one.
With the Items in place you can now build a sitemap, defining the structure of the user interface presentation. The following snippet can be inserted as part of an existing sitemap:
my.sitemap:
Text item=Current_DateTime label="Weather and Astro [%1$tA, %1$td.%1$tm.%1$tY]" icon="sun_clouds" {
Frame label="Now" {
//Switch item=Night_State label="Phase of Day" mappings=[OFF="Tag", ON="Nacht"]
Text item=Day_Phase icon="sunmoon"
Text item=Sunrise_Time icon="sunrise" visibility=[Night_State == ON]
Text item=Sunset_Time icon="sunset" visibility=[Night_State == OFF]
Text item=Sun_Elevation icon="sunmoon" visibility=[Sun_Elevation > 0]
Text item=Moon_Elevation icon="sunmoon" visibility=[Moon_Elevation > 0]
Text item=Zodiac_Sign icon="zodiac"
Text item=Moon_Phase
Text item=Moon_Next_Full icon="fullmoon"
visibility=[Moon_Phase == WAXING_CRESCENT,
Moon_Phase == FIRST_QUARTER,
Moon_Phase == WAXING_GIBBOUS,
Moon_Phase == FULL]
Text item=Moon_Next_New icon="fullmoon"
visibility=[Moon_Phase == WANING_GIBBOUS,
Moon_Phase == THIRD_QUARTER,
Moon_Phase == WANING_CRESCENT,
Moon_Phase == NEW]
}
Frame label="Forecast" {
Text label="This is part of other tutorials..." icon="sun_clouds"
}
}
Finally, a transformation file is needed to translate identifiers like “WANING_GIBBOUS” to human readable phrases.
astro.map:
Different translations:
- Spanish astro.map by @jammoyano
- Dutch astro.map by @Kees_van_Gelder
- Norwegian (Bokmal) astro.map by @Kees_van_Gelder
- German astro.map:
//
ARIES=♈ Widder
TAURUS=♉ Stier
GEMINI=♊ Zwilling
CANCER=♋ Krebs
LEO=♌ Löwe
VIRGO=♍ Jungfrau
LIBRA=♎ Waage
SCORPIO=♏ Skorpion
SAGITTARIUS=♐ Schütze
CAPRICORN=♑ Steinbock
AQUARIUS=♒ Wassermann
PISCES=♓ Fisch
//
SPRING=Frühling
SUMMER=Sommer
AUTUMN=Herbst
WINTER=Winter
//
SUN_RISE=Sonnenaufgang
ASTRO_DAWN=astronomische Morgendämmerung
NAUTIC_DAWN=nautische Morgendämmerung
CIVIL_DAWN=zivile Morgendämmerung
CIVIL_DUSK=zivile Abenddämmerung
NAUTIC_DUSK=nautische Abenddämmerung
ASTRO_DUSK=astronomische Abenddämmerung
SUN_SET=Sonnenuntergang
DAYLIGHT=Tag
NOON=Abend
NIGHT=Nacht
//
NEW=🌑 Neumond
WAXING_CRESCENT=🌑→🌓 zunehmender Halbmond
FIRST_QUARTER=🌓 erstes Viertel
WAXING_GIBBOUS=🌓→🌕 zunehmender Mond
FULL=🌕 Vollmond
WANING_GIBBOUS=🌕→🌗 abnehmender Mond
THIRD_QUARTER=🌗 letztes Viertel
WANING_CRESCENT=🌗→🌑 abnehmender Halbmond
//
NULL=unbekannt ⁉
-=unbekannt ⁉
Be aware, that the file contains Unicode symbols and needs to be saved in a UTF8 encoded text file. If your text file is in the wrong encoding, you will see question marks or other placeholders. Most text editors provide the appropriate option to change encoding.
That’s it. Enjoy!