Get weather forecast

Hi,

I’m quite new with Home Assistant. I want to get the daily rain forecast in a custom sensor. I want that this sensor update every hours.

Code is following, but I do not get any value. What is wrong?
I’m using the Open Meteo.

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: hourly
        target:
          entity_id: weather.ferme_mezieres
        response_variable: hourly
    sensor:
      name: CUST-SE-irrigation-dailyRainForecast
      unique_id: CUST-SE-irrigation-dailyRainForecast
      state: "{{ daily['weather.ferme_mezieres'].forecast[0].precipitation | tojson }}"
      unit_of_measurement: "mm"

I used as well :

state: "{{ daily['weather.ferme_mezieres'].forecast[0].precipitation | tojson }}"

But does not change. No value.

The name of your response variable is hourly, but you try to extract the value from a response named daily. you need to replace it by hourly.

I’m not that familiar with tojson but I am pretty sure it is not of any use here. The state of an entity is always a string. Precipitation is just a number, so not something that would be in need of converting to json. It doesn’t do anything to the final result.

Good catch. I change to daily (I want daily). Still the same. I as well remove the toJson.

Have you checked in the services panel that the weather forcast service actually supplies precipitation? For instance knmi does not, it only has precipitation_probability.

Also, change the trigger frequency to a minute for testing, otherwise you’ll have to wait very long to get the data :slight_smile:

Thanks, at the end it was working and my sensor was correctly populated. First I mismatch the variables names and was mainly the error. I’m still not 100% sure how to test it, as I have the feeling my sensor is not calculated after a restart, but only when triggers fires.

Marking your post as a solution when you mismatched the variable names and that was the main source of the error isn’t ideal.

OK corrected :slight_smile: Thanks for the tips.

1 Like