State_attr in config template card

I am trying to use an attribute of climate object in a dial gauge.

state_attr(‘climate.ir_remote_1_cool_study_1’,“temperature”)

Works fine in template tools tab (answer is 25) but fails miserably in the config template usage.

states[‘climate.ir_remote_1_cool_study_1’]?.attributes?.temperature

works fine. So why doesn’t state_attr work there?

ChatPT says unhelpfully:
" Your climate setpoint attribute isn’t called temperature —it’s temperature as a top-level field in the state object."

which leaves me none the wiser ..

Thanks

Which card(s) are you using? If they are custom cards, please provide a link to their repos… many custom cards and integrations have similar names, so it’s best to be specific.

Most cards do not support templating. You may need to create a Template sensor that extracts the attribute value, then use that sensor in your card.

Also, please follow Community Questions Guidelines by posting your properly-formatted, current card configuration so we can see what you are trying to do.

When you ask a bullshit engine a question, don’t be surprised when you get a bunch of bullshit.

This is the card that works. If I change the COOL_TARGET definition to use state_attr() format, it does not work, eg

state_attr(‘climate.ir_remote_1_cool_study_1’,“temperature”)

Though that produces the correct answer (25) in a template in the tools section.

type: custom:config-template-card
entities:
  - sensor.avg_study_1_temp
  - sensor.bedroom_temp_targets
  - climate.ir_remote_1_cool_study_1
variables:
  MIN_TEMP: 15
  MAX_TEMP: 30
  TARGET_TEMP: Number(states['sensor.bedroom_temp_targets'].state)
  COOL_TARGET: >-
    Number(states['climate.ir_remote_1_cool_study_1']?.attributes?.temperature)
    -0.3
  COOL_UPPER: >-
    Number(states['climate.ir_remote_1_cool_study_1']?.attributes?.temperature)
    +0.3
card:
  type: gauge
  name: Study 1
  entity: sensor.avg_study_1_temp
  unit: °C
  min: ${MIN_TEMP}
  needle: true
  max: ${MAX_TEMP}
  segments:
    - from: ${TARGET_TEMP}
      color: "#00ff00"
    - from: ${COOL_TARGET}
      color: "#ffff00"
    - from: ${COOL_UPPER}
      color: "#FE6c2c"
grid_options:
  columns: 6
  rows: 3

state_attr() is an HA template function… I don’t see anything in the card’s repo that say they support it. All of their attribute examples use the state object method pattern…

states['ENTITY_ID'].attributes.ATTRIBUTE_ID

… so that’s the way the developer of that custom card programmed it to work and that’s what you have to use in that card.

OK Thanks, guess I never found the card’s repo examples. This inconsistency between bits of HA continues to annoy me (and the ChatGPT explanation was purest mush).

You are using a custom card. Complain to the developer of that card. It has nothing to do with the home assistant developers. The custom card developer is free to make their own system as they see fit.

So stop wasting your time with it and read the documentation instead.