Setting the value of a helper from the weather temperature attribute

I’m looking to show the outdoor temperature as a helper on Home Assistant
I created a helper called outdoor temperature but I can’t work out how I pick up the temperature attribute from the hourly weather entity.
image

I also want this to trigger every hour to update. Can anyone help with this I’ve trawled the forum but I can’t find what I’m looking for and also not sure what I would use as an hourly trigger.

The code below was what I thought I needed to enter but yaml doesn’t like it :frowning:

image

try: {{ states[‘weather.home’].attributes.temperature }}

This is what I ended up with:

service: input_number.set_value
data:
value: {{ (states.weather.home_hourly.attributes.temperature) }}
target:
entity_id: input_number.outdoor_temperature

However every time I save it loses the line: value: {{ (states.weather.home_hourly.attributes.temperature) }}

I’ve checked the state using a template:

So I’m a bit lost now

Its got to do with the syntax :


or is the set_value command not capable of taking an entity value and setting a helper based on that?

For the love of god, all the documentation tells you NOT to access the attributes that way…

"{{ state_attr('weather.home','temperature')|float }}"

It’s state_attr(sensor,attribute) to access attributes. And you are setting a number, so make sure it is a float or an int you are passing as a value.

3 Likes

If you are wanting to set it to be used on Lovelace, you would probably be better off with an actual sensor though:

template:
  - trigger:
      - platform: homeassistant
        event: start
      - platform: time_pattern
        hours: "*"
        minutes: 0
        seconds: 0
    sensor:
      - name: Hourly Temperature
        unique_id: 9b5976b7-5401-41b6-9561-603f944ddcd6
        unit_of_measurement: 'C' # or F
        device_class: temperature
        state: "{{ state_attr('weather.home','temperature')|float }}"
        state_class: measurement

That will set an ACTUAL sensor to the temperature, every hour, and when Home Assistant is started.

1 Like

Thank you Andrew you’re a star for sharing all of this with me. I’m still very much a beginner am in the process of building a multisensor just waiting for parts to arrive due to christmas :slight_smile:

1 Like

Hi Mark, I´m still learning Template and Sensor coding and got this messsage while trying to past your code into my sensor.yaml which is mapped in the configuration.yaml:

While trying to check the configuration, I got this message:
Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 26).

Spent already an hour trying to fix this. Any hint?

You can’t paste it in sensor.yaml because it’s a template, you need to either paste it directly in to configuration.yaml, or you need to create template.yaml and map that in configuration.yaml like you have with sensor.yaml.