Home AssistantSettings

Installing Ukraine Alarm in HA and setting up notifications

Update 2022.5.3 to Home Assistant introduces a new integration called Ukraine Alarm. With its help, you can get information about air alarms or other alarms in Ukraine in real-time.

Ukraine Alarm creates four binary sensors, each responsible for a specific type of alarm, and when the sensor is in the “on” state, a corresponding alarm goes off.

Ukraine Alarm api key

In version 2022.5.4 HA, the integration got an update. Now you do not need to wait for the API key from the developers (who may not give you the key), and you can configure “Ukraine Alarm” by specifying the area you plan to monitor immediately.

Adding Ukraine Alarm integration to Home Assistant

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

Click the My button or add “Ukraine Alarm” manually by clicking the “+ Add Integration” button and start entering the name. Then click on the name of our integration.

Ukraine Alarm step 1

Next, you need to choose the area where you plan to monitor the alarm, which could be an area, district, local community, or city.

In the last step, you can assign a room (zone) to which new integration sensors would add.

Ukraine Alarm step 2.4

After clicking on the “Finish” button, the “Ukraine Alarm” integration will be added.

Ukraine Alarm step 3

As you can see in the image, each instance of this integration creates four binary_sensor entities responsible for having a type of alarm. These alarms are Air, Artillery, Urban Fights, and Unknown. There is a limit on the number of territories, not to exceed the number of API requests from one IP. You can monitor up to 5.

Ukraine Alarm entities

Adding sensors to the home screen in the Dashboard

If you do not want to receive notifications but want clear information about alarms in a particular region, add sensors to the Lovelace card. Of course, you can design the look to your liking.

The first image shows a card with four-alarm sensors when there are no alarms. The second image shows the state of the sensors when the air alarm goes off.

Adding sensors to the home screen in the Dashboard

I already made a tutorial on setting up a Telegram bot that receives notifications from your smart home. Next, I’ll just add the automation code, which will allow you to send notifications to your telegram bot.

telegram notification

I will also provide the code to allow you to manage notifications in your Home Assistant mobile app. This example will use a voice notification, and you will hear it even when your phone is silent. Well, let’s get acquainted with the code.

файл /config/automations/notify_telegram_ukraine_alarm.yaml:

- id: notify-air-alarm
  alias: Air alarm
  initial_state: on
  trigger:
    - platform: state
      entity_id: binary_sensor.teritorialna_gromada_air #sensor state as a trigger
      to: "on"
  action:
    - service: notify.telegram #telegram notification 
      data:
        title: '{{"\U0001F525"}}{{"\U0001F525"}}{{"\U0001F525"}} *Повітряна тривога* {{"\U0001F525"}}{{"\U0001F525"}}{{"\U0001F525"}}'
        message: "О {{ states('sensor.time_date') }} оголошено повітряну тривогу"
        data:
          inline_keyboard:
            - '{{ "\u21a9\ufe0f" }} Панель керування:/to_cp'
    - service: notify.mobile_app_note20 #in-app voice notification
      data:
        title: "Air alert! Go to the shelter immediately!" #text you'll hear
        message: TTS # turns on TTS
        data:
          channel: alarm_stream # volume, (alarm_stream_max - maximum) 
    - service: notify.mobile_app_note20 # in-app notification (status bar)
      data:
        title: Air raid alert!  # title in the status bar
        message: Go to the shelter immediately # the notification text in the status bar
        data:
          ttl: 0
          color: red # notification color
          priority: high # priority

- id: notify-air-alarm-cancel
  alias: Air alarm cancel
  initial_state: on
  trigger:
    - platform: state
      entity_id: binary_sensor.teritorialna_gromada_air
      to: "off"
  action:
    - service: notify.telegram
      data:
        title: "*Alert cancelled*"
        message: "At {{ states('sensor.time_date') }} the alert was cancelled"
        data:
          inline_keyboard:
            - '{{ "\u21a9\ufe0f" }} Панель керування:/to_cp'
    - service: notify.mobile_app_note20
      data:
        title: "Air alert cancelled! Get back to your business!"
        message: TTS
        data:
          channel: alarm_stream
    - service: notify.mobile_app_note20
      data:
        title: Air alert cancelled!
        message: Get back to your business
        data:
          ttl: 0
          color: green
          priority: high


In the code above, I left comments on the relevant parts.

That’s all for today. Have a peaceful sky without air alerts!

Leave a Reply