Switch State Disappearing (OH2)

I’m trying to use sunset events in OH2 as described here by @ThomDietrich. However, it is not working as intended.


sitemap house label="House" {
        Frame label="States" {
                Text item=NightState label="Night" icon="moon"
        Frame label="Times" {
                Text item=SunElevation label="Sun Elevation" icon="sun"
                Text item=SunriseTime label="Sunrise" icon="sunrise"
                Text item=SunsetTime label="Sunset" icon="sunset"


Group Astro
DateTime SunsetTime "Sunset [%1$tH:%1$tM]" <sunset> (Astro) { channel="astro:sun:local:set#start" }
DateTime SunriseTime "Sunrise [%1$tH:%1$tM]" <sunries> (Astro) { channel="astro:sun:local:rise#end" }
Number   SunElevation  "Elevation [%.1f °]"  <sun>  (Astro) { channel="astro:sun:local:position#elevation" }
Switch   NightState "Night" <moon> (Astro)


rule "Update NightState"
    Item SunElevation changed
    if(SunElevation.state > 0){
//        if(NightState.state != OFF) postUpdate(NightState, OFF)
        postUpdate(NightState, OFF)
    } else {
//        if(NightState.state != ON) postUpdate(NightState, ON)
        postUpdate(NightState, ON)

rule "Night has started"
    Item NightState received update ON
    sendCommand(Light1, ON)

rule "Night has ended"
    Item NightState received update OFF
    sendCommand(Light1, OFF)

Obviously, I’m excluding some parts of my sitemap and items for this example. I’m using the UPB binding, and it’s working 100% fine. I’m also aware of #640, which I have been experiencing.

The issue is that NightState does not keep its state. If I am rapidly reloading the page, whenever the elevation changes but before BasicUI “reformats” or whatever, it will show ON or OFF, but after that it just goes blank. HABmin says that it is set to NULL or ON seemingly depending on what mood it’s in. However, HABmin never formats the times or elevation (is that related)? I can never see the state in ClassicUI. My events to turn on or off Light1 never seem to fire.

It seems that something is happening with the UIs format the state. I can see the state (sometimes) in HABmin, and it never touches the times or elevation formatting. However, ClassicUI and BasicUI seem like they’re looking for a format, and when they don’t find one, they just show it as blank.

What’s going on?

So I think that I figured out both issues.

The issue of displaying the state was solved by using the proper label: Text item=NightState label="Night [%s]" icon="moon"

I noticed that while my light is not coming on, OpenHAB sets the state of the light to be as if it had set it to go on. When OpenHAB starts, the UPB binding polls some of the switches to get their states. I think that the initial setting of the light gets lost in the mix of the other commands. I will try and set a delay.