Rounding the data from my weather station

I have my Home Assistant receiving data from my weather station from mqtt. I had noticed that the temperature and wind speed readings are displayed in 4 or more decimal places. I have home assistant installed on a raspberry pi and I am new to home assistant. I have used the following script in template editor and it works there. Do I add this to the configuration.yaml file?

value_template: {{ states('sensor.cotech_367959_128_t') | float | round(2)}}

How is this sensor defined? Is it through MQTT discovery or have you defined the original sensor in configuration.yaml?

It is defined through MQTT. I have not defined it yet in configuration.yaml.

You could create a new template sensor and apply the template you have given, in configuration.yaml:

It would look something like:

template:
  - sensor:
      - name: "Rounded temperature"
        unit_of_measurement: "°C"
        state: >
          {{ states('sensor.cotech_367959_128_t') | float | round(2) }}

I had tried to add the above template and I now have a message stating:
“Integration error: Template - Integration ‘Template’ not found.”
Can this be added anywhere in the configuration.yaml file? I’m new to this, so I’m not sure where to put that in the file and if I somehow have to activate the update.

What version of HA are you running? The method of defining template sensors change recently (like in the last year or so). This is the old format - if it works maybe you need to upgrade.

sensor:
  platform: template
    sensors:
      rounded_temperature:
        friendly_name: "Rounded Temperature"
        unit_of_measurement: "°C"
        value_template: " {{ states('sensor.cotech_367959_128_t') | float | round(2) }}"

Also read through this: