Custom template to pull attribute

I am trying to grab the outside humidity from the weather.forecast_home entity but I cant get it to work. I just want to pull an attribute in to its own sensor and have been battling for a little while looking at various bits of code.

I can get it to grab the number as an attribute (as above) although I need it to be classed as a humidity sensor and show the number as the state so I can report on it in grafana

  - trigger:
      - platform: time_pattern
        minutes: /1
      - service: weather.get_forecasts
          type: hourly
          entity_id: weather.forecast_home
        response_variable: hourly
      - name: AA Humidity
        #state_class: measurement
        #unit_of_measurement: "%"
        #device_class: "humidity"
        #unique_id: weather_forecast_hourly

        state: "{{ now().isoformat() }}"
          humidity: "{{ state_attr('weather.forecast_home', 'humidity')}}"

This is what I have so far and of course commented out the bits that I think I need but they just don’t work either resulting in nothing being pulled or the sensor dissapearing.

many thanks

You are setting the state as the current datetime which cannot therefore be %. Your state should be your humidity value and then your commented out bits will work.

Also, you dont need the trigger as a template sensor will update if the senaor on which it is based updates.

As such, your template sensor should be…

  - sensor:
      - name: AA Humidity
        state_class: measurement
        unit_of_measurement: "%"
        device_class: "humidity"
        unique_id: weather_forecast_hourly
        state: state_attr('weather.forecast_home', 'humidity')}}"

Edit: if you do need to trigger the weather service to update its sensors, then add your trigger and action back

1 Like


        state: "{{ state_attr('weather.forecast_home', 'humidity') }}"
1 Like

Sorry, yes. Typing on my phone!

Thank you all for the help - seems to be working!