Convert Wind Direction (in degrees) to Compass Points

Finally got this working.

If I use a Profile transformation then it works. The Item is a string but the channel is a number:dimension.

I created a scale file but could have selected the transformation I created in the GUI.

image

If there’s a way to do this with Item State Metadata, it’s not obvious to me.

Awesome, So glad you got it working the way you wanted.

My Number:Angle Wind Direction item has definitely worked with a string state description. I also have switch items that I transform to be more meaningful (e.g. Connected and Offline for network devices).

so in step 4 where did you put the State Metadata if not in Pattern?

Absolutely, with the caveat that not all transformations require a separate config and only require an inline config.

But it would be nice if it was rude same as we see in the link with the transform profile.

It can work there but if you are happy with what you have now go with that.

I added metadata to the item, and chose State Description.

I can submit a request. Which repo should this go under?

Also, is this a bug?

It seems like that field didn’t get saved when the item was created.

EDIT: it seems like that “State Description Pattern” field shows up for number items with dimensions, but changing it when creating the item doesn’t appear to do anything. I would expect it to generate the required metadata.

For me at least any time I wanted a transform to show what I was changing the value to in the event logs and not just on display I have had to use the flat file approach. For me I have never been able to get the event log to reflect the replacement values to show up in the event log just using state description.
I recall reading many times in other posts and I think it was even mentioned in this post that using the state description will not alter what is written to the event log it only changes what is displayed.

So is that a difference in behavior of using the flat file versus mainUi config by design? I do not know but I can see it in event logs using the file method and not in the other approach.

No, what’s happening is that there are two similar-but-different ways to accomplish this task.

You’re using a profile to transform the channel data before sending it to the item. That’s why you have to have a string item to receive the string value. The log will show the transformed string value, because that’s what’s stored in the item.

Rich and I are using item metadata to transform the data after it has been sent to the item. This preserves the original data, so it doesn’t need to be a string item. As a result, the log shows the original data, and the transformed value is displayed in openHAB UIs. It’s purely cosmetic.

State Description is similar to how we used to format output in item labels in OH2:

Number openweather_WindDirection "Wind direction [SCALE(openweathermap.scale):%s]"

When metadata was introduced in OH3, it was no longer necessary to do this in the item label.

openhab-webuis

No, I don’t think so.

There was a PR to address that recently I think. It’s a bug.

Flat file or managed is irrelevant. If you want the transformed value to appear in events.log, you need to transform the value before the state gets to the Item. That means the transform needs to go on the Channel config, where available, or in transform profile on the Link.

Either can be done in a managed config or in text files.

Correct, because events.log shows the actual state of the Item and State Description only changes how that state is displayed.

If you want to change the actual state of the Item, you need to transform the value before it gets to that Item at the Channel or the Link level.

Correct, but that’s all that OP was asking for.

There’s is no difference. It’s the same whether you are using files or managed configs.

Without seeing the config I can’t say what is going on. All I can say is the State Description will never alter the actual state of the Item. All I can guess (and it appears @rpwong agrees) is you’ve used the transform profile in your text configs instead of state description metadata.

Thanks @rlkoshak for the clarification. You are correct as @rpwong also pointed out. I create new items linked to the channel and use SCALE profiles to get the behavior I want. I do not use text config file any longer (not since pre 3.x1versions) actually. The only flat file I was referring to was to create the transform :“some-name.scale” file and place in config/transform folder that is outlined in all the documentation for the transform add on, as well as in the main doc’s that discuss use of this feature. Same as where I linked in my first reply to the OP.
All the rest of the discussion I agree with and I do appreciate you taking the time to clarify again why the event.log did not reflect the change as OP was asking and why the way I was offering as a path to accomplish the task would in fact reflect in the event logs.

Oops, I meant to ask if the State Description not working was a bug. Sorry, that wasn’t clear.

That is a big but it’s been worked I think.

1 Like