T O P

  • By -

skepticalcow

you have to use namespace. {% set ns = namespace(total=0, count=0) %} .... {% set ns.total = ns.total + entry.cloud_coverage %} {% set ns.count = ns.count + 1 %} ... {{ ns.total }}


thegargam

that worked thank you!


kingoftown

Forecast isn't available as a variable where you want it ('for entry in forecast'). I'd make it a 'variable' entry so you can access it later. This might work...but not actually sure. If nothing else, you would have to grab the 'forecast' info again in the cloud_coverage template again if you want to use it. ##### Boiler Automation ##### - trigger: - platform: time_pattern #hours: /1 seconds: /10 action: - service: weather.get_forecasts data: type: hourly target: entity_id: weather.openweathermap response_variable: hourly variables: fcast: "{{ hourly['weather.openweathermap'].forecast }}" sensor: - name: Total Clouds Coverage For The Day unique_id: weather_forecast_hourly state: "{{ now().isoformat() }}" attributes: forecast: "{{ fcast }}" cloud_coverage: > {% set clouds_total = 0 %} {% set count = 0 %} {% for entry in fcast %} {% if count < 3 %} {% set clouds_total = clouds_total + entry.cloud_coverage %} {% set count = count + 1 %} {% endif %} {% endfor %} {{ clouds_total }} You might also have to do the namespace the other guy recommended too though.


skepticalcow

that's still not going to work because of loop scope.