How to get temperature from a template

I’m using IPMA component https://www.home-assistant.io/components/weather.ipma/ and it creates a card like this:


I would like to get the temperature and show it with other temperature data on history, here:

How can I achieve this?

Thank you :slight_smile:

3 Likes

You can use a template sensor that references the attribute of your weather component to achieve that. You’ll want to confirm the entity_id of your weather component and that the temperature attribute is named temperature.

Here’s an example of what I would need based on my weather component:

sensor:
  - platform: template
    sensors:
      weather_temperature:
        friendly_name: "Weather Temperature"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('weather.local_weather', 'temperature') }}"

image

6 Likes

I tried to follow your suggestion but I got a config error :s


image

image

It says “See dev-info panel for details.” What additional information about the error is reported there?

It would be helpful to know the details of the error because I created a similar template_sensor and it passed the configuration check.

      test_sensor:
        friendly_name: "Just a test"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('climate.thermostat', 'temperature') }}"

this is the error:

I’m at a loss to explain how that error message has anything to do with adding a simple template_sensor. :no_mouth:

If you remove the template_sensor from the configuration file and restart Home Assistant, does the same error message still appear?

“There are no new issues!” if I remove the template_sensor :s

Is weather_temperature the only template_sensor in your configuration or are there other ones in there already?

These are the sensors I have:

This how the template_sensor should be entered into your configuration file. It should be part of the existing sensor: section.

# Sensors
sensor:
  # Weather prediction
  - platform: yr
    name: Weather
    monitored conditions:
      - temperature
      - symbol
  - platform: template
    sensors:
      weather_temperature:
        friendly_name: "IPMA"
        unit_of_measurement: 'degrees'
        value_template: "{{ state_attr('weather.porto', 'temperature') }}"

# Text to speech
tts:
  platform: google
2 Likes

After following your suggestion this is the error I get:

Thank you for your patient

Just try changing the name to something else, like weather_temperature_2.

1 Like

It is working, thank you. I’ll read the documentation next weekend to understand the config.yaml structure.

You’re welcome! Have fun with Home Assistant.

One more question that I think is related. I would like that this sensor is shown alongside other temperature sensors however it has it’s own plot.

image

I change the settings to the following:
image

But it doesn’t make any change on history.

Not sure, but maybe the unit of measurement for already logged sensor data doesn’t change in the database. You could try changing the name of the sensor again so that Home Assistant sees it as a new sensor with the correct type and unit.

You marked “Change the name to something else” as the Solution to the original problem?

@Brett_C is the person who supplied the solution to create a template_sensor.

I helped you enter it correctly into your configuration file and @tjntomas helped you correct the name (because you already had a sensor with the same name). Basically, we pitched in to help you implement Brett’s solution.

For the benefit of other people who may encounter the same problem, please attribute the solution to Brett’s post.

As for the graph, once the recorder starts logging the entity, you’ll either have to purge the database (and lose all your existing data) or follow tjnthomas’s suggestion and rename the sensor, yet again, to force the recorder to log it with the new parameters. The old data, for sensor.weather_temperature2, will persist in the database (and appear in the graph) until it expires (typically in 7 days or whatever period of time you may have specified).

2 Likes

you’re right.

Is 7 days the default? How do I make my data there forever?

You can set the purge_interval in the recorder configuration to 0. If not, the recorder database is purged daily, keeping only the last 10 days. To keep the db size down, you can also list the the entities that you want to record. See here https://www.home-assistant.io/components/recorder/.

1 Like

The recorder is suited for storing short-term data. If you want to store data for many months (or more) it’s best to use another database, perhaps one like InfluxDB and Grafana to graph it.

1 Like