Weather Condition Icons for OpenWeatherMap Rule Problem

Hello!
I have a problrm with weather icon.
Topic: Animated Weather Condition Icons for OpenWeatherMap

I have only cloud icon.
When weather change from cloud to rain icon is cloud always.
There is a rule:

rule "OpenHAB system started - astro"
when
    System started
then
    createTimer(now.plusSeconds(180)) [ |
        if (now.isAfter((Sunset_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli) ||
            now.isBefore((Sunrise_Time.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli)
        ) {
            postUpdate(owmNightState, ON)
        } else {
            postUpdate(owmNightState, OFF)
        }
    ]
end

rule "Update NightState"
when
    Item Elevation changed
then
    // UoM <value>|<unit> (e.g. 20|°C)
    if(Elevation.state >  0|°){
        if(owmNightState.state != OFF) {
            postUpdate(owmNightState, OFF)
            // if owmNightState was ON we need to update owmCurrentConditionFormated too
            owmCurrentConditionFormated.postUpdate(transform("MAP", "openweathermap_day.map", owmCurrentConditionId.state.toString()))
        }
    } else {
        if(owmNightState.state != ON) {
            postUpdate(owmNightState, ON)
            owmCurrentConditionFormated.postUpdate(transform("MAP", "openweathermap_night.map", owmCurrentConditionId.state.toString()))
        }
    }
end

rule "Update conditions for HABPanel icon selection"
when
    Item owmCurrentConditionId changed
then
    if (owmNightState.state == ON) {
        owmCurrentConditionFormated.postUpdate(transform("MAP", "openweathermap_night.map", owmCurrentConditionId.state.toString()))
    }
    else {
        owmCurrentConditionFormated.postUpdate(transform("MAP", "openweathermap_day.map", owmCurrentConditionId.state.toString()))
    }
end

I must do:
String owmCurrentConditionFormated “Icon [MAP(openweathermap_night.map):%s]” {channel=“openweathermap:weather-and-forecast:6388adcd:current#condition-id”}

then working only night.
If i delete [MAP… not working…
Rule is loaded but not working. I think…

I must setting some channel etc.
In tutorial is only:

String				    owmCurrentConditionFormated "[%s]"
Switch                  owmNightState               "Night State"

Help please.

The idea of the rule is to set the item owmCurrentConditionFormated to different values, depending on night status. You will need two files openweathermap_day.map and openweathermap_night.map
The first rule is to switch the night status. If elevation is greater than 0°, it’s day, if elevation is less than 0° it’s night.
Depending on the new status the item owmCurrentConditionFormated shall give different information.
Therefor, owmCurrentConditionFormated isn’t linked to a channel but is unbound, so only the rule will change its status.
The second rule is if only the ID is changing, but not the elevation.

I have to admit that I think the whole setting is not necessary at all :slight_smile:
As a first point, the second rule is not needed as elevation will change maybe every 5 Minutes. So maybe the ID changes, but that will be taken care of when next time elevation changes.

But even the first rule isn’t needed at all, as you can simply change the label in the sitemap:

Text item=owmCurrentConditionFormated label="[MAP(openweathermap_day.map):%s]" visibility=[Elevation >= 0|°]
Text item=owmCurrentConditionFormated label="[MAP(openweathermap_night.map):%s]" visibility=[Elevation < 0|°]

So when Elevation is greater than 0° the first line will be visible where the second line will be visible when elevation is less than 0°

1 Like