Astro Items+Sitemap+Map+♈ Binding Example

Tags: #<Tag:0x00007f7453058060> #<Tag:0x00007f745305ff40>

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 :wink:

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:

//
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!

22 Likes

Nice!

You should also add the rule for the Nightstate switch :slight_smile:

I’m actually waiting for https://github.com/openhab/openhab2-addons/pull/1767 :wink:

Oh yeah, it’s about time for that!

Hello, first of all I like to say a big thank you for all the people who put so much efforts into this outstanding project. I really appreciate all these activities and I’m glad, to participate of all of these smart home solutions.
I join openhab 2 a few days ago and try to learn each day a little bit more, so today I try to use the astro binding (I use openhabian on Raspberry Pi3).
My simple question is: Even today is the 3.2.2017 and we should have the zodiac “AQUARIUS” so the zodiac “TAURUS” is shown in my sitemap.
I’m sure, that the mistake is on my site - any help is kindly appreciated. Again, many many thanks for all the active Providers in this stuff!
Dirk

Hey @dikahab,

you are totally right. My Sitemap is showing AQUARIUS just fine:

Please check your date, geolocation and transformation. You didn’t give much info to work with.
Another thing you can do to track down the problem is look at the log files for updates and errors. As you said you are new to openHAB(ian), here is what you might want to do (Zodiac is the item name I’m using, which is by all means not a good choice btw :slight_smile:):

[15:23:18] pi@openHABianPi:~$ grep "Zodiac" /var/log/openhab2/*
/var/log/openhab2/events.log.2:2017-01-19 02:13:59.494 [temChannelLinkRemovedEvent] - Link 'Zodiac => astro:sun:home:zodiac#sign' has been removed.
/var/log/openhab2/events.log.2:2017-01-19 02:14:00.486 [ItemRemovedEvent          ] - Item 'Zodiac' has been removed.
/var/log/openhab2/events.log.2:2017-01-19 02:26:54.498 [ItemChannelLinkAddedEvent ] - Link 'Zodiac-astro:sun:home:zodiac#sign' has been added.
/var/log/openhab2/events.log.2:2017-01-19 02:29:51.522 [ItemStateChangedEvent     ] - Zodiac changed from NULL to CAPRICORN
/var/log/openhab2/events.log.2:2017-01-20 00:00:00.212 [ItemStateChangedEvent     ] - Zodiac changed from CAPRICORN to AQUARIUS

Side note: Looking at your sceenshot, I might want to upload my icons here…

well, I made a mistake as assumed: I tried { channel=“astro:moon:home:zodiac#sign” }, but obviously { channel=“astro:sun:home:zodiac#sign” } is the right syntax!
I know to less about the signs of zodiac (if based on ‘sun’ or ‘moon’…) Sorry for my inconvenience!

So, finally I’m happy and will go straigth forward with this marvelous project! I’m sure, it wasn’t the last time to request guidance. And I learned to provide code, etc. while asking for help - nobody knows the crystal ball :wink: Many thanks!

No problem! I didn’t even know there is a moon zodiac. Smarter every day. http://www.lunarium.co.uk/moonsign/calculator.jsp

Glad you got it fixed. Check out the rest of the first posting. you will find a few sitemap visibility decisions you might want.

Could you upload your map file somewhere? I tried copy&paste but the moon icons are missing from the sitemap :frowning:

@ThomDietrich
I am working in the Astro binding with this example from you. Unfortunately i get errors on the astro.map file.
I think it is because of the icons in the file.
I tried to copy and past the contents of the astro.map direct from the webpage, and i also tried it with an other editor (Sc228.exe). Then i see some Java code included. But the icons remain question marks.

<code class="lang-java hljs"><span class="hljs-comment">//</span>
ARIES=? Ram
TAURUS=? Stier
GEMINI=? Tweeling
CANCER=? Kreeft
LEO=? Leeuw
VIRGO=? Maagd
LIBRA=? Weegschaal
SCORPIO=? Schorpioen
SAGITTARIUS=? Boogschutter
CAPRICORN=? Steenbok
AQUARIUS=? Waterman
PISCES=? Vissen

<span class="hljs-comment">//</span>
SPRING=Voorjaat
SUMMER=Zomer
AUTUMN=Herfst
WINTER=Winter

<span class="hljs-comment">//</span>
NEW=?? Nieuwe maand
WAXING_CRESCENT=????? wassende Halve maan
FIRST_QUARTER=?? eerste Kwartier
WAXING_GIBBOUS=????? wassende maan
FULL=?? Volle maan
WANING_GIBBOUS=????? abnehmender Mond
THIRD_QUARTER=?? laatste Kwartier
WANING_CRESCENT=????? afnemende Halve maan

<span class="hljs-comment">//</span>
NULL=unbekannt ?</code>

Can you advice me how to get the astro.map file correctly?

Hey @deltabert and @hakan,
I did not expect this to be a problem. The icons are Unicode symbols. Hence your files need to be in UTF8 encoding. Yours are probably ANSI.

Download: astro.map

If you want to solve this problem yourself, you can use the excellent Notepad++ editor on Windows to check and change the encoding.

2 Likes

Actually, my files are UTF-8, I created them with Emacs on Linux.

What I have discovered in the meantime is, the icons are shown nicely on the Android App, on the 3House App and the Paper UI. It’s just the Basic UI which fails to show the icons.

I will investigate this further and maybe open an issue on github,

I didn’t get that. As you can see in the screen above it’s working just fine with Basic UI

Sorry, I was not fully clear on my message. The “AQUARIUS” icons are nice on my display too, but the “Mondphase” ones are broken. They show correctly on the Android App and Paper UI though. I have just verified with the “file” commando that all my files are correctly encoded as “UTF-8 Unicode text”.

If you look at your screenshots, you will notice that they show four <?> characters right next to “Mondphase” as well. Interestingly, your astro.map file displays them correctly.

Aaaah! That’s not a problem with the files. The font used by Basic UI just doesn’t support them :smiley: Only very few modern fonts seem to…

Btw. it says so in the first paragraph of my initial posting :see_no_evil:

Just an idea: We could work around that by providing a corresponding icon on the left rather than in the value text… https://www.google.de/search?q=moon+phases+icons Wdyt?

Now that you point me to it, it is obvious. Yet another case of seeing only what I was looking for, but not the full text you have written :blush:

Would be nice as an experiment. Could you also add a pointer to where you got the “Moon” and Zodiac icons from? I only have broken images for those on my sitemap :smile:

Why experiment? :slight_smile: We could just add dynamic icons to all Astro elements.
The problem is that I’m not sure where I got (or potentially stole) the icons from. So I’m a bit careful to post them publicly. But Hey, why don’t you check the URL of the map file I’ve posted above, maybe you’ll be lucky ;D

Aaaaah, nice :smile:

1 Like

So, which moon phases icons do we want to use?

So, how about the ones below? They seem to be free as in free-to-use, and do not look overly busy on mobile displays.

2 Likes