openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.88k stars 3.59k forks source link

[transform.SCALE] scale profile only supports String types #4995

Closed ccutrer closed 5 years ago

ccutrer commented 5 years ago

I have a HomeSeer HS-FC200+ Fan Control that exposes the fan speed as a Dimmer item, with a "proper" 0-100%. But it actually only supports 3 or 4 speeds. When I have it set to 4 speeds, the device reports back the speed as 0%, 24%, 49%, 74%, or 100%. No idea why, but the off-by-one causes havoc when I try to build UIs and tell it to only support 4 steps in a slider (or shortly, when I add support for HomeKit for having a certain number of speeds for a fan). SCALE transformation seems perfect for this. Heck, I could be convinced to use MAP, but neither one support DecimalType or PercentType. My expected item configuration:

Dimmer GuestFan_Dimmer { channel="zwave..."[profile="transform:SCALE", function="fan.scale"]}

With fan.scale:

[0..0]=0
]..25[=25
[25..50[=50
[50..75[=75
[75..100]=100

Currently, it just silently ignores any update from the device with that config in place. I'm pretty sure I've got the config right, because if I change the name of the function, I actually get errors in the log that it was unable to transform.

It seems like https://github.com/openhab/openhab2-addons/blob/master/addons/transform/org.openhab.transform.scale/src/main/java/org/openhab/transform/scale/internal/profiles/ScaleTransformationProfile.java#L126 would be the easiest way to "cast" it to the appropriate type of the item, after the transformation, but I'm unsure if you can get at the actual Item type from that point in the code.

Your Environment

ccutrer commented 5 years ago

Oh duh, you have the incoming State from the binding at that point. You could probably infer the type it should be from that.

davidgraeff commented 5 years ago

Transformations and Profiles in OH 2 unfortunately work with Strings only, that is correct. It might be an idea to change that for OH 3 when we can break the APIs

Rossko57 commented 5 years ago

Post closure comment - an example of a desire to use SCALE to match incoming data to a Number type Item. https://community.openhab.org/t/scale-transformation-issues-openhabian-with-2-5-0-m1-1/75601

It would be a useful capability. But perhaps need some extra work - what if SCALE outputs non-numeric, from user file, should it force UNDEF perhaps?