Trying to convert my Wind Direction Item to display Compass Points (text) rather than Degrees (number.
Running 4.1.1 and configured entirely using MainGUI.
I searched and found many threads on this and I understand I should be using a Scale function but the thing that confusing is how to do this with Item State Description Metadata. All the examples I’ve found are showing Items with textual configuration.
What I need is a clear explanation. Do I put something in the Pattern, or in the Option, or both?
I tried putting the lines below in the Options but no luck.
[0.00…11.24]=N
[11.25…33.74]=NNE
[33.75…56.24]=NE
[56.25…78.74]=ENE
[78.75…101.24]=E
[101.25…123.74]=ESE
[123.75…146.24]=SE
[146.25…168.74]=SSE
[168.75…191.24]=S
[191.25…213.74]=SSW
[213.75…236.24]=SW
[236.25…258.74]=WSW
[258.75…281.24]=W
[281.25…303.74]=WNW
[303.75…326.24]=NW
[326.25…348.74]=NNW
[348.75…360.00]=N
NaN=Non-numeric state
Put what you see in all the examples into the “pattern” field of state description without the and :%s. For example if you see [SCALE(uvindex.scale):%s] you’d put in SCALE(uvindex.scale).
Those need to go into a separate file under $OH_CONF/transformations (uvindex.scale in the example above) or you can define it through the UI at Settings → Transformations. And of course you need to install the Scale add-on.
No, nothing you do through the UI ends up in the $OH_CONF folder. This got saved to $OH_USERDATA/jsondb/org.openhab.core.transform.Transformation.json.
I’ve personally never worked with the Scale transform so don’t know if there is a trick or syntax error or something that needs to be dealt with.
Do you see any errors in the logs?
I think I may have steered you wrong above too. You do need the “:%s” part.
Scale(config:scale:Wind_Direction):%s
We do our best but there are definitely many holes in the docs. Volunteers to help are always most welcome.
Failed transforming the state '49 °' on item 'WeatherStation_WindDirection' with pattern 'Scale(config:scale:Wind_direction):%s': Couldn't transform value because transformation service of type 'Scale' is not available.
The State Description only changes how the Item’s state is rendered in a MainUI Widget. It doesn’t change the actual state of the Item and it certainly doesn’t change the type of the Item.
On the Settings ->Items page, you will always see the Item’s actual state.
On the individual Item’s page you should see the state as it’s transformed by the State Description pattern, but that itself could be overridden by a the “default stand-alone widget” if there is one on that Item.
On the MainUI Overview pages you should see the transformed state as well. But again, this could be overridden by the the “default list item widget” on the Item.
On sitemaps I’m not sure if it uses the state description pattern or not. But you would put the same information into the “label” field of the sitemap element (this time with the [ ]).
In events.log and in rules you will only ever see the actual Item’s state.
I was wrong, still have a log error but it’s different.
Failed transforming the state '59 °' on item 'WeatherStation_WindDirection' with pattern 'SCALE(config:scale:Wind_direction):%s': Could not find configuration 'config:scale:Wind_direction' or failed to parse it.
For what it is worth.
Your example at begin of post did not have 2 valid periods separating the range.
If you create a flat file and give it a extension of .scale place it /conf/transform folder and you create a string item that is linked to the channel you are reading then you need nothing in state description or any where else all you need to do is on the item choose SCALE for profile and point to the flat file . you event logs will show your final transform and you will have a item that reflects the final transform everywhere you need it.
If you do all this through the MainUI then all the extra stuff you have been told are required.
Get rid of the unit by defining the Item as just a Number, not a Number:angle. In the UI that means setting the “Dimension” on the Item to nothing. The unit will be stripped from the value before the Item is updated.
If option 1 doesn’t work, please file an issue on openhab-addons to add support for UoM for the SCALE transform.
Having said all that, I’m not certain that’s the source of your error though. There might be something else wrong with the SCALE config.
Looking closely you have three dots between the numbers and the docs only show two:
[0.00…11.24]=N
compared to
]3..6]=2
I’m sure you note that the direction of the [ ] has meaning for the config as well.
Note, when posting configs, use code fences so the forum software doesn’t replace stuff to pretty it up, and spaces are preserved.
They say pictures speak louder then words.
here is a picture using flat file and mainUI transform and sourcing a temperature sender channels to transform using your values. for both temperature without stripping and UOM and humidity which is a number value.
Removing the dimension on the Item, it now shows in the log as an integer
Failed transforming the state '123' on item 'WeatherStation_WindDirection' with pattern 'SCALE(config:scale:Wind_direction):%s': Could not find configuration 'config:scale:Wind_direction' or failed to parse it.
And I edited my transformation using two dots separating integer values.
That is it all you need a string item linked to what ever channel you want if you create a flat file with a .scale extension. place it in the transform folder (it will show up in transformations in the mainUI as locked).
you have an item type of number letters are not a number. You need a item of type string. letters (text) are strings
To be clear everything @rlkoshak told you is correct, and it will work using MainUI approach just a lot more involved and even there you have to have a string item once you put the values in state description.
I just do flat files because it is easy and quick and gives me what i want in the event logs as well as on the GUI.
No you don’t. The State Description controls how the state of the Item is displayed but it doesn’t require any changes to the Item type.
All it does is control how the Item appears in the places I outlined above. It is perfectly acceptable to have transform like this that converts a number to a string for display purposes. State Description only controls the display.
If you want to use a String Item that’s doable. You’d just have to use a transform profile instead of the State Description to transform the value before it gets to the Item. But that’s not what OP is asking for.
Whether it’s managed configs or text files is irrelevant.
Ok, not questioning your expertise
So let me clarify it this way for me at least any time I wanted a item to display a string value I have had to use an item of the type string. for it to work correctly for me I am sure I must be doing it all wrong then.
fixed it
Added State Description metadata to the item: SCALE(config:scale:compass_direction):%s
That’s all it took. The steps are exactly the same in the UI as they are in text files–you just need to know how to point to the transformation patterns, Unfortunately, the UI method is missing from the docs.
Admittedly, it feels like the UI isn’t fully baked since we have to rely on textual config in the state description. It would be more intuitive if we could choose the type of transformation (e.g. scale, map) and then choose from the available transformations.
@rlkoshak, perhaps this would be a worthwhile feature request?