Giter Site home page Giter Site logo

kpisacic / dhmz-home-assistant-custom-component Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 0.0 109 KB

Home Assistant Custom Components for DHMZ service ("Državni hidrometeorološki zavod Republike Hrvatske / "Croatian Meteorological and Hydrological Service" )

License: MIT License

Python 74.06% JavaScript 25.94%
home-assistant custom-component croatia croatian-meteorological weather weather-platform hacs home-assistant-component home-assistant-custom home-assistant-sensor

dhmz-home-assistant-custom-component's Introduction

DHMZ-home-assistant-custom-component

Home Assistant Custom Components for DHMZ weather service ("Državni hidrometeorološki zavod Republike Hrvatske" / "Croatian Meteorological and Hydrological Service")

The dhmz weather platform provide meteorological data for DHMZ service ("Državni hidrometeorološki zavod Republike Hrvatske / "Croatian Meteorological and Hydrological Service") - https://meteo.hr/ . Data from DHMZ is listed on https://meteo.hr/proizvodi.php?section=podaci&param=xml_korisnici and provided under Open Licence of Republic of Croatia - https://data.gov.hr/otvorena-dozvola and https://data.gov.hr/open-licence-republic-croatia . Custom weather card is also included in the package, combining graphical forecast data in weather card.

The following device types and data are supported:

Installation

There are two options; manual or HACS installation:

Manual installation

  • Copy dhmz folder in custom_components from repository to your Home Assistant configuration custom_components folder. Don't copy any other YAML files from repository root not to overwrite your own configuration.
  • Copy dhmz-weather-card.js from www repocitory folder to your Home Assistant configuration www folder

HACS installation

hacs_badge

Location Selection

Each platform does not choose automatically which weather station's data to use. Selection of different identifiers is under configuration section of this document. Current version does not validate nor enforces configuration choices, but this is down the development roadmap.

For each platform, the location to use is determined according to the following list:

Weather

The dhmz weather platform populates a weather card with DHMZ current conditions and forecast data. To add DHMZ weather to your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
weather:
  - platform: dhmz
    name: DHMZ Maksimir
    station_name: Zagreb-Maksimir
    forecast_region_name: Zagreb
    forecast_text: zg_text
    forecast_station_name: Zagreb_Maksimir
  • The platform checks for new data every 20 minutes, and the source data is typically updated hourly within 10 minutes after the hour.
  • If no name is given, the weather entity will be named weather.dhmz.

Configuration

  • name:
    • description: Name to be used for the entity ID, e.g. weather.<name>.
    • required: false
    • type: string
  • station_name:
    • description: The station code of a specific weather station to use - see (#station_name)
    • required: true
    • type: string
  • forecast_region_name:
    • description: The forecase region_name - see (#forecast_region_name)
    • required: true
    • type: string
  • forecast_text:
    • description: The forecast text identifier - see ##forecast_text
    • required: true
    • type: string
  • forecast_station_name:
    • description: The forecast station name - see ##forecast_station_name
    • required: true
    • type: string

Sensor

The dhmz sensor platform creates sensors based on DHMZ current conditions data and daily forecasts.

To add DHMZ weather to your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
sensor:
  - platform: dhmz
    name: DHMZ Sensor Maksimir
    station_name: Zagreb-Maksimir
    forecast_region_name: Zagreb
    forecast_text: zg_text
    forecast_station_name: Zagreb_Maksimir
    monitored_conditions:
      - temperature
      - pressure
      - pressure_tendency
      - humidity
      - wind_speed
      - wind_bearing
      - condition
      - precipitation
      - forecast_text_today
      - forecast_text_tommorow
  • A sensor will be created for each of the following conditions, with a default name like sensor.<name>_temperature:
    • temperature - The current temperature, in ºC.
    • pressure - The current air pressure, in kPa.
    • pressure_tendency - The current air pressure tendency, e.g. "+0.5" in last hour.
    • humidity - The current humidity, in %.
    • condition - A brief text statement of the current weather conditions, e.g. "Sunny".
    • wind_speed - The current sustained wind speed, in km/h.
    • wind_bearing - The current cardinal wind direction, e.g. "SSW".
    • precipitation - precipitation in last 24 hours, in mm.
    • forecast_text_today - A textual description of today's forecast
    • forecast_text_tommorow - A textual description of tommorow's forecast

Configuration

  • name:
    • description: Name to be used for the entity ID, e.g. sensor.<name>_temperature.
    • required: false
    • type: string
  • station_name:
    • description: The station code of a specific weather station to use - see (#station_name)
    • required: true
    • type: string
  • forecast_region_name:
    • description: The forecase region_name - see (#forecast_region_name)
    • required: true
    • type: string
  • forecast_text:
    • description: The forecast text identifier - see ##forecast_text
    • required: true
    • type: string
  • forecast_station_name:
    • description: The forecast station name - see ##forecast_station_name
    • required: true
    • type: string
  • monitored_conditions:
    • description: List of sensors to monitor, create in home assistant
    • required: true
    • type: list or
      • temperature
      • pressure
      • pressure_tendency
      • humidity
      • wind_speed
      • wind_bearing
      • condition
      • precipitation
      • forecast_text_today
      • forecast_text_tommorow

Camera

The dhmz camera platform displays DHMZ [radar imagery].

To add DHMZ radar imagery to your installation, add the desired lines from the following example to your configuration.yaml file:

# Example configuration.yaml entry
camera:
  - platform: dhmz
    name: DHMZ Radar
    delta: 300
    previous_images_time: 125
    current_image_time: 2000
    longitude: 48
    latitude: 16
    mark_location: True
    image_format: WebP

Configuration

  • name:

    • description: Name to be used for the entity ID, e.g. camera.<name>.
    • required: false
    • type: string
  • delta:

    • description: Time in seconds between check for new radar images, defaults to 300 sec
    • required: false
    • type: integer
  • previous_images_time:

    • description: Time in miliseconds that determines how long old radar images in animation will be displayed, defaults to 125 ms
    • required: false
    • type: integer
  • current_image_time:

    • description: Time in miliseconds that determines how long last (current) radar image in animation will be displayed, defaults to 2000 ms
    • required: false
    • type: integer
  • mark_location:

    • description: mark red circle on geographical coordinates of current location, default is False (not to display location). Allowed values are: True or False
    • required: false
    • type: string
  • longitude:

    • description: Longitude of location to use for closest station determination, if not present will be taken from HA configuration
    • required: false
    • type: float
  • latitude:

    • description: Latitude of location to use for closest station determinationdetermination, if not present will be taken from HA configuration
    • required: false
    • type: float
  • image_format:

    • description: Animated image format that will be created, can be one of: WebP or GIF. Defaut is WebP.
    • required: false
    • type: string
  • If no name is given, the camera entity will be named camera.dhmz.

  • If no delta is given, default is set to 300 seconds (every 5 minutes). Since radar images on DHMZ are refreshed every 5 minutes, it is recommented to put this not less then 60 seconds (every minute). Components checks if image was actually updated and will not re-download it's contant if it is unchanged from last check.

  • previous_images_time and current_image_time can determine how radar image animation will be generated. All old but current radar images are show for previous_images_time and only last and current radar image is shown for current_image_time. Please note that since HA refreshes images every 10 seconds, best results are achieved if sum of all image times can be multiplied to this 10 seconds. This is why default values of 125 ms and 2000 ms - which sum up to 5 seconds (24x125+2000=5000) - which is nicely shown in the previes window without jerky and skipping frames. If changing these times it is strongly suggested to keep it to match to: 24 x previous_images_time + current_image_time = 10 sec or any other common denominator of 10 sec.

  • logitude and latitude are only usefull when setting mark_location as True. mark_location will work without explicitly stated logitude and latitude if HA has home location correctly configured.

  • image_format that animated image will be created in. Default is WebP, since it yields smaller image sizes. If you face issue in displaying WebP in your web browser, you can change to GIF, but files shall be larger and producing more traffic towards browser.

Known issues

  • When displaying radar image in home assistant's dashboard picture entity card, use "auto" not "live" mode. Ddifference is that in "auto" browser will fetch new picture every 10 seconds. And in "live" it will fetch every half seconds. This unfortunately cannot be changed, and for our purpose, more kless frequent refresh e.g. one per minute or even every 5 minutes, would be sufficient. This every 10 seconds refresh will cause only traffic between browser and home assistant server, not towards service provider DHMZ, since all images are cached. However, improvement would be to use some alternative to stock picture entity card which allows custom refresh rates. One such is https://github.com/dimagoltsman/refreshable-picture-card , but unfortunately, it does not work correctly for camera_image methods, only for static entity images.

Custom card

To add custom card for DHMZ weather, add following to your lovelace configuration YAML file:

  1. Under resources section add custom card definition
resources:
  - type: js
    url: /local/dhmz-weather-card.js
  1. In views and cards section add following card
    cards:
      - mode: hourly
        type: 'custom:dhmz-weather-card'
        weather: weather.dhmz_maksimir
        show_today_text: true
        show_tomorrow_text: true

With weather attribute you should state name of the entity configured in weather compontent. For mode, please use daily or hourly, since hourly was mostly customized and tested and is preffered to be used. Attribute show_today_text - shows today's text forecast (true|false), default is true. Attribute show_tomorrow_text - shows tomorrow's text forecast (true|false), default is true.

station_name

RC Bilogora
Bjelovar
Crikvenica
Crni Lug-NP Risnjak
Daruvar
Delnice
Dubrovnik
Dubrovnik-aerodrom
Gospić
RC Gorice (kod Nove Gradiške)
RC Gradište (kod Županje)
Gruda
Hvar
Imotski
Karlovac
Knin
Komiža
Krapina
Krk
Križevci
Kukuljanovo
Kutjevo
Lastovo
Lipik
Malinska
Makarska
Mali Lošinj
NP Mljet
RC Monte Kope
Ogulin
Opatija
RC Osijek-Čepin
Osijek-aerodrom
Palagruža
Parg-Čabar
Pazin
NP Plitvička jezera
Ploče
Poreč
Porer - svjetionik
Prevlaka
Pula
Pula-aerodrom
RC Puntijarka
Rab
Rijeka
Rijeka-aerodrom
Sv. Ivan na pučini - svjetionik
Senj
Sinj
Sisak
Slavonski Brod
Split-Marjan
Split-aerodrom
Šibenik
Varaždin
Veli Rat - svjetionik
Vinkovci
Zadar
Zadar-aerodrom
Zagreb-Grič
Zagreb-Maksimir
Zagreb-aerodrom
Zavižan

forecast_region_name

sredisnja
istocna
gorska
unutrasnjost Dalmacije
sjeverni Jadran
srednji Jadran
juzni Jadran
Zagreb

forecast_text

rh_text
zg_text

forecast_station_name

Beli_Manastir
Bilogora
Bjelovar
Cavtat
Cakovec
Zracna_luka_Dubrovni
Daruvar
Delnice
Donji_Miholjac
Dubrovnik
Dakovo
Fuzine
Glina
Gospic
Gracac
Gradiste
Hreljin
Hrvatska_Kostajnica
Hvar
Ilok
Imotski
Karlovac
Knin
Komiza
Koprivnica
Korcula
Krapina
Krizevci
Krk
Lastovo
Mali_Losinj
Makarska
Maslenica
Metkovic
Korita-NP_Mljet
Most_Krk
Nasice
Nin
Nova_Gradiska
Novska
Ogulin
Orebic
Osijek
Pag
Palagruza
cabar
Pazin
NP_Plitvicka_jezera
Ploce
Pokupsko
Porec
Pozega
Pula
Rab
Rijeka
Rovinj
Rupa
Senj
Sinj
Sisak
Slatina
Slavonski_Brod
Slunj
Split
Sibenik
Udbina
Varazdin
Vela_Luka
Vinkovci
Virovitica
Vukovar
Zadar
Zagreb_Maksimir
Zavizan
Zracna_luka_Zadar

dhmz-home-assistant-custom-component's People

Contributors

kpisacic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

dhmz-home-assistant-custom-component's Issues

update to python 3.9

Active graph is broken, seems that discontinued support for python 3.7 is the issue.

Log errors and warnings

There are few errors and warnings in log file:
Logger: homeassistant.components.weather
Source: custom_components/dhmz/weather.py:182
Integration: Weather (documentation, issues)
First occurred: 11:34:33 AM (2 occurrences)
Last logged: 11:34:33 AM

Error adding entities for domain weather with platform dhmz
Error while setting up dhmz platform for weather
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 691, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 777, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 574, in _async_write_ha_state
attr.update(self.extra_state_attributes or {})
File "/config/custom_components/dhmz/weather.py", line 182, in extra_state_attributes
"pressure_tendency": self.dhmz_data.get_data(SENSOR_TYPES["pressure_tendency"][4]) + " hPa",
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Logger: homeassistant.components.weather
Source: components/weather/init.py:308
Integration: Weather (documentation, issues)
First occurred: 11:34:29 AM (2 occurrences)
Last logged: 11:34:29 AM

custom_components.dhmz.weather::DhmzWeather is overriding deprecated methods on an instance of WeatherEntity, this is not valid and will be unsupported from Home Assistant 2023.1. Please report it to the custom integration author.
custom_components.eko_karta_zagreb.weather::EkoKartaZagrebWeather is overriding deprecated methods on an instance of WeatherEntity, this is not valid and will be unsupported from Home Assistant 2023.1. Please report it to the custom integration author.

Logger: custom_components.dhmz.weather
Source: custom_components/dhmz/weather.py:123
Integration: dhmz
First occurred: 11:34:30 AM (1 occurrences)
Last logged: 11:34:30 AM

Unknown DHMZ weather symbol: None

  1. (also for other sensors - wind, pressure etc)
    Logger: custom_components.dhmz.weather
    Source: custom_components/dhmz/weather.py:223
    Integration: dhmz
    First occurred: 11:34:33 AM (1 occurrences)
    Last logged: 11:34:33 AM

Humidity - value not float:

Weather Card

Čini se da je weather card depricated sa novom verzijom Home Assistanta?

image

Error in log file

Hi,

I'm getting this error in my log file every now and then:

This error originated from a custom integration.

Logger: custom_components.dhmz.sensor
Source: custom_components/dhmz/sensor.py:207
Integration: dhmz
First occurred: 12:18:22 (1 occurrences)
Last logged: 12:18:22

LXML PARSE error: expected '>', line 694, column 23 as position: (694, 23), offset: 22, line: 694

Thanks for this great integration!
Robert

No "version" key

Home Assistant 2021.3.0

Log file says:
No 'version' key in the manifest file for custom integration 'dhmz'. This will not be allowed in a future version of Home Assistant. Please report this to the maintainer of 'dhmz'

Type Error - Undefined

Home assistant version 0.113 - 0.115

Logger: frontend.js.latest.202009171
Source: components/system_log/init.py:193
First occurred: 11:37:33 AM (242 occurrences)
Last logged: 11:40:53 AM

https://xxx.xxx.xxx.xxx:8123/local/dhmz-weather-card.js:248:47 Uncaught TypeError: Cannot read property 'forecast' of undefined
https://xxx.xxx.xxx.xxx:8123/local/dhmz-weather-card.js:248:20 TypeError: this.weatherObj.attributes is undefined
https://xxx.xxx.xxx.xxx:8123/frontend_latest/chunk.d9cbf2fe4e32a009641f.js:2:69001 TypeError: s._view is undefined
https://xxx.xxx.xxx.xxx:8123/local/dhmz-weather-card.js:248:18 TypeError: this.weatherObj.attributes is undefined

Pressure_tendency error

Home assistant 0.115.3

3 errors in new version.

ERROR 1:

Logger: homeassistant.components.weather
Source: custom_components/dhmz/weather.py:260
Integration: Weather (documentation, issues)
First occurred: 5:58:44 PM (1 occurrences)
Last logged: 5:58:44 PM
Error while setting up dhmz platform for weather

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 193, in _async_setup_platform
await asyncio.shield(task)
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/dhmz/weather.py", line 124, in setup_platform
add_entities([DhmzWeather(probe, name)], True)
File "/config/custom_components/dhmz/weather.py", line 134, in init
self._state = self.format_condition(self.dhmz_data.get_data(SENSOR_TYPES["weather_symbol"][4]))
File "/config/custom_components/dhmz/weather.py", line 260, in format_condition
return [
IndexError: list index out of range

ERROR 2:

Logger: homeassistant.components.sensor
Source: custom_components/dhmz/sensor.py:185
Integration: Sensor (documentation, issues)
First occurred: 5:59:06 PM (1 occurrences)
Last logged: 5:59:06 PM
Error while setting up dhmz platform for sensor

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 201, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 310, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 481, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 522, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 296, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 323, in _async_write_ha_state
attr.update(self.device_state_attributes or {})
File "/config/custom_components/dhmz/sensor.py", line 185, in device_state_attributes
ret["pressure_tendency"] = self.probe.get_data(SENSOR_TYPES["pressure_tendency"][4]) + " hPa"
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Those above causes following ERROR 3:

2020-09-25 18:01:08 ERROR (MainThread) [frontend.js.latest.202009182] https://[redacted]:8123/local/dhmz-weather-card.js:244:45 Uncaught TypeError: Cannot read property 'forecast' of undefined

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.