Understanding templates

Hey guys,

I feel a bit ashamed, since I tend to call myself a programmer (mainly C#, SQL and PHP stuff), but I’m having a hard time getting the result that I want.

I use the AccuWeather integration, but the right temperature is not an entity, but it’s a state of the intergration. The integration is called ‘weater.thuis’

If successfully extracted the right temperature using:

{{ state_attr("weather.thuis","temperature") }}

Now, what I want seems so simple: I want to use THAT value on my dashboard to show (and plot) the right temperature. But whatever I try, I can’t seem to understand how to do it.

Currently I have an sensor.yaml file with integration for HP_ILO and that works perfectly. Truthfully: copy pasted from someone else. I tried adding all kinds of code to be able to have a new entity (I guess?) so I could attach that to a card on my dashboard. This is the code I currently have:

sensor:
  - platform: template
    friendly_name: Temperature at Home
    unit_of_measurement: "°C"
    value_template: < {{ state_attr("weather.thuis","temperature") }}

But this does not seem to work.

What is the right code for this template? And how do I use it in my dashboard?

Thanks, guys! I’m sure if I understand this part, I’m really starting to understand the depths of Home Assistant!

Change this:

value_template: < {{ state_attr("weather.thuis","temperature") }}

To this:

value_template: "{{ state_attr('weather.thuis','temperature') }}"

Ideally you should use the new template format:

configuration.yaml

template:
  - sensor:
      - name: Temperature at Home
        unit_of_measurement: "°C"
        device_class: temperature 
        state_class: measurement # only include this line if you want long term statistics 
        state: "{{ state_attr('weather.thuis','temperature') }}"

Do I put the template: part in templates.yaml? And how do I call this template in my dashboard/card?

You put it in

If you have an !include for templates, sure put it there instead.

Add the sensor entity_id (sensor.temperature_at_home) to an appropriate card (e.g. entities, history graph or gauge card).

This seems to work! Thank you!

I did remove the ‘template:’ line though, since I figured that was already in configuration.yaml. And apparently I was right.

And it made the “Temperature At Home” into an entity-id by putting _ as spaces. I didn’t know that, so that’s great too!

Thanks again, tom_l!

1 Like