[OH3] Main UI Examples

You need the items like he posted earlier. iconID is included in oneCallApi…

Both the icon and the iconID are available also with the Account thing, Go to the channels page and tick Show advanced, it should discover the iconID for every forecasted time interval

Thank you @hmerk for your quick reply. I know that I have to use oneCallApi… but iconID is not included only Icon as image … this may have changed … or can it be configured somehow?

Thank you @Dest “show advanced” make the difference. Thank you for the solution!

Thanks @hmerk and @Dest for clarification, you were faster than me :slight_smile:

@BG56: I see your wind direction is showing in degree. I’m using a SCALE transformation to have cardinal values.

conf/transform/winDir.scale

[0..11.25] = N
]11.25..33.75] = NNO
]33.75..56.25] = NO
]56.25..78.75] = ONO
]78.75..101.25] = O
]101.25..123.75] = OSO
]123.75..146.25] = SO
]146.25..168.75] = SSO
]168.75..191.25] = S
]191.25..213.75] = SSW
]213.75..236.25] = SW
]236.25..258.75] = WSW
]258.75..281.25] = W
]281.25..303.75] = WNW
]303.75..326.25] = NW
]326.25..348.75] = NNW
]348.75..360] = N
[..] = na
NaN="N/A"

PS: your weather forecast looks somewhat as bad as mine :frowning:

2 Likes

Thank you @Integer (Mike) for your hint. I have tried the SCALE setting in Main UI before but it didn’t work and I thought it is a general problem as described at OH 3 Scale profile exception while formatting value - #8 by icompas
You use the item for current wind direction from your weather station. Your item has item-type “String”. For the current wind direction I use the item which was created from the OneCallAPI. This item has item-type “Number:Angle”.
Inspired by your reply I changed the item-type of this item from “Number:Angle” to “String” and now the SCALE transformation works. There are so many little things to learn … which you can’t find in the documentation but only in the forum. Thank you for your help!

1 Like

I like your UI. How did you started? Got 0 experience about this. Do you know a good tutorial for this?

It’s the first time I see the profiles in use. I use these transformations on my items with metadata. Is there a reason/requirement/benefit to apply this on a channel?

see here

and profiles are more powerful. Me personally I use hysteresis profile to create events on channel level:
if temperature > 80 then a 2nd linked item of type switch is set to ON. without any rules.

@wars good question, and thanks to @Oliver2 for explanation. To be honest I thought, that for me it is not important to have the wind direction value as a number, so I made a transformation on Channel/Item level.

@Oliver2: The Hysteresis profile sounds interesting (for example for battery critical switches if only battery level is supported from the device). In the documentation the hysteresis is explained by textual configuration, but unfortunately I can’t find it in the UI?


I’m running 3.1.0.M3. Any idea, why it is not shown?

Thanks!

Can’t say if it is a bug, but if you go to thing’s channel tab and click on “+ Add Link to Item” you see the hysterese profile if the channel is a number channel.
Try to unlink and re-link the item. then hysterese should appear.
if you map hysterese profile to a switch item, make sure to add a state description to the item:

  • set the item to read only
  • add “%s” to pattern

otherwise you see “Err” as switch state

Could you please elaborate how you got this done?

Is this in the location tab or on the overview tab and have you created a page for it? Maybe a YAML if you don’t mind :grimacing:

Thanks in advance!

Correct me if I am wrong, but that looks like the normal Location card.
You achieve this by using the semantic model assigning Equipment and Properties.

I defined my semantic model but I just don’t get the (eg.) number of light in the top part and have no “tabs”.

Ah well, if I build the overview good enough, there is no need :wink:

Edit: Found some more options just now :smiley: :crazy_face:

You mean the i.e. lightbulb icon etc.? Those are called badges.
The tabs, again, are defined by your defined Equipment (Group of points => Equipment tab) and Properties (single points => Properties tab), there is quite extensive documentation here in the forum that shows how to do it.

I decided to write a Jython (Python 2) rule to update a String item with the wind direction name derived from the actual wind direction Number:angle Item (in my case, returned from OpenWeatherMap):

File location: $OPENHAB_CONF/automation/jsr223/python/personal/
File name: update_wind_direction_name.py

from core.rules import rule
from core.triggers import when

from core.actions import LogAction

from core.actions import Voice
from core.actions import Audio

import pprint

pp = pprint.PrettyPrinter(indent=4)

from java.time import ZonedDateTime
from java.time.format import DateTimeFormatter

from math import floor

rule_init_timestamp = ZonedDateTime.now()
logTitle = "update_wind_direction_name.py@{ts}".format(
    ts=rule_init_timestamp.format(DateTimeFormatter.ISO_INSTANT),
)
ruleTimeStamp = " -- (Rule set initialised at {ts})".format(
    ts=rule_init_timestamp.format(DateTimeFormatter.ISO_INSTANT),
)
rulePrefix = "Update wind direction name | "


class defaults:
    wind_direction_ANGLE_ITEM_NAME="OneCallAPIweatherandforecast_Current_Winddirection"
    wind_direction_name_item_NAME="Weather_Current_Wind_Direction_Name"
    wind_names_32 = [
        "N", "NbE", "NNE", "NEbN", "NE", "NEbE", "ENE", "EbN",
        "E", "EbS", "ESE", "SEbE", "SE", "SEbS", "SSE", "SbE",
        "S", "SbW", "SSW", "SWbS", "SW", "SWbW", "WSW", "WbS",
        "W", "WbN", "WNW", "NWbW", "NW", "NWbN", "NNW", "NbW",
    ]

@rule("Wind direction changed")
@when("Item {WIND_ANGLE_ITEM} changed".format(
    WIND_ANGLE_ITEM=defaults.wind_direction_ANGLE_ITEM_NAME
))
def Rule_WindDirectionChanged(event):
    # Note: rule can be triggered by hand
    update_wind_direction_name()


# Update the wind direction name item (usually when the wind direction angle item changes):
def update_wind_direction_name():
    global logTitle
    logPrefix = "update_wind_direction_name(): "

    LogAction.logInfo(logTitle, logPrefix + "At the start of rule")

    wind_direction_angle_item = itemRegistry.getItem(
        defaults.wind_direction_ANGLE_ITEM_NAME
    )
    wind_direction_name_item = itemRegistry.getItem(
        defaults.wind_direction_name_item_NAME
    )

    if not wind_direction_angle_item:
        LogAction.logError(
            logTitle, logPrefix + "Cannot find wind direction (angle) item '{item}' in item registry".format(
                name=defaults.wind_direction_ANGLE_ITEM_NAME
            )
        )
        return

    if not wind_direction_name_item:
        LogAction.logError(
            logTitle, logPrefix + "Cannot find wind direction (name) item '{item}' in item registry".format(
                name=defaults.wind_direction_name_item_NAME
            )
        )
        return

    wind_direction_name_value = None

    wind_direction_angle = wind_direction_angle_item.state


    if isinstance(wind_direction_angle, QuantityType):
        """
        Convert wind direction in degrees (0°-360°) into a named wind direction by means of an index.
        Since we're producing a 32-point wind rose, 'pure' wind direction names are centred across arcs
        spanning 1/32th of a full circle. Or, having equal arcs of 1/64th of a full circle at each side
        as mapping intervals. In this logic:
        a. North is centred at step 0
        b. Scaled wind angles with values between steps -1 and +1 are mapped to north
        c. Since wind directions span 2 steps, we must count the intervals at odd nonzero step values

        Therefore the index can be computed as follows:
        1. Convert a wind direction angle value into 2 * 32 = 64 steps
        2. Round down this value to the closest integer
        3. Map this value to [0..64[ using modulo (north may yield values ≥64)
        4. Convert this value to a 32-step index (use Math.floor as wind name changes at threshold)
        5. Look up the wind direction name by means of this index in the wind direction name array
        """

        # Get the wind angle in degrees:
        wind_angle = wind_direction_angle.doubleValue()
        # Scale wind angle from 360° range to 64 step range:
        scaled_wind_angle = wind_angle / 360.0 * 2 * 32
        # North goes from -1 to +1 hence we add an offset so the index starts at 0, 2, 4...
        scaled_wind_angle += 1
        # Convert index to 32-step index (use floor - returns float in Python2) and reduce range to [0; 32[:
        wind_name_index = int(floor(scaled_wind_angle / 2)) % 32

        wind_direction_name_value = defaults.wind_names_32[wind_name_index]
        LogAction.logDebug(
            logTitle, logPrefix + "Mapped {angle} to index {index} and name '{name}'".format(
                angle=wind_angle,
                index=wind_name_index,
                name=wind_direction_name_value,
            )
        )

    events.postUpdate(
        wind_direction_name_item,
        wind_direction_name_value
    ) 

You can update the wind direction item name in the rule in the defaults class at the top of the file.

I created my own set of wind direction icons, see:

To make icons dynamic in Moain UI, you must edit the Item, pick default list item widget, tick the show advanced checkbox and tick the now visible Icon depends on state option.

Have fun!

Thanks for the hint! after re-linking the item hysterese appears!

Since I try to implement a few cards based on your code I figured give you something back :wink:

The Items list you posted for the ‘wetter’-card contains 2 times forcastDay3 in the channel config. Being both there in D3 and D4. The card that you posted above it is correct however so maybe it’s already fixed :upside_down_face:

For the same card, to convert icons strings to the actual icon names, I use a MAP-file and then use the meta state description to produce the names. If Openweathermap ever decides to add icon ‘states’ you only have to adjust the map file. It is based on post#8 in this topic and works well.

Further I can’t say anything else then you’ve done a great job in creating widgets that are highly flexible. Using the visible option was a great idea! This way, you can use one card for multiple rooms for example without the need that every room has the same equipment (ie. temperature, humidity etc)

Are you able to share the media center YAML? Thanks!

You have a fancy weather station, do you also have a fancy soil moisture measuring device?