caiosweet / Home-Assistant-custom-components-INGV

INGV - National Institute of Geophysics and Volcanology [Istituto Nazionale di Geofisica e Vulcanologia] Terremoti Italia.
http://www.ingv.it/it/
MIT License
23 stars 7 forks source link

Errors after HAOS 2023.10.1 #26

Closed mfabiani53 closed 1 year ago

mfabiani53 commented 1 year ago

I always get these errors when HA start, just after upgrading to HAOS 2023.10.1

2023-10-10 12:18:31.997 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=(#### TERREMOTI - ULTIME 24h  [<img src="https://www.hsit.it/images/favicon.png"/> Hai Sentito Il Terremoto](http://www.haisentitoilterremoto.it/)
<!-- Setting -->
  {%- set person = 'person.maurizio' -%}
  {%- set url = "https://shakemap.rm.ingv.it/shake/{}/download/{}.jpg" -%}
  {%- set entityid = 'binary_sensor.lastquake' -%}
  {%- set id = state_attr(entityid, 'event_id') -%}
  {%- set data_utc = state_attr(entityid, 'publication_date') -%}
  {%- set magnitudo = (state_attr(entityid, 'magnitude')|float) if not none else '0' -%}
  {%- set code = {0:'White', 1:'Green', 2:'Yellow', 3:'Orange', 4:'Red'} -%}
  {%- set color = code[state_attr('binary_sensor.lastquake', 'level')|int] -%}
  {%- set lat = state_attr(entityid, 'lat') -%}
  {%- set long = state_attr(entityid, 'long') -%}
<font>
**<font color="{{color}}">{{as_timestamp(data_utc)|timestamp_custom ('%H:%M:%S del %d/%m/%Y')}}</font>**<br><br> Un terremoto di magnitudo **<font color="{{color}}">{{magnitudo}}</font>**<br> è avvenuto nella zona: [{{state_attr(entityid, 'region')}}](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=12/{{lat}}/{{long}})<br> a <font color="{{color}}">**{{state_attr(entityid, 'distance')}}**</font> km da casa,<br> con coordinate geografiche (lat, long) {{lat}},{{long}}.<br> {{("Tu ti trovi a " ~ distance(lat, long, person)) ~ " km dall'epicentro." if is_state(person, 'not_home') else ''}} </font> {% if magnitudo >= 3 %}<br> [Shakemap]({{url.format(id,'intensity')}}) ~  [PGA]({{url.format(id,'pga')}}) ~ [PGV]({{url.format(id,'pgv')}}) ~ [TvMap]({{url.format(id,'tvmap')}}) ~ [TvMap2]({{url.format(id,'tvmap_bare')}}) ~  [HaiSentitoIlTerremoto](http://eventi.haisentitoilterremoto.it/{{id}}/{{id}}_mcs.jpg)
<!-- Scegli il tipo di immagine da visualizzare [intensity,pga,pgv,tvmap,tvmap_bare] -->
  <img src="{{url.format(id,'intensity')}}"/>
  <!-- <img src="{{url.format(id,'pga')}}"/> -->
{% endif %}
<!-- 
  Map Google
  [{{state_attr(entityid, 'region')}}](http://maps.google.com/maps?z=8&q=loc:{{lat}}+{{long}})
  Map Open Streat Map
  [{{state_attr(entityid, 'region')}}](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=8/{{lat}}/{{long}})
-->) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1925, in forgiving_float_filter
    return float(value)
           ^^^^^^^^^^^^
ValueError: could not convert string to float: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 568, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2196, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 8, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1928, in forgiving_float_filter
    raise_no_default("float", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1626, in raise_no_default
    raise ValueError(
ValueError: Template error: float got invalid input '' when rendering template '#### TERREMOTI - ULTIME 24h  [<img src="https://www.hsit.it/images/favicon.png"/> Hai Sentito Il Terremoto](http://www.haisentitoilterremoto.it/)
<!-- Setting -->
  {%- set person = 'person.maurizio' -%}
  {%- set url = "https://shakemap.rm.ingv.it/shake/{}/download/{}.jpg" -%}
  {%- set entityid = 'binary_sensor.lastquake' -%}
  {%- set id = state_attr(entityid, 'event_id') -%}
  {%- set data_utc = state_attr(entityid, 'publication_date') -%}
  {%- set magnitudo = (state_attr(entityid, 'magnitude')|float) if not none else '0' -%}
  {%- set code = {0:'White', 1:'Green', 2:'Yellow', 3:'Orange', 4:'Red'} -%}
  {%- set color = code[state_attr('binary_sensor.lastquake', 'level')|int] -%}
  {%- set lat = state_attr(entityid, 'lat') -%}
  {%- set long = state_attr(entityid, 'long') -%}
<font>
**<font color="{{color}}">{{as_timestamp(data_utc)|timestamp_custom ('%H:%M:%S del %d/%m/%Y')}}</font>**<br><br> Un terremoto di magnitudo **<font color="{{color}}">{{magnitudo}}</font>**<br> è avvenuto nella zona: [{{state_attr(entityid, 'region')}}](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=12/{{lat}}/{{long}})<br> a <font color="{{color}}">**{{state_attr(entityid, 'distance')}}**</font> km da casa,<br> con coordinate geografiche (lat, long) {{lat}},{{long}}.<br> {{("Tu ti trovi a " ~ distance(lat, long, person)) ~ " km dall'epicentro." if is_state(person, 'not_home') else ''}} </font> {% if magnitudo >= 3 %}<br> [Shakemap]({{url.format(id,'intensity')}}) ~  [PGA]({{url.format(id,'pga')}}) ~ [PGV]({{url.format(id,'pgv')}}) ~ [TvMap]({{url.format(id,'tvmap')}}) ~ [TvMap2]({{url.format(id,'tvmap_bare')}}) ~  [HaiSentitoIlTerremoto](http://eventi.haisentitoilterremoto.it/{{id}}/{{id}}_mcs.jpg)
<!-- Scegli il tipo di immagine da visualizzare [intensity,pga,pgv,tvmap,tvmap_bare] -->
  <img src="{{url.format(id,'intensity')}}"/>
  <!-- <img src="{{url.format(id,'pga')}}"/> -->
{% endif %}
<!-- 
  Map Google
  [{{state_attr(entityid, 'region')}}](http://maps.google.com/maps?z=8&q=loc:{{lat}}+{{long}})
  Map Open Streat Map
  [{{state_attr(entityid, 'region')}}](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=8/{{lat}}/{{long}})
-->' but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 694, in async_render_to_info
    render_info._result = self.async_render(
                          ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 570, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input '' when rendering template '#### TERREMOTI - ULTIME 24h  [<img src="https://www.hsit.it/images/favicon.png"/> Hai Sentito Il Terremoto](http://www.haisentitoilterremoto.it/)
<!-- Setting -->
  {%- set person = 'person.maurizio' -%}
  {%- set url = "https://shakemap.rm.ingv.it/shake/{}/download/{}.jpg" -%}
  {%- set entityid = 'binary_sensor.lastquake' -%}
  {%- set id = state_attr(entityid, 'event_id') -%}
  {%- set data_utc = state_attr(entityid, 'publication_date') -%}
  {%- set magnitudo = (state_attr(entityid, 'magnitude')|float) if not none else '0' -%}
  {%- set code = {0:'White', 1:'Green', 2:'Yellow', 3:'Orange', 4:'Red'} -%}
  {%- set color = code[state_attr('binary_sensor.lastquake', 'level')|int] -%}
  {%- set lat = state_attr(entityid, 'lat') -%}
  {%- set long = state_attr(entityid, 'long') -%}
<font>
**<font color="{{color}}">{{as_timestamp(data_utc)|timestamp_custom ('%H:%M:%S del %d/%m/%Y')}}</font>**<br><br> Un terremoto di magnitudo **<font color="{{color}}">{{magnitudo}}</font>**<br> è avvenuto nella zona: [{{state_attr(entityid, 'region')}}](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=12/{{lat}}/{{long}})<br> a <font color="{{color}}">**{{state_attr(entityid, 'distance')}}**</font> km da casa,<br> con coordinate geografiche (lat, long) {{lat}},{{long}}.<br> {{("Tu ti trovi a " ~ distance(lat, long, person)) ~ " km dall'epicentro." if is_state(person, 'not_home') else ''}} </font> {% if magnitudo >= 3 %}<br> [Shakemap]({{url.format(id,'intensity')}}) ~  [PGA]({{url.format(id,'pga')}}) ~ [PGV]({{url.format(id,'pgv')}}) ~ [TvMap]({{url.format(id,'tvmap')}}) ~ [TvMap2]({{url.format(id,'tvmap_bare')}}) ~  [HaiSentitoIlTerremoto](http://eventi.haisentitoilterremoto.it/{{id}}/{{id}}_mcs.jpg)
<!-- Scegli il tipo di immagine da visualizzare [intensity,pga,pgv,tvmap,tvmap_bare] -->
  <img src="{{url.format(id,'intensity')}}"/>
  <!-- <img src="{{url.format(id,'pga')}}"/> -->
{% endif %}
<!-- 
  Map Google
  [{{state_attr(entityid, 'region')}}](http://maps.google.com/maps?z=8&q=loc:{{lat}}+{{long}})
  Map Open Streat Map
  [{{state_attr(entityid, 'region')}}](https://www.openstreetmap.org/?mlat={{lat}}&mlon={{long}}#map=8/{{lat}}/{{long}})
-->' but no default was specified

Never seen before....

caiosweet commented 1 year ago

Hi, this is not the right place. This error is related to the card for my natural events package, and mostly refers to the INGV part. In any case, the solution is to modify the templates, which I think I had done at his time. Check if the cards relating to the package are updated. However, it seems that these errors are due to the new rules, which provide a default value. (e.g. see int/float etc)

mfabiani53 commented 1 year ago

Can you give me the link to your updated package? I am sure these errors depends also from the new rules as i never see them before updating HAOS.

caiosweet commented 1 year ago

Card natural events light

mfabiani53 commented 1 year ago

Thanks, last question. Where to find docs about the package? I see we need to install more integrations, etc....

caiosweet commented 1 year ago

The package is very very old.

In the documentation of the INGV component I had included an example of a card (markdown), extrapolating the data from the card contained in the Natural Events package. So, either you can take the data relating only to INGV, from the link I posted or from the example in the readme, or if you prefer to install the package, you can read this old article , taking care to replace some things, such as, for example, there are components that should no longer be installed via yaml but from the user interface.

In my opinion, it is better to take ideas and make the cards yourself, the packages only lead to confusion and are not very customizable :D

In conclusion, for the errors you have, just correct the templates with the new guidelines, for the default values, especially on the use of filters) Updating Templates with the new default values in 2021.10.x