thank you so much for your patience in trying to help me, but I’m so unprepared that I can’t make a mistake, I stop even before. maybe it’s time to abandon and use an already existing weather. Maybe too complex for me. I’m only sorry for having created a thousand sensors, but not being able to use them in some way
Ciao Diego,
I would like to have the same sensors from ARPAV…
Can you help me?
Maybe in private session and in italian.
Grazie
C’ho rinunciato… Non sono arrivato a concludere la cosa. Non sono riuscito a creare una entità meteo come volevo
Cosa ti mancava?
Ho visto che eri riuscito ad estrarre tutto; i dati li avevi tutti, giusto?
I tried in February, then I gave up. Now I’m trying again, and the rests from the XML it’s. I always get stuck in the forecast of the future day.
I’m stuck here:
weather:
- platform: template
name: Meteo ARPAV
condition_template: "{{ states('sensor.arpav_simbolo0') }}"
temperature_template: "{{ states('sensor.arpav_temperatura0') }}"
humidity_template: "{{ states('sensor.giardino_umidita') }}"
I did not understand how to format and where to insert that part that you indicated to me in the previous post:
[
{
"datetime": "2024-03-01T12:00:00+00:00",
"is_daytime": true,
"condition": "pouring",
"humidity": 86,
"pressure": 98675,
"temperature": 6,
"templow": 3,
"precipitation_probability": 59,
"wind_speed": 6
},
{
"datetime": "2024-03-02T00:00:00+00:00",
"is_daytime": false,
"condition": "cloudy",
"humidity": 92,
"pressure": 98996,
"temperature": 4,
"templow": 3,
"precipitation_probability": 28,
"wind_speed": 3
}
]
Have the rest temperature sensors, forecasts, precipitation and even a description as a text, but I think they are all useless things, only the forecasts and temperatures should serve.
I have the forecast for the next 5 half days (day 1 morning - evening day 2 morning - evening day 3) then two full days. This will be feasible to align it by comparing the current date with the date of the REST sensor, but it will be a future modification to be given. First I need to figure out how to fix them
You don’t "insert that code " — you have to build the data structure from the available forecast data. Look again at my post:
… where I build the hourly forecast data structure in the template weather entity:
forecast_hourly_template: >
{% from 'met_office_codes.jinja' import code2ha %}
{% from 'direction.jinja' import dir %}
{% set dh = state_attr('sensor.local_datahub_hourly','timeSeries') %}
{% set ns = namespace(forecast=[]) %}
{% for ts in dh -%}
{% if ts['time']|as_datetime > now() %}
{% set tsd = { 'datetime': (ts['time']|as_datetime).isoformat(),
'condition': code2ha(ts['significantWeatherCode']),
'precipitation_probability': ts['probOfPrecipitation'],
'wind_bearing': dir(ts['windDirectionFrom10m']),
'humidity': ts['screenRelativeHumidity'],
'pressure': ts['mslp'],
'uv_index': ts['uvIndex'],
'temperature': ts['screenTemperature']|round(0),
'apparent_temperature': ts['feelsLikeTemperature']|round(0),
'wind_speed': ts['windSpeed10m']|round(0) } -%}
{% set ns.forecast = ns.forecast + [tsd] -%}
{% endif %}
{% endfor %}
{{ ns.forecast }}
You need to do the same to get whatever your input looks like into the same structure.
@Troon I read everything and did a lot of tests, but my inexperience and my bad relationship with English are perhaps making me go the wrong way.
I didn’t understand, but in the end your method creates a weather entity, or creates a sensor with the same data, but not exactly a weather entity? just to understand, because I’m reading everywhere that the weather forecast entity is not supported, so I don’t understand
It creates a Template Weather entity, which should be the same as a “real” weather entity. Here’s what mine looks like:
But in this way, will you not be able to use cards already made specifically for correct weather entities? I’m trying to understand🧐
Yes you will.
I have a very long file in package called arpav.yaml.
I was hoping to have arrived at a good point, look, a part that downloads the bulletins, then rest to extract all the data, all the available sensors, a working arpav weather entity with the current forecasts, but nothing, for future forecasts I can’t figure out how to create that part of the code.
##############################################################
# #
# BINARY_SENSOR #
# #
##############################################################
# diventa ON quanto c'è nuovo bollettino, serve per visualizzazione su scheda
binary_sensor:
- platform: template
sensors:
arpav_nuovo_bollettino:
entity_id: input_boolean.arpav_nuovo_bollettino
device_class: update
value_template: "{{ is_state('input_boolean.arpav_nuovo_bollettino', 'on') }}"
icon_template: >-
{% if is_state('input_boolean.arpav_nuovo_bollettino', 'on') %}
mdi:information-variant
{% else %}
mdi:information-outline
{% endif %}
##############################################################
# #
# SENSORI #
# #
##############################################################
sensor:
# seleziona l'ID dell zona per i sensor restful
- platform: template
sensors:
arpav_zona_id:
entity_id: input_select.arpav_zona
icon_template: mdi:target
value_template: >-
{% set zona = states('input_select.arpav_zona') %}
{% if zona == "Dolomiti Nord-Est" %} 0
{% elif zona == "Dolomiti Sud-Ovest" %} 1
{% elif zona == "Belluno e Prealpi orientali" %} 2
{% elif zona == "Prealpi centrali" %} 3
{% elif zona == "Pedemontana orientale" %} 4
{% elif zona == "Treviso e pianura orientale" %} 5
{% elif zona == "Veneziano orientale" %} 6
{% elif zona == "Prealpi occidentali" %} 7
{% elif zona == "Vicenza e pedemontana" %} 8
{% elif zona == "Padova e pianura centrale" %} 9
{% elif zona == "Venezia e laguna" %} 10
{% elif zona == "Delta del Po" %} 11
{% elif zona == "Rovigo e pianura meridionale" %} 12
{% elif zona == "Verona e pedemontana" %} 13
{% elif zona == "Area del Garda" %} 14
{% elif zona == "Litorale nord" %} 15
{% elif zona == "Litorale centrale" %} 16
{% else%} 17
{% endif %}
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: ARPAV Bollettino Aggiornamento
value_template: >
{% set data_ora = value_json.previsioni.data_aggiornamento['@date'] | default(None) %}
{% if data_ora is not none %}
{% set data = data_ora.split(' alle ')[0] %}
{% set ora = data_ora.split(' alle ')[1].replace('.', ':') %}
{% set anno_corrente = now().year %}
{% if data.count('/') == 2 %}
{{ strptime(data ~ ' ' ~ ora, '%d/%m/%Y %H:%M').strftime('%Y-%m-%dT%H:%M:%S') }}
{% else %}
{{ strptime(data ~ '/' ~ anno_corrente ~ ' ' ~ ora, '%d/%m/%Y %H:%M').strftime('%Y-%m-%dT%H:%M:%S') }}
{% endif %}
{% else %}
"nessuno"
{% endif %}
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: ARPAV Bollettino Emissione
value_template: >
{% set data_ora = value_json.previsioni.data_emissione['@date'] %}
{% set data = data_ora.split(' alle ')[0] %}
{% set ora = data_ora.split(' alle ')[1].replace('.', ':') %}
{% set anno_corrente = now().year %}
{% if data.count('/') == 2 %}
{{ strptime(data ~ ' ' ~ ora, '%d/%m/%Y %H:%M').strftime('%Y-%m-%dT%H:%M:%S') }}
{% else %}
{{ strptime(data ~ '/' ~ anno_corrente ~ ' ' ~ ora, '%d/%m/%Y %H:%M').strftime('%Y-%m-%dT%H:%M:%S') }}
{% endif %}
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_zona
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int]['@name'] }}"
scan_interval: 600
# Prima Mezza Giornata
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_simbolo0
value_template: >
{% set url = value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[0].previsione[0]['@value'] | default('Valore non disponibile') %}
{% if url != 'Valore non disponibile' %}
{% set file_name = url.split('/')[-1].replace('.png', '') %}
{% if file_name == 'a1N' %}
clear-night
{% elif file_name in ['a4', 'a5', 'a6'] %}
cloudy
{% elif file_name in ['f1', 'f2', 'f3', 'f4'] %}
fog
{% elif file_name in ['c1', 'c2', 'c3', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] %}
lightning-rainy
{% elif file_name == 'a3' %}
partlycloudy
{% elif file_name in ['b6', 'b7', 'b8', 'b9', 'b10'] %}
pouring
{% elif file_name in ['b1', 'b2', 'b3', 'b4', 'b5'] %}
rainy
{% elif file_name in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10'] %}
snowy
{% elif file_name in ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'e10'] %}
snowy-rainy
{% elif file_name in ['a1', 'a2'] %}
sunny
{% else %}
"Condizione sconosciuta"
{% endif %}
{% else %}
"Valore non disponibile"
{% endif %}
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_data0
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[0]['@data'] | default('Valore non disponibile') }}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_cielo0
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[0].previsione[1]['@value'] | default('Valore non disponibile') }}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_temperatura0
value_template: >
{%- set temp_string = value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[0].previsione[2]['@value'] -%}
{%- set numbers = temp_string | regex_findall('\\d+') -%}
{%- if numbers | length == 2 -%}
{{ ((numbers[0] | int + numbers[1] | int) / 2) | round(0) }}
{%- elif numbers | length == 1 -%}
{{ numbers[0] | int }}
{%- else -%}
Valore non disponibile
{%- endif -%}
scan_interval: 600
unit_of_measurement: "°C"
device_class: temperature
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_precipitazioni0
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[0].previsione[3]['@value'] | default('Valore non disponibile') }}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_probabilita0
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[0].previsione[4]['@value'] | default('Valore non disponibile') }}"
scan_interval: 600
# Seconda Mezza Giornata
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_simbolo1
value_template: >
{% set url = value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[1].previsione[0]['@value'] | default('Valore non disponibile') %}
{% if url != 'Valore non disponibile' %}
{% set file_name = url.split('/')[-1].replace('.png', '') %}
{% if file_name == 'a1N' %}
clear-night
{% elif file_name in ['a4', 'a5', 'a6'] %}
cloudy
{% elif file_name in ['f1', 'f2', 'f3', 'f4'] %}
fog
{% elif file_name in ['c1', 'c2', 'c3', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] %}
lightning-rainy
{% elif file_name == 'a3' %}
partlycloudy
{% elif file_name in ['b6', 'b7', 'b8', 'b9', 'b10'] %}
pouring
{% elif file_name in ['b1', 'b2', 'b3', 'b4', 'b5'] %}
rainy
{% elif file_name in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10'] %}
snowy
{% elif file_name in ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'e10'] %}
snowy-rainy
{% elif file_name in ['a1', 'a2'] %}
sunny
{% else %}
"Condizione sconosciuta"
{% endif %}
{% else %}
"Valore non disponibile"
{% endif %}
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_data1
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[1]['@data'] }}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_cielo1
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[1].previsione[1]['@value'] }}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_temperatura1
value_template: >
{%- set temp_string = value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[1].previsione[2]['@value'] -%}
{%- set numbers = temp_string | regex_findall('\\d+') -%}
{%- if numbers | length == 2 -%}
{{ ((numbers[0] | int + numbers[1] | int) / 2) | round(0) }}
{%- elif numbers | length == 1 -%}
{{ numbers[0] | int }}
{%- else -%}
Valore non disponibile
{%- endif -%}
scan_interval: 600
unit_of_measurement: "°C"
device_class: temperature
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_precipitazioni1
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[1].previsione[3]['@value']}}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_probabilita1
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[1].previsione[4]['@value']}}"
scan_interval: 600
# terza Mezza Giornata
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_simbolo2
value_template: >
{% set url = value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[2].previsione[0]['@value'] | default('Valore non disponibile') %}
{% if url != 'Valore non disponibile' %}
{% set file_name = url.split('/')[-1].replace('.png', '') %}
{% if file_name == 'a1N' %}
clear-night
{% elif file_name in ['a4', 'a5', 'a6'] %}
cloudy
{% elif file_name in ['f1', 'f2', 'f3', 'f4'] %}
fog
{% elif file_name in ['c1', 'c2', 'c3', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'] %}
lightning-rainy
{% elif file_name == 'a3' %}
partlycloudy
{% elif file_name in ['b6', 'b7', 'b8', 'b9', 'b10'] %}
pouring
{% elif file_name in ['b1', 'b2', 'b3', 'b4', 'b5'] %}
rainy
{% elif file_name in ['d1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'd10'] %}
snowy
{% elif file_name in ['e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'e10'] %}
snowy-rainy
{% elif file_name in ['a1', 'a2'] %}
sunny
{% else %}
"Condizione sconosciuta"
{% endif %}
{% else %}
"Valore non disponibile"
{% endif %}
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_data2
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[2]['@data'] }}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_cielo2
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[2].previsione[1]['@value'] }}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_temperatura2
value_template: >
{%- set temp_string = value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[2].previsione[2]['@value'] -%}
{%- set numbers = temp_string | regex_findall('\\d+') -%}
{%- if numbers | length == 2 -%}
{{ ((numbers[0] | int + numbers[1] | int) / 2) | round(0) }}
{%- elif numbers | length == 1 -%}
{{ numbers[0] | int }}
{%- else -%}
Valore non disponibile
{%- endif -%}
scan_interval: 600
unit_of_measurement: "°C"
device_class: temperature
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_precipitazioni2
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[2].previsione[3]['@value']}}"
scan_interval: 600
- platform: rest
resource: https://www.arpa.veneto.it/previsioni/it/xml/bollettino_utenti.xml
name: arpav_probabilita2
value_template: "{{ value_json.previsioni.meteogrammi.meteogramma[states('sensor.arpav_zona_id')|int].scadenza[2].previsione[4]['@value']}}"
scan_interval: 600
# Aggiungi i sensori template separatamente
forecast_hourly_template: >
{% from 'met_office_codes.jinja' import code2ha %}
{% from 'direction.jinja' import dir %}
{% set dh = state_attr('sensor.local_datahub_hourly','timeSeries') %}
{% set ns = namespace(forecast=[]) %}
{% for ts in dh -%}
{% if ts['time']|as_datetime > now() %}
{% set tsd = { 'datetime': (ts['time']|as_datetime).isoformat(),
'condition': code2ha(ts['significantWeatherCode']),
'precipitation_probability': ts['probOfPrecipitation'],
'wind_bearing': dir(ts['windDirectionFrom10m']),
'humidity': ts['screenRelativeHumidity'],
'pressure': ts['mslp'],
'uv_index': ts['uvIndex'],
'temperature': ts['screenTemperature']|round(0),
'apparent_temperature': ts['feelsLikeTemperature']|round(0),
'wind_speed': ts['windSpeed10m']|round(0) } -%}
{% set ns.forecast = ns.forecast + [tsd] -%}
{% endif %}
{% endfor %}
{{ ns.forecast }}
##############################################################
# #
# INPUT #
# #
##############################################################
# memorizza ultimo aggiornamento bollettino
input_text:
arpav_data_ultimo_aggiornamento:
name: ARPAV Data Ultimo Aggiornamento
# Diventa ON quando viene emesso un nuovo bollettino o un nuovo aggiornamento
input_boolean:
arpav_nuovo_bollettino:
name: ARPAV Nuovo Bollettino
# Selettore Zone presenti nel bollettino. Cambiare initial con la zona preferita
# altrimenti prende la prima della lista
input_select:
arpav_zona:
name: ARPAV Zona
options:
- "Dolomiti Nord-Est"
- "Dolomiti Sud-Ovest"
- "Belluno e Prealpi orientali"
- "Prealpi centrali"
- "Pedemontana orientale"
- "Treviso e pianura orientale"
- "Veneziano orientale"
- "Prealpi occidentali"
- "Vicenza e pedemontana"
- "Padova e pianura centrale"
- "Venezia e laguna"
- "Delta del Po"
- "Rovigo e pianura meridionale"
- "Verona e pedemontana"
- "Area del Garda"
- "Litorale nord"
- "Litorale centrale"
- "Litorale sud"
icon: mdi:target
initial: "Padova e pianura centrale"
##############################################################
# #
# SCRIPT #
# #
##############################################################
script:
bollettino_popup:
sequence:
- service: input_boolean.turn_off
data:
entity_id: input_boolean.arpav_nuovo_bollettino
##############################################################
# #
# AUTOMAZIONI #
# #
##############################################################
automation:
# Mette ON input_boolean.arpav_nuovo_bollettino quando cambia la data rispetto
# all'ultimo aggiornamento contenuta in input_text.arpav_data_ultimo_aggiornamento
- id: '1575837712577'
mode: single
alias: Aggiornamento bollettino ARPAV
trigger:
- platform: template
value_template: "{{ states('sensor.arpav_bollettino_aggiornamento') != states('input_text.arpav_data_ultimo_aggiornamento') }}"
condition: []
action:
- data: {}
entity_id: input_boolean.arpav_nuovo_bollettino
service: input_boolean.turn_on
- data_template:
value: "{{states('sensor.arpav_bollettino_aggiornamento')}}"
entity_id: input_text.arpav_data_ultimo_aggiornamento
service: input_text.set_value
# Aggiorna i sensori sensor.arpav_xxxx dopo ogni cambio di stato del selettore input_select.arpav_zona
# e mette ON input_boolean.arpav_nuovo_bollettino
- id: '1575837712578'
mode: single
alias: aggiorna sensori ARPAV
trigger:
platform: state
entity_id: input_select.arpav_zona
action:
- service: homeassistant.update_entity
entity_id:
- sensor.arpav_zona
- sensor.arpav_data0
- sensor.arpav_simbolo0
- sensor.arpav_cielo0
- sensor.arpav_temperatura0
- sensor.arpav_precipitazioni0
- sensor.arpav_probabilita0
- sensor.arpav_data1
- sensor.arpav_simbolo1
- sensor.arpav_cielo1
- sensor.arpav_temperatura1
- sensor.arpav_precipitazioni1
- sensor.arpav_probabilita1
- sensor.arpav_data2
- sensor.arpav_simbolo2
- sensor.arpav_cielo2
- sensor.arpav_temperatura2
- sensor.arpav_precipitazioni2
- sensor.arpav_probabilita2
- data: {}
entity_id: input_boolean.arpav_nuovo_bollettino
service: input_boolean.turn_on
weather:
- platform: template
name: Meteo ARPAV
condition_template: "{{ states('sensor.arpav_simbolo0') }}"
temperature_template: "{{ states('sensor.arpav_temperatura0') }}"
humidity_template: "{{ states('sensor.giardino_umidita') }}"
this really escapes me and I don’t understand, I think I’ll have to give up for the second time
forecast_hourly_template: >
{% from 'met_office_codes.jinja' import code2ha %}
{% from 'direction.jinja' import dir %}
{% set dh = state_attr('sensor.local_datahub_hourly','timeSeries') %}
{% set ns = namespace(forecast=[]) %}
{% for ts in dh -%}
{% if ts['time']|as_datetime > now() %}
{% set tsd = { 'datetime': (ts['time']|as_datetime).isoformat(),
'condition': code2ha(ts['significantWeatherCode']),
'precipitation_probability': ts['probOfPrecipitation'],
'wind_bearing': dir(ts['windDirectionFrom10m']),
'humidity': ts['screenRelativeHumidity'],
'pressure': ts['mslp'],
'uv_index': ts['uvIndex'],
'temperature': ts['screenTemperature']|round(0),
'apparent_temperature': ts['feelsLikeTemperature']|round(0),
'wind_speed': ts['windSpeed10m']|round(0) } -%}
{% set ns.forecast = ns.forecast + [tsd] -%}
{% endif %}
{% endfor %}
{{ ns.forecast }}
For starters, you need to make a template weather entity. You just copied and pasted what troon wrote into your configuration.
yes exactly, I copied and pasted saying “I don’t understand this thing”. I understand that I have to create a weather template entity, I will still have to study to understand how
How have you created any other template entity? Note your file has other examples of other templates. e.g. your binary sensor starts with
And the template weather documents show:
Yet you just copied and pasted
thanks again for your patience, little by little I hope to succeed!
I created this:
weather:
- platform: template
name: Meteo ARPAV
condition_template: "{{ states('sensor.arpav_simbolo1') }}"
temperature_template: "{{ states('sensor.arpav_temperatura1') }}"
humidity_template: "{{ states('sensor.giardino_umidita') }}"
forecast_daily_template: "{{ states('sensor.forecast_arpav') }}"
then I also created a template, hoping it works, as a test:
- platform: template
sensors:
forecast_arpav:
friendly_name: "Forecast ARPAV"
unique_id: forecast_arpav
value_template: >
{% set ns = namespace(forecast=[]) %}
{% set simbolo = states('sensor.arpav_simbolo1') %}
{% set temperatura = states('sensor.arpav_temperatura1') %}
{% set precipitazioni = states('sensor.arpav_precipitazioni1') %}
{% set probabilita_precipitazioni = states('sensor.arpav_probabilita1') %}
{% set cielo = states('sensor.arpav_cielo2') %}
{% if simbolo != 'Valore non disponibile' and temperatura != 'Valore non disponibile' %}
{% set tsd = {
'datetime': now().isoformat(),
'condition': simbolo,
'temperature': temperatura,
'precipitation_probability': probabilita_precipitazioni,
'precipitation': precipitazioni,
'sky_condition': cielo
} %}
{% set ns.forecast = ns.forecast + [tsd] %}
{% endif %}
{{ ns.forecast }}
at least now I managed to save my arpav.yaml file without errors and restart home assistant.
The weather entity is created, but no forecast, I think there are definitely errors in my template. Now I just have to figure out how to generate it correctly, I have the data, I just have to figure out how to make home assistant understand it
Paste that whole template into Developer Tools / Template and see what it generates.
You should be looking for a state of 'unavailable'
— the front end might translate it into Valore non disponibile but the template will look for the “real” state.
this:
- platform: template
sensors:
forecast_arpav:
friendly_name: "Forecast ARPAV"
unique_id: forecast_arpav
value_template: >
{% set ns = namespace(forecast=[]) %}
{% set simbolo = states('sensor.arpav_simbolo1') %}
{% set temperatura = states('sensor.arpav_temperatura1') %}
{% set precipitazioni = states('sensor.arpav_precipitazioni1') %}
{% set probabilita_precipitazioni = states('sensor.arpav_probabilita1') %}
{% set cielo = states('sensor.arpav_cielo2') %}
{% if simbolo != 'Valore non disponibile' and temperatura != 'Valore non disponibile' %}
{% set tsd = {
'datetime': now().isoformat(),
'condition': simbolo,
'temperature': temperatura,
'precipitation_probability': probabilita_precipitazioni,
'precipitation': precipitazioni,
'sky_condition': cielo
} %}
{% set ns.forecast = ns.forecast + [tsd] %}
{% endif %}
{{ ns.forecast }}
answer:
Tipo di risultato: string
- platform: template
sensors:
forecast_arpav:
friendly_name: "Forecast ARPAV"
unique_id: forecast_arpav
value_template: >
[{'datetime': '2024-10-15T22:30:00.388459+02:00', 'condition': 'cloudy', 'temperature': '12', 'precipitation_probability': '20%', 'precipitation': 'Deboli piogge sparse', 'sky_condition': 'Nuvoloso o molto nuvoloso'}]
OK, that’s a good start. You only have one forecast entry, but that’s to be expected as you have no for
loop. You’ll need to fix the precipitation_probability
, which must just be a number. Either do that in the original sensor or in your template like this:
{% set precipitazioni = states('sensor.arpav_precipitazioni1')|replace('%','') %}
Maybe I’m taking crazy pills, but that configuration is back to a template sensor, not weather entity.
I can’t comment on the pills, but you’re right.
@Diegocampy — this must be a forecast_daily_template:
(or hourly
) under a template weather entity. Look at the docs again: