openhab / openhab-google-assistant

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

Google Home app sometimes doesn't show light brightness #413

Closed cholawo closed 1 year ago

cholawo commented 1 year ago

@michikrug TL;DR I want to suggest that openhab-google-assistant should round brightness to an integer when sending to Google. Trait docs say brightness should be an integer.

I've noticed that my Google Home app often won't display the current percentage brightness of a light.

I've found the reason: brightness percentage in openhab isn't an integer but something like 33.46456692913385826771653543307087 This happens for me because I'm using the mqtt things and channels binding. I believe I've set that up as it was meant to be:

Type dimmer : dimmer "Dimmer"
    [
        min = 0,
        max = 254,
        step = 1,
        stateTopic = "zigbee2mqtt/livingroom_ceiling_lights",
        commandTopic = "zigbee2mqtt/livingroom_ceiling_lights/set/brightness",
        transformationPattern = "JSONPATH:$.brightness"
    ]

When it transforms from 0-254 to a percentage, that percentage is understandably not an integer. When I tested setting brightness to integer in openhab, Google Home App does then show the brightness. I appreciate that there are other ways I could transform the number in openhab, but I removed JS transformations when the new mqtt binding gave the ability to transform natively. Also I want to retain the real percentage in openhab as it's useful to be able to convert back to a precise 0-254 number sometimes.

cholawo commented 1 year ago

Another thing to add, I notice this also affects any items that are Group:Dimmer:AVG since those will very often not be integers. I can't think of any way to ensure that they get converted to an integer without openhab-google-assistant rounding their values.

michikrug commented 1 year ago

Thanks for reaching out.

Valid points. Was not aware of such a behavior of openHAB so far.

Will likely implement this soon.

michikrug commented 1 year ago

Should be resolved with #425

michikrug commented 1 year ago

@cholawo could you verify the fixed behavior?

cholawo commented 1 year ago

@michikrug yes I now have percentages shown for light groups in google home app, thanks so much for sorting it out!