Skip to content

Instantly share code, notes, and snippets.

@gardart
Last active April 7, 2024 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gardart/0a7d2711fba1d34a59614923b21b82ab to your computer and use it in GitHub Desktop.
Save gardart/0a7d2711fba1d34a59614923b21b82ab to your computer and use it in GitHub Desktop.
Home Assistant skynjari fyrir 3ja tíma mannaðar veðurathuganir frá Veðurstofu Íslands
#########################
# 5.4.2024 : Breytti ur apis.is yfir i xml thjonustu vedur.is
#
# Home Assistant skynjari fyrir 3ja tíma mannaðar veðurathuganir frá Veðurstofu Íslands.
# Mannaðar veðurstöðvar birta athuganir á 3 klst fresti.
# https://www.vedur.is/media/vedurstofan/XMLthjonusta.pdf
#
# Stöðvanúmerin má finna með því að fara á slóðina: https://www.vedur.is/vedur/stodvar
# Hér að neðan er Reykjavík valin (station=1)
#
# Skynjarinn inniheldur eftirfarandi mælingar
# F: Vindhraði (m/s)
# FX: Mesti vindhraði (m/s)
# FG: Mesta vindhviða (m/s)
# D: Vindstefna
# T: Hiti (°C)
# W: Veðurlýsing
# V: Skyggni (km)
# N: Skýjahula (%)
# P: Loftþrýstingur (hPa)
# RH: Rakastig (%)
# SNC: Lýsing á snjó
# SND: Snjódýpt (cm)
# SED: Sjólag
# RTE: Vegahiti (°C)
# TD: Daggarmark (°C)
# R: Uppsöfnuð úrkoma (mm / klst) úr sjálfvirkum mælum
#########################
sensor:
- platform: rest
name: imo_reykjavik_1h
scan_interval: 600
json_attributes_path: "$.observations.station"
json_attributes:
- id
- name
- time
- link
- F
- FX
- FG
- D
- T
- W
- V
- N
- P
- RH
- SNC
- SND
- SED
- RTE
- TD
- R
- err
- valid
resource: https://xmlweather.vedur.is/?op_w=xml&view=xml&type=obs&lang=is&ids=1&params=F;FX;FG;D;T;W;V;N;P;RH;SNC;SND;SED;RTE;TD;R
value_template: '{{ value_json.observations.station.W }}'
- platform: template
sensors:
vedur_rvk_temperature_1h:
friendly_name: "Reykjavík hitastig"
value_template: "{{ state_attr('sensor.imo_reykjavik_1h','T' ) | replace(',','.') | float(0) }}"
device_class: temperature
unit_of_measurement: '°C'
- platform: template
sensors:
vedur_rvk_wind_speed_1h:
friendly_name: "Reykjavík vindhraði"
value_template: "{{ state_attr('sensor.imo_reykjavik_1h','F' ) | replace(',','.') | float(0) }}"
device_class: speed
unit_of_measurement: 'm/s'
- platform: rest
name: imo_reykjavik_3h
scan_interval: 600
json_attributes_path: "$.observations.station"
json_attributes:
- id
- name
- time
- link
- F
- FX
- FG
- D
- T
- W
- V
- N
- P
- RH
- SNC
- SND
- SED
- RTE
- TD
- R
- err
- valid
resource: https://xmlweather.vedur.is/?op_w=xml&view=xml&type=obs&lang=is&ids=1&params=F;FX;FG;D;T;W;V;N;P;RH;SNC;SND;SED;RTE;TD;R&time=3h
value_template: '{{ value_json.observations.station.W }}'
- platform: template
sensors:
vedur_rvk_temperature:
friendly_name: "Hitastig"
value_template: "{{ state_attr('sensor.imo_reykjavik_3h','T' ) | replace(',','.') | float(0) }}"
device_class: temperature
unit_of_measurement: '°C'
- platform: template
sensors:
vedur_rvk_wind_speed:
friendly_name: "Reykjavík vindhraði"
value_template: "{{ state_attr('sensor.imo_reykjavik_3h','F' ) | replace(',','.') | float(0) }}"
device_class: speed
unit_of_measurement: 'm/s'
- platform: rest
name: Veðurhorfur á höfuðborgarsvæðinu
scan_interval: 3600
json_attributes_path: "$.texts.text"
json_attributes:
- title
- creation
- valid_from
- valid_to
- id
- content
resource: https://xmlweather.vedur.is/?op_w=xml&view=xml&type=txt&lang=is&ids=3
value_template: '{{ value_json.texts.text.content }}'
# Veðurhorfur á suðurlandi
- platform: rest
name: Veðurhorfur á suðurlandi
scan_interval: 3600
json_attributes_path: "$.texts.text"
json_attributes:
- title
- creation
- valid_from
- valid_to
- id
- content
resource: https://xmlweather.vedur.is/?op_w=xml&view=xml&type=txt&lang=is&ids=31
value_template: '{{ value_json.texts.text.content }}'
# Veðurhorfur á landinu
- platform: rest
name: Veðurhorfur á landinu
scan_interval: 3600
json_attributes_path: "$.texts.text"
json_attributes:
- title
- creation
- valid_from
- valid_to
- id
- content
resource: https://xmlweather.vedur.is/?op_w=xml&view=xml&type=txt&lang=is&ids=2
value_template: '{{ value_json.texts.text.content }}'
# Hugleiðingar veðurfræðings
- platform: scrape
resource: https://www.vedur.is/vedur/spar/textaspar
name: Hugleiðingar veðurfræðings
select: ".pgmain .wrap .article .boxbody .textforec p"
value_template: '{{ value | truncate(255) }}'
scan_interval: 3600
headers:
User-Agent: Mozilla/5.0
# Í Lovelace er svo hægt að kalla í þetta frá markdown card
## Veðurhorfur á höfuðborgarsvæðinu
## {{ states.sensor.vedurhorfur_a_hofudborgarsvaedinu.attributes.content }}
## Hugleiðingar veðurfræðings
## {{ states('sensor.hugleidingar_vedurfraedings') }}
@snjallingur
Copy link

Seems like https://apis.is/weather/ is not an available resource anymore. Should probably switch to use https://xmlweather.vedur.is/?op_w=xml&view=xml&type=obs&lang=is&time=3h&ids=1 instead

@gardart
Copy link
Author

gardart commented Apr 7, 2024

@snjallingur . Now using XML service directly from xmlweather.vedur.is since apis.is is broken. Added 1 hour sensor as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment