How to template entities?

Background

I run a speedtest test hourly by having in my configuration.yaml

  - platform: speedtest
    monitored_conditions:
      - ping
      - download
      - upload

I then use the information in a card on the frontend:

type: entities
entities:
  - entity: sensor.speedtest_download
  - entity: sensor.speedtest_upload
  - entity: sensor.speedtest_ping
graph: line
detail: 2

which gives me

image

Yes, I know that the latency is surprisingly large for a test on an edge server

Question

I would like to round the results and was hoping to use templates for that ({{ sensor.speedtest_download | round(0) }}).

I just do not know where to put the template. I tried

type: entities
entities:
  - entity: 
        data_template: {{ sensor.speedtest_download | round(0) }}
  - entity: sensor.speedtest_upload
  - entity: sensor.speedtest_ping
graph: line
detail: 2

and some other combinations but in reality I do not understand the mechanics of templating (where to use it when I have a non-templated version, like sensor.speedtest_download above and would like to manipulate it though a template)

1 Like

you need to create a template sensor first.

You cant do this…
Instead you have to create a template sensor and replace the original, with the template one:

sensor:
  - platform: template
    sensors:
      speedtestdownloadtemplate:
        friendly_name: 'Download Speed'
        unit_of_measurement: 'Mbit/s'
        value_template: '{{states.sensor.speedtest_download.state |round(0)}}'

And then replace your ui-lovelace using this:

type: entities
entities:
  - entity: sensor.speedtestdownloadtemplate // This is the new one
  - entity: sensor.speedtest_upload
  - entity: sensor.speedtest_ping
graph: line
detail: 2
1 Like

also graph:line and detail:2 are not a valid attributes for the entities card. Those attributes only work on the sensor card.