Trigger based template sensor not working

I am at the end of my wits and I’m sure I’m making a super simple mistake somewhere… I’m trying to set up a trigger based template sensor to extract temperature forecast from a weather entity into its own sensor. I’ve followed the examples I could find but not matter what I do, I never see the sensor actually being created.

my config (in a separate templates.yaml file) looks like this:

- trigger:
    - platform: time_pattern
      hours: "/1"
  action:
    - service: weather.get_forecasts
      data:
        type: daily
      target:
        entity_id: weather.openweathermap
      response_variable: result
  sensor:
    - name: Temperature Forecast 
      unique_id: openweathermap_temperature_forecast
      state: "{{ result['weather.openweathermap'].forecast[0].temperature }}"
      unit_of_measurement: °C

- select:
...

In testing this, I’ve tried to create a script with that calls the service and then spits out the state template in a notification - worked exactly as expected. I even tried to completely remove the service call and just assign a static value to the sensor, then I tried using time instead of time_pattern… nothing ever produces a sensor. All my other template entities in the same file work as expected, there’s nothing I could find in logs that would help me in any way.

Am I missing something completely obvious?

HI @Plawa,
I do not see any obvious error so I tried your code and it simply worked – I just adapted the weather entity to my local entity_id weather.zuhause and set the trigger to minutes: "/1" so I do not have to wait for the next full hour for the sensor to update:

template:
  - trigger:
      - platform: time_pattern
        minutes: "/1"
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.zuhause
        response_variable: result
    sensor:
      - name: Temperature Forecast 
        unique_id: openweathermap_temperature_forecast
        state: "{{ result['weather.zuhause'].forecast[0].temperature }}"
        unit_of_measurement: °C

Is your weather entity_id correct?

Is your weather entity updating correctly? OWM recently deprecated API v2.5, so you need to subscribe and configure the integration to v3.0 mode.

In other news, the template snippet from this post restores the functionality of all the removed OWM forecast entities, including their device classes and their original default names, so they should be shown exactly like before:

So… you helped me, but not in a way that you wanted to help me :slight_smile: It was something stupid exactly as I expected…

I noticed that the entity name this setup created for you didn’t actually follow the unique_id defined in the sensor but rather the name which is why I couldn’t actually see the entity… it was always there, I just wasn’t looking in the right place. Now that I know this, it works exactly as expected.

Danke vielmals for the kick in the right direction :slight_smile:

1 Like