Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Customize unit settings per entity #308

Closed
ketilmo opened this issue Oct 9, 2022 · 19 comments
Closed

Feature Request: Customize unit settings per entity #308

ketilmo opened this issue Oct 9, 2022 · 19 comments
Assignees
Labels
enhancement Enhancement of the code, not introducing new features.

Comments

@ketilmo
Copy link

ketilmo commented Oct 9, 2022

Is your feature request related to a problem? Please describe.
Thanks for creating an amazing weather solution. It works great. An extension I would enjoy is being able to choose unit settings per entity, in the same way that the Ecowitt UI allows for.

Describe the solution you'd like
Be able to choose the unit types for

  • Temperature (°C, °F)
  • Pressure (hPa, inHgm, mmHg)
  • Wind (m/s, km/h, mph, knots)
  • Rain (mm, in)
  • Irradiance (Klux, W/㎡, Kfc)

Additional context
See screenshot from Ecowitt GW1100 settings page.
Settings

@bachya
Copy link
Owner

bachya commented Oct 9, 2022

To confirm: you're wanting to choose the units per entity category (temperature, etc.), not per each individual entity?

@ketilmo
Copy link
Author

ketilmo commented Oct 9, 2022

Hi @bachya,

Thanks for your quick reply. Yes, that's correct. Category would be sufficient.

@bachya
Copy link
Owner

bachya commented Oct 9, 2022

Got it; thanks!

@bachya bachya added the enhancement Enhancement of the code, not introducing new features. label Oct 9, 2022
@bachya bachya self-assigned this Oct 9, 2022
@bachya
Copy link
Owner

bachya commented Oct 10, 2022

Putting down some thoughts.

Underneath the hood, this isn't challenging. We can abstract unit conversion logic into a set of UnitConverter objects that take a "normalized unit" (e.g., perhaps we use "length in meters" for distance) and then store conversions to various other units.

The more challenging part is configuration – what is the least "breaking," most user-friendly way to implement this? More specifically:

  1. Can the existing configuration options – --input-unit-system and --output-unit-system – still provide value? Perhaps as a global conversion that can then be refined per unit category?
  2. How should the user provide unit configurations for an entity category? Something like --temperature-unit=c?

Will start working on the backend while I chew on this.

EDIT: Okay, I think I have a plan:

  • Implement a series of new conversion helpers for each entity category
  • Replace existing conversion code with these helpers in a 1:1 fashion (i.e., no functional changes to the user)
  • Investigate "scaled" conversion (i.e., scaling the precision when converting to a larger unit)
  • Implement user-facing configuration options

@bachya
Copy link
Owner

bachya commented Oct 16, 2022

@ketilmo Thanks for your patience! I've been hard at work and I'm now starting to implement the final user-facing portion of this: #338

In particular, take a look at what I'm proposing in the docs and see if it makes sense to you. Thanks!

@ketilmo
Copy link
Author

ketilmo commented Oct 16, 2022

Wow @bachya,

That was fast! Thanks a lot for your efforts, they are much appreciated. I checked the docs, and this looks like a great solution on how to handle the settings from a user perspective.

@bachya
Copy link
Owner

bachya commented Oct 16, 2022

Alright, with #346, this is completed for all unit categories. I have a few other PRs to add, but I will cut a release later today (and post back here when I do).

@bachya bachya closed this as completed Oct 16, 2022
@bachya
Copy link
Owner

bachya commented Oct 17, 2022

@ketilmo 2022.10.1 release with this functionality. Enjoy!

@ketilmo
Copy link
Author

ketilmo commented Oct 17, 2022

Awesome, @bachya! I can't wait to check it out! I'm running it as an add-on. Is there a way to change the settings through the UI?

@bachya
Copy link
Owner

bachya commented Oct 17, 2022

I haven't exposed any of this to the Home Assistant add-on because I didn't want to duplicate functionality that HASS already has:

CleanShot 2022-10-17 at 09 15 02

@bachya
Copy link
Owner

bachya commented Oct 17, 2022

After investigating a bit, perhaps that thinking is erroneous – HASS only appears to allow you to alter some units (like temperature), but not others. Has that been your experience, too, @ketilmo?

@ketilmo
Copy link
Author

ketilmo commented Oct 17, 2022

Nice! I wasn't aware of the possibility of changing the sensor type per entity. But you're right, it doesn't seem to work wind, rain and irradiance.

@bachya
Copy link
Owner

bachya commented Oct 17, 2022

Thanks for checking. I'll expose my options to the add-on and will report back.

@bachya bachya reopened this Oct 17, 2022
@ketilmo
Copy link
Author

ketilmo commented Oct 17, 2022

For clarity: Changing the type in the native UI works for temperature and pressure.

@bachya
Copy link
Owner

bachya commented Oct 17, 2022

Give me your thoughts: would it be worth exposing all of our options in the add-on, or only those options that HASS doesn't already cover (i.e., everything except temperature and pressure)?

The former is probably the easiest/clearest to do, but appreciate your opinion.

@ketilmo
Copy link
Author

ketilmo commented Oct 17, 2022

+1 for the second option. Hopefully, Home Assistant will eventually implement the UI unit setting for more types. So this might be a temporary workaround.

@ketilmo
Copy link
Author

ketilmo commented Oct 17, 2022

I have raised a feature request for this over at the Home Assistant forums: https://community.home-assistant.io/t/customisable-units-for-more-sensor-types/476474?u=ketil

@bachya
Copy link
Owner

bachya commented Oct 17, 2022

@ketilmo Okay, version 2022.10.1 of the add-in is building, and once it's complete (and you upgrade), you'll be able to configure units other than temperature and pressure:

CleanShot 2022-10-17 at 17 09 11

To configure these options in the add-on, you'll need to toggle "Show unused optional configuration options" first.

P.S., that strange UI – where a config option with two possible values shows radio buttons, and >2 shows a dropdown – Is in Home Assistant OS and not something I can change, unfortunately.

@bachya bachya closed this as completed Oct 17, 2022
@ketilmo
Copy link
Author

ketilmo commented Oct 18, 2022

This works like a charm, @bachya! Thanks for your efforts and making this happen! 👏🏻

@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Enhancement of the code, not introducing new features.
Projects
None yet
Development

No branches or pull requests

2 participants