Hebrew video of the installation, configuration and usage 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.
HACS is the preferred and easier way to install the component. When HACS is installed, the integration can be installed using this My button:
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:
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:
There are 5 configuration fields:
- Selected areas: list of areas to monitor. It's also possible to select a district (מחוז) and all-areas (כל האזורים) for cities with sub-areas.
- Active duration of an alert: this is the alert's active time period (in minutes). The default is 10 minutes.
- Update frequency: the time to wait between updates of the sensor (in seconds). The default is 2 seconds.
- 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".
- Off icon: the icon to be used when the state of the binary sensor is "off".
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.
It's possible to create additional sensors using the service oref_alert.add_sensor
. The service can be accessed via this My button:
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:
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).
All sensors have the following extra attributes:
Areas
: the list of areas provided by the user.Alert active duration
: as configured by the user.Selected areas active alerts
: when the sensor ison
, the alerts are listed here.Selected areas alerts
: active and inactive alerts in the selected areas.Country active alerts
: all active alerts in Israel.Country alerts
: all alerts in Israel.
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:
Area
: the name of the area.Time to shelter
: as provided by Pikud Haoref for the selected area (constant value).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
.
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 active duration
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:
Area
: the name of the area.Alert active duration
: as configured by the user.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 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 state of the entity is the distance in kilometers from HA home's coordinates. In addition, each entity has the following attributes:
friendly_name
: alert's arealatitude
longitude
home_distance
: same as the state, but an integer type and not a string (state is always a string)title
: alert's descriptiondate
category
: integer with alert's categoryicon
: Material icon ("mdi:xxx") based on the categoryemoji
: based on the category
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:
(Below you can find a another explanation on how to add a textual element for the data.)
A new event is fired on HA bus for any new alert. Here is an example of such an event:
event_type: oref_alert_event
data:
area: תל אביב - מרכז העיר
home_distance: 9.7
latitude: 32.0798
longitude: 34.7772
category: 1
title: ירי רקטות וטילים
icon: mdi:rocket-launch
emoji: 🚀
In the Mobile Notifications: Detailed Alerts section there is an example for usage of this event.
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:
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.
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:
type: entities
entities:
- entity: binary_sensor.oref_alert
card_mod:
style: |
:host {
--state-binary_sensor-on-color: red;
--state-binary_sensor-off-color: green;
}
Note that it depends on the installation of card-mod lovelace custom component.
Here is a markdown card for presenting all active alerts sorted by their distance from HA's home coordinates (the list of categories is based on this file):
type: markdown
content: >-
{% for alert in states.geo_location |
selectattr('entity_id', 'in', integration_entities('oref_alert')) |
sort(attribute='attributes.home_distance') %}
<p>
<font color="red"><ha-icon icon="{{ alert.attributes.icon }}"></ha-icon></font>
<a href="https://maps.google.com/?q={{ alert.attributes.latitude }},{{ alert.attributes.longitude }}">{{ alert.name }}</a>
[{{ alert.state | int }} ק״מ]
({{ alert.attributes.date | as_timestamp | timestamp_custom('%H:%M') }})
</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 requires the installation of card-mod lovelace custom component.)
Here is an automation rule for getting mobile notifications for new alerts:
alias: Oref Alert Country Notifications
id: oref_alert_country_notifications
triggers:
- trigger: state
entity_id: binary_sensor.oref_alert
attribute: country_active_alerts
actions:
- variables:
current: "{{ trigger.to_state.attributes.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 }}"
- action: notify.mobile_app_amits_iphone
data:
title: התרעות פיקוד העורף
message: "{{ alerts | join(' | ') }}"
mode: queued
This is a different approach where only alerts which are either within 30km from home or 5km from Amit's current location generate notifications. However, each notification has additional information (and being sent separately):
alias: Oref Alert Country Notifications Details
id: oref_alert_country_notifications_details
triggers:
- trigger: event
event_type: oref_alert_event
actions:
- condition: or
conditions:
- condition: template
value_template: "{{ trigger.event.data.home_distance < 30 }}"
- condition: template
value_template: "{{ distance('device_tracker.amits_iphone', trigger.event.data.latitude, trigger.event.data.longitude) < 5 }}"
- action: notify.mobile_app_amits_iphone
data:
title: התרעות פיקוד העורף
message: "{{ trigger.event.data.emoji }} {{ trigger.event.data.area }} [{{ trigger.event.data.title }}] ({{ trigger.event.data.home_distance | int }} ק״מ)"
mode: queued
It's possible to set a custom sound for a specific mobile app push notification. Here is an iOS example:
action: notify.mobile_app_amits_iphone
data:
title: התרעות פיקוד העורף
message: <<omitted-in-example>>
data:
push:
sound: US-EN-Morgan-Freeman-Vacate-The-Premises.wav
Additional information (for Android and iOS) can be found here.
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
triggers:
- trigger: state
entity_id: sensor.oref_alert_time_to_shelter
actions:
- variables:
time_to_shelter: "{{ states('sensor.oref_alert_time_to_shelter') | int(-1) }}"
- condition: "{{ time_to_shelter >= 0 and time_to_shelter % 5 == 0}}"
- action: tts.google_translate_say
data:
entity_id: media_player.shelter_speaker
language: iw
message: "{{ time_to_shelter }}"
mode: queued
If you want to contribute to this please read the Contribution guidelines
- Thanks to Gugulator for the Russian translation as well as many great ideas during our brainstorming sessions.