Template Sensors for Multiple Entity Attributes

I’m having a difficult time creating individual sensors from multiple attribute values of a single entity. I’m successful with one attribute using this method in configuration.yaml:

template:
    sensor:
      - name: "Air Temp"
        unit_of_measurement: "F"
        state: "{{state_attr('sensor.temp_monitoring_device','airtemp')}}"

but any attempt at adding additional sensor names from the other entity attributes of sensor.temp_monitoring_device does not work, and breaks the one sensor that I was able to get working.

I’ve tried about everything including replicating the -name block, the template and sensor sections, etc. but nothing seems to work.

All examples I’ve found online only seem to address those entities having one attribute, but I’ve found no examples of how the template/sensor block of code should be constructed if there are more than one entity attribute. In fact, most of what I turn up appears to be an older platform/template/sensors syntax.

Are there any examples anyone could point me to?

Thanks!

It may be useful for you to post your code that is not working so that we can better understand what your trying to do.

In any case, are you trying to create multiple sensors (multiple entries) with the state of each sensor being an attribute of the underlying sensor? Or, are you trying to create a single sensor (entity) that uses attributes to pick out the attributes of the underlying sensor?

As I’m sure you know, the sensor you create can only have one state. It can have multiple attributes though.

template:
    sensor:
      - name: "Air Temp"
        unit_of_measurement: "F"
        state: "{{state_attr('sensor.temp_monitoring_device','airtemp')}}"
      - name: "Something Else"
        unit_of_measurement: "%"
        state: "{{state_attr('sensor.temp_monitoring_device','some_other_attribute')}}"

Multiple sensors from the attributes of a single sensor entity.

I’m pretty sure I tried this variation, but I think your code block example gives me the construct I was looking for.

Is there a better way to extract attribute values from an entity, or is the state_attr the best method? At the moment, I’m just trying to report the values directly on an entity card, but at some point would like to act on them in automations.

Thanks for the prompt reply!

If you did then it would have worked.

There is one other way but it is not recommended.

states.sensor.temp_monitoring_device.attributes.airtemp


https://www.home-assistant.io/docs/configuration/templating/#states

Actually, no. Repeating the “name” block seemed logical and was the first thing I tried. I finally hard-restarted the NUC, and things started working. Not sure what the issue was, but from all the attempts there were quite a few extraneous entities that the restart seemed to remove. May also have been a restful process that wasn’t updating. I don’t know, but it seems to be working now.

Thanks again for the prompt assist!