openhab / openhab-google-assistant

openHAB Google Assistant: Actions on Google for openHAB
Eclipse Public License 2.0
176 stars 86 forks source link

Humidity metadata should automatically detect if humidity item's range 0-1 or 0-100 (or make it configurable) #579

Open Flowdalic opened 1 month ago

Flowdalic commented 1 month ago

Homematic thermostats in OpenHAB report the humidity in the range between 0 and 1 (I am sure this is true for other humidity sensors as well). To expose it via openhab-google-assistant, I need to create another item that maps the value between 0 and 1, to an integer between 0 and 100. Otherwise, Google Home constantly displays a humidity of 1%.

It would be great if I did not had to duplicate the item just for openhab-google-assistant, and if it would instead automatically determine if humidity is reported between 0 and 1 and map this value accordingly. If an automatism isn't feasible, then it should be at least made configurable.

michikrug commented 1 month ago

Hi, thanks for raising that. I would assume that this is a rather easy thing to implement, if we would just assume any number between 0-1 is not an actual percentage but needs conversion. Otherwise, we would allow edge case to create false representations. So a configuration option would be the safe solution to go for. Also that should be implemented rather easy. I will put it on the list. :)

michikrug commented 1 month ago

I guess this would solve your issue: https://github.com/openhab/openhab-google-assistant/pull/405/commits/d3031224dbc9df5281f1985679a16f8c65d3e5e4

Flowdalic commented 1 month ago

Thanks 👍

Does setting the option to 'float' automatically imply a range from 0 to 1? If so, the this should be clearly stated, because it could also mean that values like 41.76 are also supported. Maybe change the option name to "float (range 0-1)". Would we also need an option "float (range 0-100)"?

michikrug commented 1 month ago

Actually it does not matter what you write in there if it is just different from "percent" to trigger the transformation 🙄😅

What could be a proper value/name?

michikrug commented 1 month ago

I would like to keep the config as short as possible, but still meaningful. So float is short but not explicit enough.

In general, all numbers are supported but rounded as Google wants it like that. So also with percent a floating point would be fine.

michikrug commented 1 month ago

I just had another idea. Maybe just let the user define the maximum and calculate the rest.

E.g. humidityMaxValue:1 or default 100

It would be always assumed that the target value will be between 0 and 100 and calculated accordingly

Thoughts?

Flowdalic commented 1 month ago

Ultimately, I wonder if this needs a setting at all, or if it could be automatic instead. If the value has a dot, then it's a float. If the value is below 1 then it's range is between 0 and 1.

michikrug commented 4 weeks ago

Changed to configuration option to maxHumidity defaulting to 100

In your case you should set this to 1

It is already included in the latest v4 release, so you should be able to test this rightaway

Flowdalic commented 4 weeks ago

Changed to configuration option to maxHumidity defaulting to 100

Thanks for your work on openhab-google-assistant. If I understand correctly, then this setting would fix the issue I reported.

However, I am curious, why have this setting at all and not automatically scale values correctly? If the value is <= 1 then multiply it by 100 to get the value in the range between 1 and 100. It is usually beneficial towards UX if a setting can be avoided.

michikrug commented 4 weeks ago

Sure that would work, but what if there is actually a humidity of 1% reported. Then this logic would report 100%, which is not correct.

Flowdalic commented 4 weeks ago

While a relative humidity of 1% is possible, it is hardly common. Therefore, I doubt that this would be a real problem in practice. And the option to select the range could still be provided, if it is really needed. However, it would work for most users out of the box.

juju1337 commented 3 weeks ago

Is this already integrated in the stable release?

Homematic thermostats in OpenHAB report the humidity in the range between 0 and 1 (I am sure this is true for other humidity sensors as well). To expose it via openhab-google-assistant, I need to create another item that maps the value between 0 and 1, to an integer between 0 and 100. Otherwise, Google Home constantly displays a humidity of 1%.

It would be great if I did not had to duplicate the item just for openhab-google-assistant, and if it would instead automatically determine if humidity is reported between 0 and 1 and map this value accordingly. If an automatism isn't feasible, then it should be at least made configurable.

How does your current "solution" look like? I have the same issue with another humidity sensor, how did you configure the "mapping"-item?

michikrug commented 3 weeks ago

Is this already integrated in the stable release?

Yes, was rolled out with the v4 release last Friday

juju1337 commented 3 weeks ago

Where should the percent/float config be available? In the item config? Or GA Metadata? If yes, only for Thermostat or also for Humidity Sensor? I can't see it (yet?), after updating my installation to 4.1.3 (in docker).

michikrug commented 3 weeks ago

It's available for all devices with a humidity value.

As for any config related the the GA integration this goes into metadata.

The integration is not at all part of the openHAB software itself. So updating it will not influence anything related to this integration. It's completely standalone.

For the new configuration options you need to enter the metadata manually using the code tab.

There has not been an update made for the UI configuration part.

juju1337 commented 3 weeks ago

Ok, so I have an item linked to a channel of my humidity sensor, showing me a value from 0...1 in OpenHAB UI. I now add GA metadata to this item (e.g. GA Humidity Sensor). How does the (initially empty) config{} section have to look like to map it to 0..100% for GA?

michikrug commented 3 weeks ago
config:
 maxHumidity: 1
juju1337 commented 3 weeks ago

Works like a charm, thx!