Picture element card - number rounding

I’m using a picture element card to present sensors. I know how to round a sensor entity.

One of my sensor items is fan speed which is a percentage.
Code

  • type: state=label
    Entity: number.hb_2_fan_speed

The item number.hb_2_fan_speed is presented with 2 decimals and I’m looking for no decimals . So 43% vs 43,23%

try reduce a precision in UI settings for this entity

Not sure if I understand.
Under integration > entities I see the option ‘display precision’ for sensors. (sensor.hb_temp_inlet). This option is missing for a number entity (number.hb_2_fan_speed)
Which UI settings are you refering to?

Sorry, missed a fact that this is a number.

Did you create this “number” entity by yourself? Or it is created by some integration?
If by yourself - then did you set a “step” value fractional?
If it was created by some integration - you can create a template sensor for this “number” entity with a desired precision.

It was create by an integration.
Will check template sensor option.
Is integration helpers the best way forward?
Looking for some examples.


This should get you started.
It takes the value of a sensor (in this case a water sensor that also provides temperature values).
The sensor will give you a numeric value with a C at the end.
This template strips the C, turns the number into a float (now you could do some math with it if you wanted) and finally rounds it to one digit after the comma.
In order to be able to show it in HA as a graph, it also assigns a unit of measurement

Not making progress…
The entity is integrated via the MQTT server and is a number with 2 decimals.
I use the Helpers under settings.
State template

{number.heatbooster_hb_1_achter_fan_speed | float | round(0)}

Purpose is to return entity with 0 decimals.
Get an error: required key not provided @ data[‘set_value’]. Got None

Thanks, Guess this should be in configuration.yaml file?
Edit: added the code
Created the following code in configuration.yaml file

 - sensor:
    - name: heatbooster_hb_1_achter_fan_speed
        friendly_name: "hb 1 achter fan speed"
        value_template: "{{ (states('number.heatbooster_hb_1_achter_fan_speed') | float | round(0) ) }} "
        unit of measurement: "%"

Currently fan is at 0%, so no decimals. Will keep you posted

1 Like

Yes - sorry, forgot to mention the config.yaml — very old school – I know
:slight_smile:

You can of course also do it in the GUI

  • create helper
  • template sensor
    in the field “State Template” you just enter the same info as before:
    {{ (states(‘number.heatbooster_hb_1_achter_fan_speed’) | float | round(0) ) }}

I guess the advantage with the GUI is, that you get an immediate readout of the template sensor as preview on the bottom. That way it is easier to play around with the parameters .

Same may be easily achieved with Dev tools → Template when you test a template before saving it in yaml file.

1 Like

Frank’s code example is based on the legacy way of creating a template and I had already some sensors in the new format in my configuration file.
This is the code result (so far)

template:
  - sensor:
    - name: WP1-status
      [...]
  - sensor:
    - name: WP2-status
      [...]
# purpose template sensor is to present fanspeed with no decimals 
  - sensor:
    - name: hb-1a-fanspeed
      unique_id: 6298b6e5-1528-4089-99ac-b5eb4b7ceff3
      state: "{{ (states('number.heatbooster_hb_1_achter_fan_speed') | round(0, default=255) ) }}"
      unit_of_measurement: "%"
      icon: mdi:fan

Edit: although original script is working, you get a log error because default is missing
changed line: state: “{{ (states(‘number.heatbooster_hb_1_achter_fan_speed’) | round(0) }}”