- name: "CT1 Current Sensor 1"
state_topic: "Mains_Power/Status"
state_class: measurement
value_template: >
{% set x = value.split(',') %}
{{ ((x[1] | float(0)) -0.05) / 6.296 }}
unit_of_measurement: "A"
icon: mdi:current-ac
However, the value is being displayed as 0.00158831003811944 A, which is one or two decimal points more than I need. I want to keep the sensor with precision than I’m showing, as I am using the value for further calculations.
For device sensors, there is the precision drop down. However, for yaml defined sensors, I get: This entity (‘sensor.ct1_power_1’) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.
What config do I need to set the display precision? I’d prefer to avoid making a dummy sensor just for display purposes, as it starts to make the yaml unmaintainable.
What is a purpose of this ID - just to set a precision?
OK, this is one of the ways - but then you will get a user-yaml-defined sensor (i.e. not created by some integration added via UI) whose settings are partially defined via UI. If managing setup via UI is absolutely OK for you - then fine).
I myself do not recommend to use UI-controlled precision for entities created/managed by yaml.
I accept a tendency of “moving HA settings from to UI” only if similar yaml-settings are supported.
Currently many integrations are UI-controlled only, I had to accept it - but rest of other parts of HA are kept in yaml. This is MY choice.
The sensor is unaffected and will continue to measure with a precision of 10 attoamperes which the OP wanted to remain — your round() would reduce precision. The unique ID gives the UI a reference to allow it to customise its display in the front end. It’s a separation of data and presentation, but I do take your point.
Agreed, but imagine this special case:
– entities & integrations are set up in yaml (except UI-controlled-only integrations);
– all HA parts are stored as packages (“Tesla”, “garden”, “vacuum” etc);
– lovelace is managed in yaml;
– when a vacuum is moved to a country house - just move the whole package into another HA setup;
– when one more Tesla is added - just create a copy of the corr. package with needed changes;
– also you may just “remove” (temporarily ofc) some package if you do not use it.
All this is possible only when your setup is yaml-controlled. And this is why I keep all my helpers & automations in yaml too.
Thanks all.
The unique ID has enabled me to set the precision.
I need a different storage precision to the display precision, as I am using data entity for further calculations - e.g. sum(current * voltage) * unit rate, and a loss of precision will impact the answer (albeit only a few pence in this case).
I agree its not ideal having some config in the yaml and others in the UI, but setting the precision only in the yaml loses precision rather than simply masking it.
Then using rounding for frontend only is a good idea.
But in similar cases I usually ether change a precision locally (where it is possible - like multiple-entity-row or template-entity-row) or use a specially created template sensor with rounding (excluded from Recorder)…
I have a similar question. Gasoline prices are often shown with 3 decimal places, the last one always being a 9 anyway. I would like to cut off the 9 and do it without rounding. By default, Home Assistant seems to give only the option to use it rounded. How can I implement it differently?
I was also hoping to customize the sensor and then use a value_template, but that doesn’t seem to work.