Round a sensor number on a card

I’m new to HA so please go easy. I’ve had a look at Rounding number in a card? and Templating - Home Assistant but am still scratching my head.

I’m using the Speedtest integration/sensor on my dashboard to display up/down speed as a gauge. I want to round the number to an integer.

Example, I want to round the numbers below to 912 and 812:

I’ve tried something like this, but it does not round the number.

- type: horizontal-stack
  cards:
    - type: gauge
      entity: sensor.speedtest_download
      min: 100
      max: 1000
      severity:
        green: 800
        yellow: 500
        red: 100
      name: ' '
      unit: ↓
    - type: gauge
      value_template: "{{ states('sensor.speedtest_upload') | round(0) }}"
      entity: sensor.speedtest_upload
      min: 100
      max: 1000
      severity:
        green: 800
        yellow: 500
        red: 100
      name: ' '
      unit: ↑

Home Assistant’s standard set of cards don’t support templates (the sole exception is the Markdown card). Some custom cards support templating.

You may have noticed that the documentation for the Gauge card doesn’t describe a value_template option nor does it show any examples employing a template.

Your options:

  1. Create two Template Sensors, one that rounds the value of sensor.speedtest_upload and the other for sensor.speedtest_download. Reference the Template Sensors in your Gauge cards.

  2. Find a custom card, like the Gauge card, that supports templating.

1 Like

Option 1 above is the only way to do this without any custom cards / other custom lovelace elements.

Apexcharts can ‘probably’ do something similar for Option 2.
GitHub - RomRider/apexcharts-card: :chart_with_upwards_trend: A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant

Another option is to use something like
GitHub - iantrich/config-template-card: :memo: Templatable Lovelace Configurations

or
GitHub - gadgetchnnel/lovelace-card-templater: Custom Lovelace card which allows Jinja2 templates to be applied to other cards

They will allow you to template pretty much anything.

Thanks for the tips guys, I will give this a try when I get home!