Skip to content

amitfin/oref_alert

Repository files navigation

Oref Alert

HACS Badge

GitHub Release

Download Analytics

Project Maintenance

Hebrew demos of the installation, configuration and usage can be found here: part1, part2, part3. A blog post with Hebrew instructions can be found here. A blog post with Russian instructions can be found here.

The integration provides binary_sensor.oref_alert which turns on when an alert is reported by the Israeli National Emergency Portal (Pikud Haoref). The sensor monitors the alerts in the user selected areas. An alert is considered active for a certain period of time as configured by the user (10 minutes by default). The integration is installed and configured via the user interface. There is no YAML or templates involved.

Install

HACS is the preferred and easier way to install the component. When HACS is installed, the integration can be installed using this My button:

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

Otherwise, download oref_alert.zip from the latest release, extract and copy the content under custom_components directory.

Home Assistant restart is required once the integration files are copied (either by HACS or manually).

The integration should also be added to the configuration. This can be done via this My button:

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

The setup identifies the area according to the Home location in the Zones settings (the latitude and longitude coordinates). If the detection fails, the user is asked to select the area manually.

Once the component is installed, it's possible to control additional parameters using the Configure dialog which can be accessed via this My button:

Open your Home Assistant instance and show an integration.

There are 5 configuration fields:

  1. Selected areas: list of areas to monitor. It's also possible to select a district (מחוז) and all-areas (כל האזורים) for cities with sub-areas.
  2. Max age of an alert: this is the alert's active time period (in minutes). The default is 10 minutes.
  3. Update frequency: the time to wait between updates of the sensor (in seconds). The default is 2 seconds.
  4. On icon: the icon to be used when there are active alerts in one of the selected areas. This is the icon which is displayed when the state of the binary sensor is "on".
  5. Off icon: the icon to be used when the state of the binary sensor is "off".

All Areas Sensor

binary_sensor.oref_alert_all_areas is an additional sensor monitoring any active alert in the country. The sensor is on when there is one or more active alerts in Israel.

Additional Sensors

It's possible to create additional sensors using the service oref_alert.add_sensor. The service can be accessed via this My button:

Open your Home Assistant instance and show your service developer tools with a specific service selected.

The selected areas of an additional sensor can be different (non overlapping) than the primary sensor. Additional sensors can be re-added (with the same name) for overriding their configuration (there is no edit page).

The service oref_alert.remove_sensor can be used for deleting an additional sensor. The service can be accessed via this My button:

Open your Home Assistant instance and show your service developer tools with a specific service selected.

Note: additional sensors created before v2.2.0 use a different implementation. It's better to delete such entities and to create new sensors using the new functionality (old sensors are not broken and can be used).

Additional Attributes

All sensors have the following extra attributes:

  1. Areas: the list of areas provided by the user.
  2. Alert max age: as configured by the user.
  3. Selected areas active alerts: when the sensor is on, the alerts are listed here.
  4. Selected areas alerts: active and inactive alerts in the selected areas.
  5. Country active alerts: all active alerts in Israel.
  6. Country alerts: all alerts in Israel.

Time To Shelter Sensors

The integration creates an additional set of sensors which monitor the time to shelter for a specific area. The ID of the entity is similar to the corresponding binary sensor, with the suffix of _time_to_shelter. For example, sensor.oref_alert_time_to_shelter. When there is a new alert in the area, the state of the sensor is set according to the instructions of Pikud Haoref for the selected area (e.g. 90 seconds in the middle of Israel). The state of the sensor decrements as time passes, and it becomes unknown once it reaches -60 seconds (one minute past due). The sensor has the following extra attributes:

  1. Area: the name of the area.
  2. Time to shelter: as provided by Pikud Haoref for the selected area (constant value).
  3. Alert: the active alert (when there is such).

Note: this sensor is not created when the configuration contains multiple areas or groups (e.g. cities with multiple areas or districts). It's possible in such a case to create an additional sensor configuration for the specific area of interest by using the service oref_alert.add_sensor.

Alert End Time Sensors

The integration creates an additional set of sensors which monitor the time to the end of the alert for a specific area. The ID of the entity is similar to the corresponding binary sensor, with the suffix of _end_time. For example, sensor.oref_alert_end_time. When there is a new alert in the area, the state of the sensor is set according to the Alert max age as configured by the user (default is 10 minutes). The state of the sensor decrements as time passes, and it becomes unknown once the alert is off. The sensor has the following extra attributes:

  1. Area: the name of the area.
  2. Alert max age: as configured by the user.
  3. Alert: the active alert (when there is such).

Note: this sensor is not created when the configuration contains multiple areas or groups (e.g. cities with multiple areas or districts). It's possible in such a case to create an additional sensor configuration for the specific area of interest by using the service oref_alert.add_sensor.

Geo Location Entities

Geo-location entities are created for every active alert in Israel (regardless of the selected areas). These entities exist while the corresponding alert is active (10 minutes by default). The map card can be used to present the entities on a map. oref_alert should be added to geo_location_sources, and auto_fit should be set to true:

type: map
entities: []
auto_fit: true
geo_location_sources:
  - oref_alert

This will create a map presenting all active alerts in Israel:

image

(Below you can find a another explanation on how to add a textual element for the data.)

Synthetic Alert

Synthetic alerts are useful for testing purposes. The service oref_alert.synthetic_alert can be used to create a synthetic alert. The service can be accessed via this My button:

Open your Home Assistant instance and show your service developer tools with a specific service selected.

Note: a synthetic alert is an additional alert. It doesn't override or hide any other alert. A synthetic alert disappears after the amount of seconds supplied to the custom service. This is different from a regular alert which disappears only after 24 hours.

Usages

The basic usage is to trigger an automation rule when the binary sensor is turning on. Some ideas for the actions section can be: play a song (can be less stressful when choosing the right song and setting the volume properly), open the lights and TV in the shelter, etc'. It's also possible to trigger an alert when the sensor is turning off for getting an indication when it's safe to get out of the shelter.

Below are a few more examples:

Coloring State Icons

type: entities
entities:
  - entity: binary_sensor.oref_alert
    card_mod:
      style: |
        :host {
          --state-binary_sensor-on-color: red;
          --state-binary_sensor-off-color: green;
          }

image

Note that it depends on the installation of card-mod lovelace custom component.

Presenting Active Alerts in Israel

Here is a simple markdown card for presenting all active alerts:

type: markdown
content: >-
  {% set icons = {
    1: "rocket-launch",
    2: "airplane-alert",
    3: "chemical-weapon",
    4: "alert",
    5: "firework",
    6: "firework",
    7: "earth",
    8: "earth",
    9: "nuke",
    10: "shield-home",
    11: "home-flood",
    12: "biohazard",
    13: "update",
    14: "flash-alert",
    15: "alert-circle-check",
    16: "alert-circle-check",
    17: "alert-circle-check",
    18: "alert-circle-check",
    19: "alert-circle-check",
    20: "alert-circle-check",
    21: "alert-circle-check",
    22: "alert-circle-check",
  } %}
  {% for alert in (state_attr('binary_sensor.oref_alert', 'country_active_alerts') or []) %}
    <p>
      <font color="red"><ha-icon icon="mdi:{{ icons.get(alert['category'], 'alert') }}"></ha-icon></font>
      {{ alert['data'] }}
      [{{ alert['title'] }}]
      ({{ alert['alertDate'] | as_timestamp | timestamp_custom('%H:%M:%S') }})
    </p>
  {% endfor %}
card_mod:
  style: |
    ha-card {
      direction: rtl;
    }

(The card_mod section at the bottom is only required when the language is English. It forces RTL for this element. Note that it depends on the installation of card-mod lovelace custom component.)

image

Mobile Notifications

Here is an advanced usage for getting mobile notifications on any alert in the country:

alias: Oref Alert Country Notifications
id: oref_alert_country_notifications
trigger:
  - platform: state
    entity_id: binary_sensor.oref_alert
    attribute: country_active_alerts
action:
  - variables:
      current: "{{ state_attr('binary_sensor.oref_alert', 'country_active_alerts') | map(attribute='data') | list }}"
      previous: "{{ trigger.from_state.attributes.country_active_alerts | map(attribute='data') | list }}"
      alerts: "{{ current | reject('in', previous) | unique | sort | list }}"
  - condition: "{{ alerts | length > 0 }}"
  - service: notify.mobile_app_amits_iphone
    data:
      message: "התרעות פיקוד העורף: {{ alerts | join(' | ') }}"
mode: queued

Time To Shelter Countdown

Here is another advanced usage for counting down (every 5 seconds) the time to shelter:

alias: Oref Alert Time To Shelter Countdown
id: oref_alert_time_to_shelter_countdown
trigger:
  - platform: state
    entity_id: sensor.oref_alert_time_to_shelter
action:
  - variables:
      time_to_shelter: "{{ states('sensor.oref_alert_time_to_shelter') | int(-1) }}"
  - condition: "{{ time_to_shelter >= 0 and time_to_shelter % 5 == 0}}"
  - service: tts.google_translate_say
    data:
      entity_id: media_player.shelter_speaker
      language: iw
      message: "{{ time_to_shelter }}"
mode: queued

Contributions are welcome!

If you want to contribute to this please read the Contribution guidelines

Acknowledgements

  • Thanks to Gugulator for the Russian translation as well as many great ideas during our brainstorming sessions.