Concatenate String on Number in state jinja2 template

template:
  - sensor:
      - unique_id: living_room_temp
        name: "Living Room Temp"
        unit_of_measurement: "°F"
        state: >
          {{ (state_attr('climate.family_room', 'current_temperature') | string) ~ "°F" }}

If I don’t concatenate the string, it returns the number beautifully. As soon as I concatenate, I get unavailable as the state.

A template sensor with a unit_of_measurement must render to a number or none, a string is not allowed.

Why are you trying to add the unit into the sensor’s value? That’s very non-typical.

Agreed. I’m working with the cb-lcars-label-card and it only works with states, not attributes. Since the current_temperature is an attribute of my climate sensor I have to move it to be the state of a template sensor so I can render it on my cb-lcars-label-card.

type: custom:cb-lcars-label-card
cblcars_card_type: cb-lcars-label
show_label: true
variables:
  card:
    height: 7vh
  label: Temperature&#58
  entity: sensor.template_living_room_temp
  text:
    label:
      justify: flex-start
      align_items: center
      align: left
    state:
      justify: flex-end
      align_items: center
      align: left
tap_action:
  action: none
double_tap_action:
  action: none
hold_action:
  action: none
show_state: true
show_name: false
units: F
show_units: false

I’d love to find a way to jinja template the content of the label-card but I’ve not found a way and I’m not sure it supports it.

If you want to include the °F in the state so that it shows on the card exactly how you want it to, then you’ll need to remove the unit_of_measurement from the template sensor definition.

Got it. That was the secret sauce!