-
-
Save orpolaczek/5d3e6388f30c5b71df83dabdc237bd18 to your computer and use it in GitHub Desktop.
Oct 2023 - SEE UPDATED VERSION IN THE COMMENTS BELOW | |
Update no. 2 -> see a proper integration build by Amit here:https://github.com/amitfin/oref_alert. It's the way to go | |
# Create a REST sensor (built in) - place the following lines in `sensors.yaml` | |
- platform: rest | |
resource: https://www.oref.org.il/WarningMessages/alert/alerts.json | |
scan_interval: 5 | |
value_template: "{{ value_json.data if value_json is defined else [] }}" | |
headers: | |
Accept: application/json | |
Content-Type: application/json | |
x-requested-with: XMLHttpRequest | |
Referer: https://www.oref.org.il//12481-he/Pakar.aspx | |
# Use a template to generate binary sensors - add this in your configuration.yaml | |
sensor: !include sensors.yaml | |
template: | |
- binary_sensor: | |
- name: "Alert Givatayim" | |
state: "{{ 'גבעתיים' in states('sensor.rest_sensor') or 'רמת גן - מערב' in states('sensor.rest_sensor')}}" | |
- name: "Alert Otef Gaza" | |
state: "{{ 'ניר עם' in states('sensor.rest_sensor') or 'כפר עזה' in states('sensor.rest_sensor') or 'מפלסים' in states('sensor.rest_sensor') }}" |
I Sugguest doing
value_template: "{{ value_json.data if value else [] }}"
Insead for not getting the warning messeges
I Sugguest doing
value_template: "{{ value_json.data if value else [] }}"
Insead for not getting the warning messeges
Great suggestion! I revised.
I'm getting any error, any ideas what I'm going wrong?
Invalid config for [template]: [binary_sensor] is an invalid option for [template]. Check: template->binary_sensor. (See /config/configuration.yaml, line 15).
configuration.yaml
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
# Text to speech
tts:
- platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
# Use a template to generate binary sensors - add this in your configuration.yaml
sensor: !include sensors.yaml
template:
- binary_sensor:
- name: "Alert Givatayim"
state: "{{ 'גבעתיים' in states('sensor.rest_sensor') or 'רמת גן - מערב' in states('sensor.rest_sensor')}}"
- name: "Alert Otef Gaza"
state: "{{ 'ניר עם' in states('sensor.rest_sensor') or 'כפר עזה' in states('sensor.rest_sensor') or 'מפלסים' in states('sensor.rest_sensor') }}"
sensors.yaml
# Create a REST sensor (built in) - place the following lines in `sensors.yaml`
- platform: rest
resource: https://www.oref.org.il/WarningMessages/alert/alerts.json
scan_interval: 5
value_template: "{{ value_json.data if value else [] }}"
headers:
Accept: application/json
Content-Type: application/json
x-requested-with: XMLHttpRequest
Referer: https://www.oref.org.il//12481-he/Pakar.aspx
This solution works great but a few month ago it stops working and I am getting Unknown value on the rest sensor.
Can someone help ?
This solution works great but a few month ago it stops working and I am getting Unknown value on the rest sensor. Can someone help ?
Change the value_template
to be "{{ value_json.data if value_json is defined else [] }}"
@orpolaczek I think this is the best method, maybe you should consider updating the gist
This solution works great but a few month ago it stops working and I am getting Unknown value on the rest sensor. Can someone help ?
Change the
value_template
to be"{{ value_json.data if value_json is defined else [] }}"
@orpolaczek I think this is the best method, maybe you should consider updating the gist
Thank you for that. Updated
Hi,
The rest sensor value is always on [] although in the telegram channel of pikud haoref there are alerts.
Any idea how to fix it ?
Same for me.
Same for me.
Try increasing the refresh interval
I used the rest integration, same thing but easier to extract multiple sensors and I don't need an extra sensor for the list.
rest:
- scan_interval: 10
resource: https://www.oref.org.il/WarningMessages/alert/alerts.json
headers:
Accept: application/json
Content-Type: application/json
x-requested-with: XMLHttpRequest
Referer: https://www.oref.org.il//12481-he/Pakar.aspx
sensor:
- name: 'Oref Alarm'
value_template: '{% set locations = (value_json.data if value_json is defined else []) %}{{ "גבעתיים" in locations or "רמת גן - מערב" in locations}}'
Update over update - Amit has built a proper integration that makes this solution redundant.
Please replatform to use his solution.
I'll leave the server up until the end of the current war and then it'll be deleted.
Stay safe!
==============================
Updating here -
I know many of you see cases where alerts are missed.
I believe it's due to the way Pikud HaOref cache the alerts JSON file.
I've created a server that merges the 'live' alerts from alerts.json
and the historical alerts from GetAlarmsHistory.aspx
and returns one, unified, array of all active alerts in the past 30 seconds. That way you won't miss alerts (maybe only get them in a slight delay).
I'm running this server free of charge. You can use it by adding a 'rest' sensor as follows:
- platform: rest
name: restalert
resource: https://DONT_USE_ME
scan_interval: 2
value_template: "{{ (value_json.active_alerts if value_json is defined else []) | count }}"
json_attributes:
- active_alerts
verify_ssl: false
headers:
Referer: https://www.oref.org.il/
X-Requested-With: XMLHttpRequest
Content-Type: 'application/json'
It will publish a new sensor, with an attribute that contains all active alerts.
Then, you can set a binary sensor either in Hebrew or English (or Russian or Arabic) by adding a binary_sensor:
- name: "Alert Tel-Aviv"
state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('Tel Aviv')}}"
- name: "Alert Bnei-Brak"
state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('בני ברק') }}"
If you want to test it out, set the URL to https://-----
instead of https://r------
and it'll return today's historical alerts
please be mindful and set the refresh interval for test alerts to be 3600 seconds or less. It's the same data.
Rate limit is enforced on the test endpoint to save me from excessive cost :)
I used the rest integration, same thing but easier to extract multiple sensors and I don't need an extra sensor for the list.
rest: - scan_interval: 10 resource: https://www.oref.org.il/WarningMessages/alert/alerts.json headers: Accept: application/json Content-Type: application/json x-requested-with: XMLHttpRequest Referer: https://www.oref.org.il//12481-he/Pakar.aspx sensor: - name: 'Oref Alarm' value_template: '{% set locations = (value_json.data if value_json is defined else []) %}{{ "גבעתיים" in locations or "רמת גן - מערב" in locations}}'
It’s a valid approach.
however - I prefer one sensor with all active alerts, so I can configure more areas down the line. That’s the only benefit over your implementation.
Thanks Or, much appriciated !
I am starting to use your URL.
Update after checking:
I think the state of the sensor.restalert should be the value of the Json and not the alerts count (It will be easier to debug since the data will be visible in the logbook).
Updating here - I know many of you see cases where alerts are missed.
I believe it's due to the way Pikud HaOref cache the alerts JSON file.
I've created a server that merges the 'live' alerts from
alerts.json
and the historical alerts fromGetAlarmsHistory.aspx
and returns one, unified, array of all active alerts in the past 30 seconds. That way you won't miss alerts (maybe only get them in a slight delay).I'm running this server free of charge. You can use it by adding a 'rest' sensor as follows:
- platform: rest name: restalert resource: https://redalert.pci.co.il/get_active_alerts scan_interval: 2 value_template: "{{ (value_json.active_alerts if value_json is defined else []) | count }}" json_attributes: - active_alerts verify_ssl: false headers: Referer: https://www.oref.org.il/ X-Requested-With: XMLHttpRequest Content-Type: 'application/json'It will publish a new sensor, with an attribute that contains all active alerts.
Then, you can set a binary sensor either in Hebrew or English (or Russian or Arabic) by adding a binary_sensor:
- name: "Alert Tel-Aviv" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('Tel Aviv')}}" - name: "Alert Bnei-Brak" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('בני ברק') }}"If you want to test it out, set the URL to
https://redalert.pci.co.il/get_test_alerts
instead ofhttps://redalert.pci.co.il/get_active_alerts
and it'll return today's historical alerts
Thanks Or, much appriciated ! I am starting to use your URL. Update after checking: I think the state of the sensor.restalert should be the value of the Json and not the alerts count (It will be easier to debug since the data will be visible in the logbook).
Updating here - I know many of you see cases where alerts are missed.
I believe it's due to the way Pikud HaOref cache the alerts JSON file.
I've created a server that merges the 'live' alerts fromalerts.json
and the historical alerts fromGetAlarmsHistory.aspx
and returns one, unified, array of all active alerts in the past 30 seconds. That way you won't miss alerts (maybe only get them in a slight delay).
I'm running this server free of charge. You can use it by adding a 'rest' sensor as follows:- platform: rest name: restalert resource: https://redalert.pci.co.il/get_active_alerts scan_interval: 2 value_template: "{{ (value_json.active_alerts if value_json is defined else []) | count }}" json_attributes: - active_alerts verify_ssl: false headers: Referer: https://www.oref.org.il/ X-Requested-With: XMLHttpRequest Content-Type: 'application/json'
It will publish a new sensor, with an attribute that contains all active alerts.
Then, you can set a binary sensor either in Hebrew or English (or Russian or Arabic) by adding a binary_sensor:- name: "Alert Tel-Aviv" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('Tel Aviv')}}" - name: "Alert Bnei-Brak" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('בני ברק') }}"
If you want to test it out, set the URL to
https://redalert.pci.co.il/get_test_alerts
instead ofhttps://redalert.pci.co.il/get_active_alerts
and it'll return today's historical alerts
It's that way on purpose, because all the alerts are exposed under the state attributes.
If you put the entire response in the state itself you'll get a really big state that will be hard to render/read.
Regardless - it's up to you :)
Thanks Or, much appriciated ! I am starting to use your URL. Update after checking: I think the state of the sensor.restalert should be the value of the Json and not the alerts count (It will be easier to debug since the data will be visible in the logbook).
Updating here - I know many of you see cases where alerts are missed.
I believe it's due to the way Pikud HaOref cache the alerts JSON file.
I've created a server that merges the 'live' alerts fromalerts.json
and the historical alerts fromGetAlarmsHistory.aspx
and returns one, unified, array of all active alerts in the past 30 seconds. That way you won't miss alerts (maybe only get them in a slight delay).
I'm running this server free of charge. You can use it by adding a 'rest' sensor as follows:- platform: rest name: restalert resource: https://redalert.pci.co.il/get_active_alerts scan_interval: 2 value_template: "{{ (value_json.active_alerts if value_json is defined else []) | count }}" json_attributes: - active_alerts verify_ssl: false headers: Referer: https://www.oref.org.il/ X-Requested-With: XMLHttpRequest Content-Type: 'application/json'
It will publish a new sensor, with an attribute that contains all active alerts.
Then, you can set a binary sensor either in Hebrew or English (or Russian or Arabic) by adding a binary_sensor:- name: "Alert Tel-Aviv" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('Tel Aviv')}}" - name: "Alert Bnei-Brak" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('בני ברק') }}"
If you want to test it out, set the URL to
https://redalert.pci.co.il/get_test_alerts
instead ofhttps://redalert.pci.co.il/get_active_alerts
and it'll return today's historical alerts
Hi buddy,
please see my update about moving over to Amit's integration. It's the way to go
Thanks Or, much appriciated ! I am starting to use your URL. Update after checking: I think the state of the sensor.restalert should be the value of the Json and not the alerts count (It will be easier to debug since the data will be visible in the logbook).
Updating here - I know many of you see cases where alerts are missed.
I believe it's due to the way Pikud HaOref cache the alerts JSON file.
I've created a server that merges the 'live' alerts fromalerts.json
and the historical alerts fromGetAlarmsHistory.aspx
and returns one, unified, array of all active alerts in the past 30 seconds. That way you won't miss alerts (maybe only get them in a slight delay).
I'm running this server free of charge. You can use it by adding a 'rest' sensor as follows:- platform: rest name: restalert resource: https://redalert.pci.co.il/get_active_alerts scan_interval: 2 value_template: "{{ (value_json.active_alerts if value_json is defined else []) | count }}" json_attributes: - active_alerts verify_ssl: false headers: Referer: https://www.oref.org.il/ X-Requested-With: XMLHttpRequest Content-Type: 'application/json'
It will publish a new sensor, with an attribute that contains all active alerts.
Then, you can set a binary sensor either in Hebrew or English (or Russian or Arabic) by adding a binary_sensor:- name: "Alert Tel-Aviv" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('Tel Aviv')}}" - name: "Alert Bnei-Brak" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('בני ברק') }}"
If you want to test it out, set the URL to
https://redalert.pci.co.il/get_test_alerts
instead ofhttps://redalert.pci.co.il/get_active_alerts
and it'll return today's historical alertsHi buddy, please see my update about moving over to Amit's integration. It's the way to go
Thanks, I have stopped using your server.
BTW, what's the advantage of Amit's integration over the original code in this thread ?
Does Amit's integration create request directly to https://www.oref.org.il/WarningMessages/alert/alerts.json or via another proxy server (like the one you suggested before at redalert.pci.co.il) ?
Thanks Or, much appriciated ! I am starting to use your URL. Update after checking: I think the state of the sensor.restalert should be the value of the Json and not the alerts count (It will be easier to debug since the data will be visible in the logbook).
Updating here - I know many of you see cases where alerts are missed.
I believe it's due to the way Pikud HaOref cache the alerts JSON file.
I've created a server that merges the 'live' alerts fromalerts.json
and the historical alerts fromGetAlarmsHistory.aspx
and returns one, unified, array of all active alerts in the past 30 seconds. That way you won't miss alerts (maybe only get them in a slight delay).
I'm running this server free of charge. You can use it by adding a 'rest' sensor as follows:- platform: rest name: restalert resource: https://redalert.pci.co.il/get_active_alerts scan_interval: 2 value_template: "{{ (value_json.active_alerts if value_json is defined else []) | count }}" json_attributes: - active_alerts verify_ssl: false headers: Referer: https://www.oref.org.il/ X-Requested-With: XMLHttpRequest Content-Type: 'application/json'
It will publish a new sensor, with an attribute that contains all active alerts.
Then, you can set a binary sensor either in Hebrew or English (or Russian or Arabic) by adding a binary_sensor:- name: "Alert Tel-Aviv" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('Tel Aviv')}}" - name: "Alert Bnei-Brak" state: "{{ state_attr('sensor.restalert', 'active_alerts') is search('בני ברק') }}"
If you want to test it out, set the URL to
https://redalert.pci.co.il/get_test_alerts
instead ofhttps://redalert.pci.co.il/get_active_alerts
and it'll return today's historical alertsHi buddy, please see my update about moving over to Amit's integration. It's the way to go
Thanks, I have stopped using your server. BTW, what's the advantage of Amit's integration over the original code in this thread ? Does Amit's integration create request directly to https://www.oref.org.il/WarningMessages/alert/alerts.json or via another proxy server (like the one you suggested before at redalert.pci.co.il) ?
No. you're losing the proxy advantage, but if you have a stable internet connection, even if you missed the alarm from alerts.json
you'll still get it processed from the historical alerts json, so you won't lose alerts.
Example: