I have a Python script which parses some data from Slovenian weather service to get forecast for tomorrow and a day after tomorrow. If I call /bin/python3 /config/python_scripts/arso_parse2.py I get data in readable form:
Time/Day: 15.04.2024 17:00 CEST Ponedeljek CEST (popoldne)
Temperatura: 25 °C
Hitrost vetra: 12 m/s
Padavine:
Vremenska napoved: pretežno jasno ()
Time/Day: 16.04.2024 8:00 CEST Torek CEST (zjutraj)
Temperatura: 13 °C
Hitrost vetra: 0 m/s
Padavine:
Vremenska napoved: pretežno oblačno ()
Time/Day: 16.04.2024 17:00 CEST Torek CEST (popoldne)
Temperatura: 6 °C
Hitrost vetra: 8 m/s
Padavine: mod
Vremenska napoved: oblačno (plohe)
Which is OK for a start. My goal is to get this data to sensor, so I could use it in announcements or get info over VA…
That data is not JSON, so you can’t treat it like it is.
Best options are: see if you can get HA to talk directly to the weather service and remove the Python script from the picture; or see if you can get the script to output JSON.
You can work with the data format you have, but it’s not ideal.
import requests
from bs4 import BeautifulSoup
# Fetch XML data
url = "https://meteo.arso.gov.si/uploads/probase/www/fproduct/text/sl/fcast_SI_OSREDNJESLOVENSKA_latest.xml"
response = requests.get(url)
# Check if request was successful
if response.status_code == 200:
# Parse XML content
soup = BeautifulSoup(response.content, 'xml')
# Find all metData elements
met_data_list = soup.find_all('metData')
# Iterate over each metData element
for met_data in met_data_list:
# Extract time or day information
valid_day = met_data.find('valid_day').text
valid_daypart = met_data.find('valid_daypart').text
valid_time = met_data.find('valid').text
# Extract temperature information
t_var_desc = met_data.find('t_var_desc').text
t_var_unit = met_data.find('t_var_unit').text
t = met_data.find('t').text
# Extract wind speed information
ff_var_desc = met_data.find('ff_var_desc').text
ff_var_unit = met_data.find('ff_var_unit').text
ff_value = met_data.find('ff_value').text
# Extract precipitation information
rr_decode_text = met_data.find('rr_decodeText').text
# Extract weather forecast information
nn_short_text = met_data.find('nn_shortText').text
wwsyn_short_text = met_data.find('wwsyn_shortText').text
# Print the information
print(f"Time/Day: {valid_time} {valid_day} ({valid_daypart})")
print(f"Temperatura: {t} {t_var_unit}")
print(f"Hitrost vetra: {ff_value} {ff_var_unit}")
print(f"Padavine: {rr_decode_text}")
print(f"Vremenska napoved: {nn_short_text} ({wwsyn_short_text})")
print() # Print newline after each metData element
else:
print("Failed to fetch XML data from the URL.")
Well, the weather service provides RSS, XML and HTML formats
Use the rest integration to pull the data you want from the XML with a single call. Let me know if you need help with that, but it looks pretty simple. Which data do you want?
json_attributes_path is the JSONPath of the element that the attributes you want to pull is stored in: here, it’s $.data and you then want the metData structure (list) as an attribute.
I don’t know any better way to present data for tomorrow and a day after tomorrow forecast as with use of a list since the metData spits out 3 sets of forecast. So I made a template sensor separate for today [0], tomorrow morning [1] and tomorrow afternoon [2] using this:
- platform: template
sensors:
arso_napoved_jutri_popoldne:
friendly_name: "ARSO napoved vremena jutri popoldne"
unique_id: arso_napoved_jutri_popoldne
value_template: >
{% set forecast_list = state_attr('sensor.arso_forecast', 'metData') %}
{% if forecast_list and forecast_list|length >= 3 %}
Jutri popoldne bo {{ forecast_list[2]['nn_shortText'] }}.
{% else %}
Za jutri popoldne ni vremenske napovedi.
{% endif %}
As there is sometimes some additional shot text added to a primary forecast, I used this template to add this or omit if there is null being presented instead of forecast state. For example partly cloudly [and] showers. This ‘showers’ is that part and if the forecast is just partly cloudly and no second part, the second part has null. So I changed to this:
{% set forecast_list = state_attr('sensor.arso_forecast', 'metData') %}
{% if forecast_list and forecast_list|length >= 2 %}
{{ forecast_list[1]['nn_shortText'] }}
{% if forecast_list[1]['wwsyn_shortText'] != 'null' %}
{% if forecast_list[1]['wwsyn_shortText'] is not none %}
({{ forecast_list[1]['wwsyn_shortText'] }})
{% endif %}
{% endif %}
{% else %}
Za jutri zjutraj ni vremenske napovedi.
{% endif %}
I havent tested it though because I’m waiting for fresh forecast
Hi.
I’m wondering if someone can write me a code to insert into HA that would read the current weather from ARSO for Logatec. I don’t need other data because I have my own weather station, which unfortunately gets data about the current weather from wunderground, which is not nearly accurate.
Thanks for your help.
I’m currently working on building custom component which fetches from ARSO api. But the downside is it’s a sensor entity and not weather entity (so far). So you can use it only for sensor, if you know what I mean. The data provided are current and forecast for next 5 days.
But it shows current weather conditions in slovenian language. If you prefer english (or for configuring weather template, I’m not there yet
You can test this one:
and let me know of any error or mistakes…the code is from this weekend
Hello.
Thanks for the reply.
I downloaded the file and found that I need to add it in devices & services as shown in the image below and then I can select a location.
Yes, I’m aware, the data from ARSO API is for forecast (3h, 6h, 24h) and currently I’m having problems with importing values as current weather conditions from api.
I’m working on it…
As for weather state (sunny - > display as jasno) and in weather CC is shown ‘delno oblačno’ it’s different because weather template needs state in english, but for weather entity (arso_weather CC) it’s originaly ok to be in Slovenian. It’s a bit confused, I’m still struggling to find the right way to transform arso api to hass recognized values.
Hi. Did you try to change hardocoded value to Logatec in [GitHub - andrejs2/ARSO-Weather-Conditions-RSS-Feed-Parser](https://github.com/andrejs2/ARSO-Weather-Conditions-RSS-Feed-Parser/tree/main)
I didn’t, because I don’t know (I have no programming knowledge) and I also realized that I don’t need this add-on, because I have a home weather station, I get all the data from it except the current state, which I get via GitHub - cytech/Home-Assistant-wundergroundpws: Home Assistant custom component sensor for Weather Underground personal weather station users add-on, which has a problem with displaying the current weather condition, which almost never matches the current weather condition in Logatco. (for example, in Maribor it is raining, here the sun is shining, but it shows me a clear night “confusion”).
Well, the speed test from AKOS, it depends if they provide API key for this. But as far as I know, it’s different service as speed dot net. But this is some other topic …
What are you trying to say? Did the weather sensor report state?
If not, there is a flaw in a code because the weather integration allows only one state - ‘cloudy’ and not combined states ‘oblačno, rosi’ for instance. I’m aware of the flaws in integration.
My new integration I’m just finishing will try to ‘merge’ multiple weather states (‘pojavi’) which ARSO is reporting (clould coverage + weather condition) into only numerus clausus states from weather integration from HA. It’s a bit complicated because ARSO is having realy detailed weather conditions reporting espacally from manned observation stations.
Stay tuned for a new version for ARSO Weather.
Thanks for reporting!
Sorry for the confusion. I just had to do something while I was writing and I’d rather just post than write again. I have now corrected the text. I wrote about Custom ARSO Weather Component for Home Assistant. I wrote with the intention that if you find something useful in the description of the add-on for installation, because I, as a layman, needed for quite some time what you meant when you wrote, if I tried to change the location of the weather station.