Custom Component Krisinformation (Sweden)

This is a work in progress and I would appreciate having a couple of users testing it and reporting back!

stability-wip

Version maintained

maintainer

sensor.krisinformation

Component to get Krisinformation for Home Assistant.

Will get all messages from Krisinformations api in a set radius from your coordinates.
If one of the fetched messages is an alert as opposed to news, the state of the sensor will be “Alert”. The sensor contains all fetched messages as objects.

Use together with custom card for Lovelace:

This component is supported by Custom updater and Tracker card.

Installation:

  1. Install this component by copying to your /custom_components/sensor/ folder.
  2. Add the code to your configuration.yaml using the config options below.
  3. You will need to restart after installation for the component to start working.

Configuration variables:

key type description
platform (Required) string krisinformation
latitude (Required) sring The latitude of the position from which the sensor should look for messages.
longitude (Required) string The longitude of the position from which the sensor should look for messages.
name (Optional) string Custom name for the sensor. Default krisinformation
radius (Optional) number The radius in km from your position that the sensor should look for messages. Default 50

Example configuration.yaml:

sensor:
  - platform: krisinformation
    name: Krisinformation Stockholm
    latitude: !secret lat_coord
    longitude: !secret long_coord
    radius: 100

Usage

Example automation for getting a notification when the sensor has an alert:

automation:
  - alias: 'Krisinformation Alert'
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: sensor.krisinformation
      to: "Alert"
    action:
      - service: notify.my_phone
        data_template:
          message: >
            {{states.sensor.krisinformation_stockholm.attributes.messages[0].Headline}} - {{states.sensor.krisinformation_stockholm.attributes.messages[0].Message}} {{states.sensor.krisinformation_stockholm.attributes.messages[0].Web}}
9 Likes

Great job :+1:

Do you know how much info that is gathered from this channels?
https://cert.se/
https://www.msb.se/

1 Like

Great work!

1 Like

You could default lat/long to home location?

Krisinformation.se is MSB:s site.
I don’t know anything about cert.se unfortunately.

Thanks! And yes, I plan to do that as soon as I get the time. I have opened an issue on that myself. :smiley:

1 Like

It warned about some cert stuff right before christmas. (I did a component a couple of weeks ago for this, but this one is much better)

2 Likes

I found a bug, so hold on a bit!

Bug fixed, version 0.0.2 out now!

1 Like

Well done @teachingbirds :ok_hand:

1 Like

A few more bugs squashed, so now it’s on 0.0.4. I’m working on getting it in custom updater and tracker card for those who use that, then this process will be easier.

Available in custom updater now: https://github.com/custom-components/custom_updater

1 Like

Made a quick custom card for Lovelace to display the information since it’s not that easy to see it otherwise: https://github.com/isabellaalstrom/krisinfo-card

1 Like

The card is now also available in custom updater.

1 Like

I think I have a problem with the sensor. Its the first message I got from the sensor but it does not seem to display correct. Message is [object Object]

krisinfo

It’s a list of objects. Look at the examples in the repo to see how to get the info from object.

I get this error in the log when trying to add the card:
Uncaught TypeError: Cannot read property 'attributes' of undefined

What can be wrong? The sensor seems to work ok.

Made sure you have the right sensor defined in the card?

v 0.0.9 is released.

With the latest releases you now don’t have to configure coords if you want the same ones as in your base configuration for Hass. You can also make a sensor for nation wide alerts, with the new option “country”.
You can also specify county (län) to get more accurate alerts for your whole county, despite setting a lower radius.

2 Likes

After updating Homeassistant to 0.89.0, I get no sensors to work. Neither “krisinformation”. When I comment out platform krisinformation, all sensors work again. What could be the problem?