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
assistant geofisica home homeassistant ingv terremoti vulcanologia

INGV Earthquakes

hacs Validate

GitHub latest release ![GitHub Release Date] Maintenancebadge GitHub issuesbadge

Websitebadge Forum telegrambadge facebookbadge

Don't buy me a coffee

Instructions on how to integrate the INGV Earthquakes feed into Home Assistant.

All credit goes to Malte Franken @exxamalte.

The ingv_centro_nazionale_terremoti integration lets you use a QuakeML feeds provided by the Italian Istituto Nazionale di Geofisica e Vulcanologia with information about seismic events like earthquakes on the Italian Peninsula. It retrieves incidents from a feed and shows information of those incidents filtered by distance to Home Assistant's location.

Entities are generated, updated and removed automatically with each update from the feed. Each entity defines latitude and longitude and will be shown on the default map automatically, or on a map card by defining the source ingv_centro_nazionale_terremoti. The distance in kilometers is available as the state of each entity.

The data is updated every 5 minutes and retrieve all events from the last 24 hours by default.

The material used by this integration is provided under the [Creative Commons Attribution 4.0 International](http://creativecommons.org/licenses/by/4.0/). It has only been modified for the purpose of presenting the material in Home Assistant. Please refer to the [creator's disclaimer notice](hhttp://terremoti.ingv.it/en/webservices_and_software) and [Terms of service](http://www.fdsn.org/webservices/) for more information. We acknowledge the INGV and ISIDe Working Group at National Earthquake Observatory project and its sponsors by the Italian Presidenza del Consiglio dei Ministri, Dipartimento della Protezione Civile, for providing data/images used in this integration.

How to install

  1. Install via HACS or you can copy the entire ingv_centro_nazionale_terremoti folder into custom_components folder in your root directory. You will need to create the dir custom_components if this is your first custom component.
  2. Restart Home Assistant.

Configuration

Config flow user interface

To configure this integration go to: Configurations -> Integrations -> ADD INTEGRATIONS button, search for INGV and configure the component.

You can also use following My Home Assistant link

Open your Home Assistant instance and start setting up a new integration.

Config yaml

  1. Add the following lines to your configuration.yaml:

    # Example configuration.yaml entry
    ingv_centro_nazionale_terremoti:
        location: "Home"
  2. Save it.

  3. Restart Home Assistant.

NOTE: In an environment other than HassOS, you will probably need to install the dependencies manually. Activate Python environment Home Assistant is running in and use following command:

python3 -m pip install aio_quakeml_ingv_centro_nazionale_terremoti_client

CONFIGURATION VARIABLES

Variables Type Requirement Default Description
location string optional Location name defined in your configuration.yaml Location name.
latitude string optional Latitude defined in your configuration.yaml Latitude of the coordinates around which events are considered.
longitude string optional Longitude defined in your configuration. yaml Longitude of the coordinates around which events are considered.
radius float optional 50.0 The distance in kilometers around Home Assistant's coordinates in which seismic events are included.
minimum_magnitude float optional 3.0 The minimum magnitude of an earthquake to be included.
scan_interval int optional 300 The time in seconds for each update.
start_time int optional 24 The start-time delta in hours. (e.g., last 18 hours)

State Attributes

The following state attributes are available for each entity in addition to the standard ones:

Attribute Description
latitude Latitude of the earthquake.
longitude Longitude of the earthquake.
source ingv_centro_nazionale_terremoti to be used in conjunction with geo_location automation trigger.
region Textual description of named geographic region near to the event.
magnitude Reported magnitude of the earthquake.
depth The depth of the quake in km.
status The Evaluation Status of the quake (preliminary, confirmed, reviewed, final, rejected).
mode The Evaluation Mode of the quake (manual or automatic).
publication_date Date and time when this event occurred.
event_id Return the short id used in the feed to identify the earthquake in the feed.
image_url URL for a map not provided in the feed that marks the location of the event. This could for example be used in notifications. Images are only available for magnitude >= 3.

geo_location

Sensor

This integration automatically creates a sensor that shows how many entities are currently managed by this integration. In addition to that the sensor has some useful attributes that indicate the currentness of the data retrieved from the feed.

Attribute Description
status Status of last update from the feed ("OK" or "ERROR").
last update Timestamp of the last update from the feed.
last update successful Timestamp of the last successful update from the feed.
last timestamp Timestamp of the latest entry from the feed.
created Number of entities that were created during last update (optional).
updated Number of entities that were updated during last update (optional).
removed Number of entities that were removed during last update (optional).

sensor

Full Configuration

# Example configuration.yaml entry
ingv_centro_nazionale_terremoti:
  location: "Home"
  latitude: 41.89
  longitude: 12.51
  radius: 100
  minimum_magnitude: 2.0
  scan_interval: 300
  start_time: 24

Example Zone

zone:
  - name: geoalert
    latitude: !secret latitude_home
    longitude: !secret longitude_home
    radius: 100000 #The radius of the zone in meters
    passive: true

Example Automation

automation:
  alias: INGV Quakes Notification Send
  description: ''
  trigger:
    - platform: geo_location
      source: ingv_centro_nazionale_terremoti
      zone: zone.geoalert
      event: enter
  condition: []
  action:
    - service: notify.discord
      data:
        title: New INGV Quakes
        message: |
          Rilevato terremoto a una distanza di {{trigger.to_state.state}} Km da
          casa. Magnitudo: {{trigger.to_state.attributes.magnitude}}  Epicentro:
          {{trigger.to_state.attributes.region}} Profondità:
          {{trigger.to_state.attributes.depth}} km. {% set data_utc =
          trigger.to_state.attributes.publication_date %}
          {{as_timestamp(data_utc)|timestamp_custom('%H:%M:%S - %d/%m/%Y')}}
  mode: queued

Example Lovelace Map Card

type: map
entities:
  - entity: person.YUOR_PERSON
geo_location_sources:
  - ingv_centro_nazionale_terremoti
dark_mode: true
default_zoom: 8
aspect_ratio: '16:9'
hours_to_show: 72

Other information

My Package

type: markdown
title: ''
content: >-
  {% set ingv_entities = integration_entities("ingv_centro_nazionale_terremoti") %}
  {% set entityid = ingv_entities | select('match','geo_location') | max | default(false) %}

  {# START ->> if geo_location entities exsist #}
  {% if entityid %} 
  {% set alert_type = {0:'info', 1:'success', 2:'warning', 3:'warning', 4:'error'} %}
  {% set code = {0:'White', 1:'Green', 2:'Gold', 3:'Orange', 4:'Red'} %} 
  {% set url = "http://shakemap.rm.ingv.it/shake4/data/{}/current/products/{}.jpg" %}
  {% set url2 = "http://shakemap.ingv.it/shake4/data/{}/current/products/{}.jpg" %} 
  {% set openmap = "https://www.openstreetmap.org/?mlat={}&mlon={}#map=12/{}/{}" %}
  {% set id = state_attr(entityid, 'event_id') %} 
  {% set magnitudo = state_attr(entityid, 'magnitude')|float(default=0) %} 
  {% set lat = state_attr(entityid, 'latitude') %} 
  {% set long = state_attr(entityid, 'longitude') %} 
  {% set utc = as_timestamp(state_attr(entityid, 'publication_date'),0) %} 
  {% set depth = state_attr(entityid, 'depth')|default(none) %}
  {# MACRO MAGNITUDE LEVEL #}
  {% macro mag(m) -%}
    {% if 0 <= m < 2 %}0{% elif 2 <= m < 3 %}1{% elif 3 <= m < 4 %}2
    {% elif 4 <= m < 6 %}3{% else %}4{% endif %}
  {% endmacro %}
  {% set level = mag(magnitudo)|int(0) %}
  {% set alert = alert_type[level] %}
  {% set color = code[level] %}
  {# MACRO BOLD TEXT FORMAT and COLOR according to the warning LEVEL #}
  {%- macro form(data) -%}
    <font color="{{color}}">**{{data}}**</font>
  {%- endmacro -%}
  ___

  <ha-alert title="TERREMOTO 
  {{ utc|timestamp_custom('%H:%M:%S del %d-%m-%Y') 
  if utc is not none else 0 }}" alert-type={{alert}}>

  Un terremoto di magnitudo {{ form(magnitudo) }}
  è avvenuto nella zona: 
  [{{ state_attr(entityid, 'region') }}]({{ openmap.format(lat,long,lat,long) }})
  a {{ form(states(entityid)) }} km da casa,
  con coordinate epicentrali {{ lat }}, {{ long }},
  ad una profondità di {{ form(depth) }} Km.

  {# PERSON #}
  {% set state_dict = {'home': 'casa', 'not_home': 'fuori casa', 'unknown': '❓'} %} 
  {% for person in expand(states.person) %} 
  {% if 'latitude' in person.attributes and person.attributes.latitude is not none %} 
  {% set distanza = distance(lat|default(0), long|default(0), person.entity_id|default(0)) %}
  {{ "📍 {} ({}) a circa {} km dall'epicentro.".format(
    person.name|upper, state_dict.get(person.state, person.state), distanza|round(1, default=0)
    ) }} 
  {% else %}
  {{ "📍 {} ({})".format(person.name|upper, state_dict.get(person.state, person.state)) }} 
  {% endif %} 
  {% endfor %}

  [INGV](http://terremoti.ingv.it/) [Hai Sentito Il Terremoto?](http://www.haisentitoilterremoto.it/) 

  </ha-alert>

  {# IMAGE AND LINK #}
  {% if magnitudo >= 3 %}

  [Intensity]({{url.format(id,'intensity')}}) ~ 
  [PGA]({{url.format(id,'pga')}}) ~ [PGV]({{url.format(id,'pgv')}}) ~ 
  [PSA0]({{url.format(id,'psa0p3')}}) ~ [PSA1]({{url.format(id,'psa1p0')}}) ~ 
  [HSIT](http://eventi.haisentitoilterremoto.it/{{id}}/{{id}}_mcs.jpg)

  {% if is_state('binary_sensor.download_file', 'on') %}

  <a href="http://shakemap.rm.ingv.it/shake4/view.html?eventid={{id}}"><img
  src="https://github.com/caiosweet/Home-Assistant-custom-components-INGV/raw/main/local/hassiohelp/downloads/lastquake.jpg?t='{{now().timestamp()}}'"></a>
  {% else %} 
  <a  href="http://shakemap.rm.ingv.it/shake4/view.html?eventid={{id}}"><img
  src="http://shakemap.rm.ingv.it/shake4/data/{{id}}/current/products/pga.jpg"></a>
  {% endif %} {% endif %}

  {# SENSOR STATUS #}
  {% else %}

  {% for entity in ingv_entities %}
  <ha-alert title="{{ state_attr(entity, 'friendly_name') }}" alert-type="info">
  {{ state_attr(entity, 'status')|slugify(separator=" ") }} - {{ states(entity) }}
  </ha-alert>
  {% endfor %}
  {% endif %}

Markdown Card

Trademark Legal Notices

All product names, trademarks and registered trademarks in the images in this repository, are property of their respective owners. All images in this repository are used by the author for identification purposes only. The use of these names, trademarks and brands appearing in these image files, do not imply endorsement.