Format temperature reading on Lovelace card

The cleaning lady knocked over my RPi and in the process the microSD card broke and with that I lost my entire HA config.

I have a few temperature sensors that include degree symbol “f” with the temp reading and there was a way I had set up to get the reported format on the Lovelace card for those to match other sensors that just report the numeric value, but I can’t recall what I did. Any idea how I would make the temp reading in the card on the right look like the one on the left?

make a template sensor

I had this code but not sure it ever worked:

template:

  • sensor:
    • name: “Kitchen temperature”
      unit_of_measurement: “°F”
      state: >
      {% set kitchen = states(‘sensor.kitchen_temp_sensor’) | float %}

When I put this entity on a Lovelace card, it only gives me the attributes Friendly Name and Unit of Measurement and the card just shows degree symbol F.

You’d have to have that in configuration.yaml, and it would create a second sensor. Also, you’d have to parse out the units if your source sensor has the units. Post a screenshot of your current sensor in developer tools → states page.

I did put it in configuration.yaml, This is the actual temp sensor:

and this is the one created in configuration.yaml:

template:
- sensor:
  - name: Kitchen Temperature
    unique_id: kitchen_temperature
    device_class: temperature
    state_class: measurement
    unit_of_measurement: °F
    state: >
      {{ (state_attr('sensor.kitchen_temp_sensor', 'temperature') or '0') | regex_findall('([0-9.]+)') | map('float', 0) | first | default(0) }}
1 Like

Thanks and of course it works! Juts curious, is the findall needed to parse out the number from the symbol and f string?

Yep, that’s all it’s doing