How to change . (dot) for a , (comma) in a template sensor

Hi All,

I currently use the home assistant integrated weather forecast. (hint look at the seperator for thousands and decimals).

I want to log the outside temperature to compare it to the power consumed by my heat pump and the internal home temperature. Therefore I created a template sensor with below code:

template:
  - sensor:
      - name: Outdoor temperature
        state: "{{ state_attr('weather.forecast_home','temperature') }}"
        unit_of_measurement: '°C'
        state_class: measurement
        device_class: temperature

This code is working but the output is dot separated xx.x °C instead of comma separated xx,x °C and therefore not showing up as numerical in graphs.

When checking developer tools i see the same . versus ,

How can I solve this?

Please see this post. Specifically number 11. People might want to grab your code and test it in their system. They can’t easily do that from a picture.

How to help us help you - or How to ask a good question - Configuration - Home Assistant Community (home-assistant.io)

1 Like

Thanks! I think i was able to show the code as a syntax.

Decimal dots are correct for numerical states.

Your problem is a missing underscore in unit_of_measurement:. The system is ignoring that line, and without a unit of measurement defined, it is assuming non-numeric states.

Hi Troon,

Thanks for your answer I updated the code in the sensor template but it still does not show up as a numerical value.

I tried to do it different by removing the unit, state and device and used the native template sensor for that. See below screenshot

and then i get below error message

Sensor None has device class ‘temperature’, state class ‘measurement’ unit ‘°C’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘template: - sensor: - name: Outdoor temperature state: “-1.0”’ (<class ‘str’>)

I see what’s going on now. You’re mixing up YAML and UI configuration. The State template box should just contain:

{{ state_attr('weather.forecast_home','temperature') }}

All the other lines are for when you are editing the YAML configuration manually, not using the UI. They were ending up in the state of your sensor, which you can see in your very first screenshot.

Thank you! this solved it!

1 Like