Last active
November 19, 2023 11:54
-
-
Save yaronalk/c9ee61b1ff19d9db20dc038a88680e44 to your computer and use it in GitHub Desktop.
Quick-n'-Dirty צבע אדום alerts in Home Assistant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rest: | |
- resource: https://www.oref.org.il/WarningMessages/History/AlertsHistory.json | |
scan_interval: 3 | |
binary_sensor: | |
- name: "Red Alert צבע אדום" | |
device_class: safety | |
value_template: > | |
{% set homeCitiesTf = 'כפר עזה ,בצת' %} | |
{%- set ns = namespace() -%} | |
{%- set ns.output=[]-%} | |
{%- set thresholdMin = 5 -%} | |
{%- set homeCities = homeCitiesTf.split(',') | map('trim') | list -%} | |
{%- for dict in value_json -%} | |
{%- set dateString = dict["alertDate"] -%} | |
{%- set dateObj = dateString | as_datetime | as_local -%} | |
{%- set timeFromNow = now() - dateObj -%} | |
{%- if timeFromNow.days == 0 and (timeFromNow.seconds < (thresholdMin * 60)) -%} | |
{%- set cityList = dict["data"].split(',') | map('trim') | list -%} | |
{%- for alertCity in cityList -%} | |
{%- for homeCity in homeCities -%} | |
{%- if alertCity.startswith(homeCity) -%} | |
{%-set ns.output=ns.output+[alertCity]-%} | |
{%- endif -%} | |
{%- endfor -%} | |
{%- endfor -%} | |
{%- endif -%} | |
{%- endfor -%} | |
{{ ns.output | unique | list | count > 0 }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script creates a Binary Sensor in Home Assistant, which activates during a Red Alert in specified locations. Features include:
homeCitiesTf
with a comma-separated list (whitespace tolerant). It can be a single place or multiple.thresholdMin
).Installation:
Important Notes:
scan_interval
to avoid the risk of being blocked by the service.