RedAlert
Israeli Red Alert Service for Home Assistant
Install / Use
/learn @idodov/RedAlertREADME
Red Alerts Israel
Not Official Pikud Ha-Oref
Simple rocket-alert monitoring for Home Assistant via AppDaemon
Red Alerts Israel is an AppDaemon application for Home Assistant that connects to the official Israeli Home Front Command (Pikud HaOref) API. It fetches real-time "Tzeva Adom" rocket alerts and other hazards, making this information available via easy-to-use Home Assistant sensors.
This script monitors various hazards signaled by PIKUD HA-OREF, including missile/rocket fire, unauthorized aircraft, seismic activity, tsunami, terrorist incursions, chemical emergencies, and more. Upon receiving an alert, the specific threat type is indicated, for example, ירי רקטות וטילים for rocket and missile fire.
The application is designed for reliability and persistence, offering features like archiving alert details, state persistence via JSON backup, triggering Home Assistant native events, publishing messages via MQTT, and providing detailed sensor attributes for creating derived sensors and advanced automations.
Key Features
- Polls the official Israeli Home Front Command API every few seconds for live alerts.
- Creates dedicated Home Assistant entities: main binary sensors, a text helper, a test boolean, and three detailed history sensors.
- Offers flexible alert notification publishing via MQTT and native Home Assistant events triggered by new alert payloads.
- Saves alert history (TXT, CSV) and the last active state (JSON) for persistence across restarts (optional).
- Generates GeoJSON files for visualizing active and historical alert locations on the Home Assistant map (optional).
- Provides specific binary sensors to indicate if an alert affects your configured cities or if it's a special "Pre-Alert" type.
- Tracks the history of distinct alert events within a configurable time window.
- Generates pre-formatted messages suitable for platforms like WhatsApp and Telegram based on cumulative window data.
Entities Created
The script creates several Home Assistant entities, using your configured sensor_name as the base name (default: red_alert):
binary_sensor.YOUR_SENSOR_NAME: Indicates if any alert is currently active nationwide. This sensor staysonfor the duration of the configuredtimerafter the last detected alert activity in a sequence.binary_sensor.YOUR_SENSOR_NAME_city: Indicates ifbinary_sensor.YOUR_SENSOR_NAMEisonand the alert window includes one of the specific cities/areas you configured incity_names.binary_sensor.YOUR_SENSOR_NAME_pre_alert: Indicates if a pre alert is currently active nationwide. This sensor turnson.binary_sensor.YOUR_SENSOR_NAME_city_pre_alert: Indicates if a pre alert alert is currently active and affects one of your configuredcity_names. This sensor turnsononly when an pre alert is received and processed AND the alert window includes one of your configuredcity_names.binary_sensor.YOUR_SENSOR_NAME_active_alert: Indicates if an alert with a category other than pre alert is currently active nationwide. This sensor turnson.binary_sensor.YOUR_SENSOR_NAME_city_active_alert: Indicates if an alert with a category other pre alert is currently active and affects one of your configuredcity_names. This sensor turnsonwhen a pre alert is received and processed AND the alert window includes one of your configuredcity_names.input_text.YOUR_SENSOR_NAME: Displays a summary of the latest alert payload received during an active alert window.input_boolean.YOUR_SENSOR_NAME_test: Allows manual triggering of a fictitious test alert sequence.
Three additional history sensors track distinct alert events that occurred within the configured hours_to_show timeframe (after applying timer-based deduplication):
sensor.YOUR_SENSOR_NAME_history_cities: State is the count, attributes list unique cities alerted in the history window.sensor.YOUR_SENSOR_NAME_history_list: State is the count, attributes list each distinct alert event entry in the history window.sensor.YOUR_SENSOR_NAME_history_group: State is the count, attributes group distinct alert events by title, area, and city in the history window.
Binary Sensor States (binary_sensor.YOUR_SENSOR_NAME, _city, _pre_alert, _city_pre_alert, _active_alert, _city_active_alert)
All six binary sensors are controlled by the script's polling and reset logic.
-
When a new alert payload is received from the API:
binary_sensor.YOUR_SENSOR_NAMEturnson(if not already) and its internaltimeris reset.binary_sensor.YOUR_SENSOR_NAME_cityturnsonif any of the accumulated cities in the current alert window match your configuredcity_names, otherwise it staysoff.- If the
catvalue in the latest incoming alert payload is13:binary_sensor.YOUR_SENSOR_NAME_pre_alertturnson.binary_sensor.YOUR_SENSOR_NAME_city_pre_alertturnsonif thebinary_sensor.YOUR_SENSOR_NAME_citysensor ison(i.e., if configured cities are affected), otherwise it turnsoff.binary_sensor.YOUR_SENSOR_NAME_active_alertturnsoff.binary_sensor.YOUR_SENSOR_NAME_city_active_alertturnsoff.
- If the
catvalue in the latest incoming alert payload is not13(e.g.,cat=1for rockets, which is the case for test alerts):binary_sensor.YOUR_SENSOR_NAME_pre_alertturnsoff.binary_sensor.YOUR_SENSOR_NAME_city_pre_alertturnsoff.binary_sensor.YOUR_SENSOR_NAME_active_alertturnson.binary_sensor.YOUR_SENSOR_NAME_city_active_alertturnsonif thebinary_sensor.YOUR_SENSOR_NAME_citysensor ison, otherwise it turnsoff.
-
When the alert timer expires and confirms no active alerts are pending:
- All six binary sensors (
_main,_city,_pre_alert,_city_pre_alert,_active_alert,_city_active_alert) are explicitly set tooff.
- All six binary sensors (
-
On Script Initialization/Restart:
- All six binary sensors are initialized to
off.
- All six binary sensors are initialized to
Shared Binary Sensor Attributes
When any of the six binary sensors are updated, they receive the same set of attributes. These attributes reflect the state and accumulated information for the current alert window since binary_sensor.YOUR_SENSOR_NAME last turned on. When binary_sensor.YOUR_SENSOR_NAME is off, they show default/empty values or the prev_* values from the window that just ended, providing context about the last alert incident.
| Attribute name | Description | Example |
| :------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------- |
| active_now | true when binary_sensor.YOUR_SENSOR_NAME is on, false when off. Mirrors the main sensor state. | false |
| script_status | The operational status of the AppDaemon script (initializing, running, error, terminated). Useful for monitoring the script itself. | running |
| id | Unique ID of the latest alert payload received during the current window. | 1721993400123456 |
| cat | Category number (0-14) of the latest alert payload. Corresponds to alert type (e.g., 1 for rockets, 13 for special update). | 1 |
| title | Title/Type of the latest alert payload (e.g., "ירי רקטות וטילים"). | ירי רקטות וטילים |
| desc | Recommended action description from the latest alert payload (e.g., "היכנסו למרחב המוגן ושהו בו 10 דקות"). | היכנסו למרחב המוגן ושהו בו 10 דקות |
| special_update | true if the cat of the latest alert payload is 13, false otherwise. This attribute mirrors the state logic of the *_pre_alert sensors. | false |
| areas | Comma-separated string of all areas affected by any payload within the current active window. | גוש דן, קו העימות |
| cities | A sorted list of all unique original city names affected by any payload within the current active window. | ['אור יהודה', 'תל אביב - מרכז העיר'] |
| data | Comma-separated string of all unique original city names affected during the current active window. May be truncated if very long. |
