Hi,
I want to display my DSL sync values in Home Assistant (pulled from InfluxDB). They should be shown in mbps and be rounded to 2 decimals. The rounding should only be done for the UI, so I don’t lose the precision on the underlying sensor. The following code does this by creating an extra template sensor to be used by the UI:
sensor:
- platform: influxdb
ssl: false
api_version: 2
host: !secret influxdb_host
port: !secret influxdb_port
organization: !secret influxdb_organization
token: !secret influxdb_token_default_ro
bucket: default
queries_flux:
- group_function: last
name: "DSL Downstream (kbps)"
unique_id: dsl_downstream_kbps
unit_of_measurement: kbps
range_start: "-15m"
query: >
filter(fn: (r) => r["_measurement"] == "smart4_vdsl_status")
|> filter(fn: (r) => r["_field"] == "dsl_downstream")
template:
- sensor:
- name: "DSL Downstream"
unit_of_measurement: mbps
state: "{{ (states('sensor.dsl_downstream_kbps') | float / 1024) | round(2) }}"
This works just fine, but I’m wondering if there is a way to avoid having the extra template sensor. I read that suggested_display_precision
was recently introduced and I was hoping that I could do something like this in my InfluxDB sensor:
- group_function: last
name: "DSL Downstream"
unique_id: dsl_downstream
unit_of_measurement: mbps
value_template: "{{ value | float / 1024 }}"
suggested_display_precision: 2
range_start: "-15m"
query: >
filter(fn: (r) => r["_measurement"] == "smart4_vdsl_status")
|> filter(fn: (r) => r["_field"] == "dsl_downstream")
However, it looks like that this isn’t supported in the Influx integration (yet?).
So is the code I’m currently using still the best approach in 2023, or are there better alternatives (without using custom UI cards)?
Thanks,
Aaron