Weather template no longer works what do i need to change

hi i been having issues with my enviromental canada weather template… i had little screens that display raining or sun icon picture and high and low … so i decided to delete it and re add it… and i cant seem to get it to populate… the forecast field has a bunch of readings… but i cant get the templates to work… i tried looking at the home assistant page for weather template… not sure how to do do it for what i got… i got this setup from another link off google… someone else did but some reason its not longer working… its been flaky for a long time it sometimes works sometimes doesnt… so reason i decided to delete the intergration and see if it would re fix itself but it didnt…

here is what i got the file is weather.yaml located in the packages folder

sensor:
  - platform: template
    sensors:
      today_min:
        value_template: "{{ state_attr('weather.peterborough', 'forecast')[0].templow }}"
        friendly_name: Today's maximal temperature
      today_max:
        value_template: "{{ state_attr('weather.peterborough', 'forecast')[0].temperature }}"
        friendly_name: Today's minimal temperature
      today_rain:
        value_template: "{{ state_attr('weather.peterborough', 'forecast')[0].precipitation_probability }}"
        friendly_name: Today's rain forecast
      today_icon:
        value_template: >-
          {% if state_attr("weather.peterborough","forecast")[0].condition =='clear-night' %}
            3
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='cloudy' %}
            5
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='fog' %}
            16
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='hail' %}
            6
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='lightning' %}
            13
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='lightning-rainy' %}
            17
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='partlycloudy' %}
            8
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='pouring' %}
            18
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='rainy' %}
            9
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='snowy' %}
            11
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='snowy-rainy' %}
            7
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='windy' %}
            14
          {% elif state_attr("weather.peterborough","forecast")[0].condition =='windy-variant' %}
            14
          {% else %}
            12
          {% endif %}
        friendly_name: Today weather forecast```

What do the Template Sensors report? Are their values unknown?

right now they reporting unavailiable

i have a weather.yaml file in the packages… from the example i used a long time ago went in there

now if i put it in the configuration.yaml under weather: it gives several errors

and the values should show temperature low and high… the weather if its rainy so then the icon i have will be a rainy icon on my display and the today rain is for snow or rain for how much its going to rain or snow

i made this from a couple years ago im sure code has changed so maybe doesnt work right

The only thing that has changed is that the format used by your Template Sensors is now known as “legacy” format. There’s a new “modern” format but the legacy format wasn’t deprecated and continues to work properly.

Copy-paste the following into the Template Editor and see what it reports.

{{ states('weather.peterborough') }}
{{ state_attr('weather.peterborough', 'forecast')[0] }}

the error i get is end ofthe stream or a document seperator is expected

That’s not where I explained to paste the templates.

The Template Editor is in Developer Tools > Template.

oh ok didnt know what you ment figured edit the template i didnt know about template editor

so the error i get is
undefinederror: none has no element 0

and if its possible can i convert this old way to the new way? that way i not needing to change the esphome devices… they still use the today_min:today_max etc

It implies you either don’t have a weather.peterborough entity or its forecast attribute has no value.

Go to Developer Tools > States and find weather.peterborough. Let me know if it exists and, if it does, what is the value shown in its forecast attribute.

If it doesn’t exist, there’s your problem (check the Environment Canada integration).

As predicted, weather.peterborough doesn’t exist. What you have is weather.peterborough_forecast.

To fix your Template Sensors, replace all references to weather.peterborough with weather.peterborough_forecast.


EDIT

The alternative is to rename the entity_id weather.peterborough_forecast to weather.peterborough. However make sure that renaming it doesn’t break some other Template Sensor, automation, or script.

ah ok… i dont know how to rename the forecast… i dont think i have any automations

but i did rename the template to add _forecast… probably why it wasnt working right anymore i not 100% sure… i got some warnings going to reboot the server

i know i used to get float errors that arent showing up in the logs maybe cuz things have changed… but gonna reboot and check as it would work then stop working it got annoying lot of times in the day everything unavaliable… will do a few reboots and entire network see for less log issues and to see if it all works

What kind of warnings?

First occurred: 6:42:38 PM (2 occurrences)
Last logged: 6:42:43 PM

NRCan base map could not be retreived
Mapbox base map could not be retreived```
```Logger: homeassistant.bootstrap
Source: bootstrap.py:494
First occurred: 6:42:47 PM (2 occurrences)
Last logged: 6:43:47 PM

Waiting on integrations to complete setup: environment_canada```

i not getting the float errors anymore  i used to get.. but now i getting float errors on my outside temperatures i dunno..  i didnt have these before maybe last couple HA updates  did something

Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:329
First occurred: 6:44:11 PM (4 occurrences)
Last logged: 6:44:11 PM

TemplateError(‘ValueError: Template error: float got invalid input ‘unavailable’ when rendering template ‘{{ (states(‘sensor.outside_barometric_pressure’) | float * 0.029529980164712) | round(2) }}’ but no default was specified’) while processing template ‘Template("{{ (states(‘sensor.outside_barometric_pressure’) | float * 0.029529980164712) | round(2) }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.barometric_pressure’
TemplateError(‘ValueError: Template error: float got invalid input ‘unavailable’ when rendering template ‘{{ states(‘sensor.bedroom_temperature_xiaomi’) | float }}’ but no default was specified’) while processing template ‘Template("{{ states(‘sensor.bedroom_temperature_xiaomi’) | float }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.b_bedroom_temperature_display’
TemplateError(‘ValueError: Template error: float got invalid input ‘unavailable’ when rendering template ‘{{ states(‘sensor.hallway_temperature_xiaomi’) | float }}’ but no default was specified’) while processing template ‘Template("{{ states(‘sensor.hallway_temperature_xiaomi’) | float }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.hallway_temperature_display’
TemplateError(‘ValueError: Template error: float got invalid input ‘unavailable’ when rendering template ‘{{ states(‘sensor.hallway_humidity_xiaomi’) | float }}’ but no default was specified’) while processing template ‘Template("{{ states(‘sensor.hallway_humidity_xiaomi’) | float }}")’ for attribute ‘_attr_native_value’ in entity ‘sensor.hallway_humidity_display’```

Source: components/sensor/__init__.py:677
Integration: Sensor (documentation, issues)
First occurred: 6:41:55 PM (4 occurrences)
Last logged: 6:44:12 PM

Entity sensor.smoke_detector_by_wood_stove_esp32 (<class 'homeassistant.components.esphome.sensor.EsphomeSensor'>) is using native unit of measurement '%' which is not a valid unit for the device class ('voltage') it is using; expected one of ['mV', 'V']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+esphome%22
Entity sensor.smoke_detector_esp_basement_back_room (<class 'homeassistant.components.esphome.sensor.EsphomeSensor'>) is using native unit of measurement '%' which is not a valid unit for the device class ('voltage') it is using; expected one of ['mV', 'V']; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+esphome%22```


i got a bunch of warning and errors  i dunot how to copy and paste them all.   i guessing maybe last couple updates i havent been checking my logs after each update.. 
and msot of the times i dont even know what the warnings mean

For starters, replace float with float(0) everywhere it’s used in your templates.

1 Like

ok changed the one sets of floats what does the float do and the float0) what does the bracket 0 mean and do?

doing another reboot to see what logs have changed… i find i have to do a host reboot… if i do a just restart it doesnt seem to clean out the logs…

guess this is from the temperature? dont know where to find it

Source: components/sensor/recorder.py:382
Integration: Sensor (documentation, issues)
First occurred: 8:11:27 PM (1 occurrences)
Last logged: 8:11:27 PM

The unit of sensor.peterborough_aqhi (None) can not be converted to the unit of previously compiled statistics (AQI). Generation of long term statistics will be suppressed unless the unit changes back to AQI or a compatible unit. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this```

and then the esphome stuff..  lot less warnings at least

float(0) means if float is unable to convert the supplied value to a number, it will report the specified default value 0.

None of the changes I have recommended require rebooting the host machine. All it takes is to execute Developer Tools > YAML > Reload Template Entities.

If you have to reboot, something is very wrong. Were all of these errors known to you when you wrote your first post?

oh ok that be nice for the esphome stuff where i get errors for cant convert unknown to a number

oh i ment i do a host reboot… if i just do the check configuration and restart the system logs dont erase it still keeps it… so i never know whats cleaned up or not so i do a full reboot… so it wipes the system logs… as i have had no luck to restart to get it to clear the logs

So where are we at now? Are the Template Sensors reporting data from Environment Canada or are they still indicating unavailable?