kalkih / simple-weather-card

Minimalistic weather card for Home Assistant
MIT License
285 stars 33 forks source link

Can values with decimals be rounded? #17

Closed Yllelder closed 5 years ago

Yllelder commented 5 years ago

The Darksky component shows the temperature values with decimals, and I personally don't need so much precision. It would be more aesthetic if the values were integers.

Image of Yaktocat

Is there a template or a way to round the values with decimals?

Yllelder commented 5 years ago

I autorespond.

I didn't know you could create your own sensors from templates.

I have created 3 new sensors with templates that round off the values to integers. That's how it looks:

sensor:
  - platform: template
    sensors:
      rounded_temp:
        value_template: "{{ states('sensor.dark_sky_temperature') | round(0) }}"
        device_class: temperature
      max_rounded_temp:
        value_template: "{{ states('sensor.dark_sky_daytime_high_temperature_0d') | round(0) }}"
        device_class: temperature
      min_rounded_temp:
        value_template: "{{ states('sensor.dark_sky_overnight_low_temperature_0d') | round(0) }}"
        device_class: temperature

The sensors are now available as

and can now be used like any other sensor, providing the temperature already rounded.

I hope this can help someone ;)

kalkih commented 5 years ago

Nice solution @Yllelder , thanks for sharing!

juanbeniteza commented 1 year ago

@Yllelder Thanks, but maybe a noob question here. Where do you exactly put this code?

Yllelder commented 1 year ago

@Yllelder Thanks, but maybe a noob question here. Where do you exactly put this code?

You can use this code in the configuration.yaml file.

This will create 3 new sensors (sensor.rounded_temp, sensor.max_rounded_temp, sensor.min_rounded_temp) that you can use anywhere in the interface.