Remove unit from json formatted value?

I have a z-wave device that has an attribute value which includes unit of measure embedded in the value. I use the following to extract the value into an entity:

sensor:
  - platform: template
    sensors:
       pool_solar_temp:
         friendly_name: "Solar Temperature" 
         value_template: '{{ states.sensor.zw_044_21_solar_temperature.attributes.temperature }}'
         unit_of_measurement: '°F'

I get a result of 109°f°F

I know I can just remove my °F and get 109°f, but I want to have all my temperatures in °F format.

I want to strip the “°f” from the value. How do I do that?

Well, since it looks like the attribute is a string, if the last two characters of the string are always °f, then:

value_template: >
  {{ state_attr('sensor.zw_044_21_solar_temperature', 'temperature')[:-2] }}
1 Like

Bingo! Thanks!

1 Like