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.
- Install this component by creating a
custom_components
folder in the same folder as your configuration.yaml is, if you don't already have one. - Inside that folder, create another folder named
krisinformation
. Put thesensor.py
file in there (if you copy and paste the code, make sure you do it from the raw version of the file). - Add the code to your
configuration.yaml
using the config options below. - You will need to restart after installation for the component to start working.
- If you're having issues, ask for help on the forums or post an issue.
Configuration variables:
key | type | description |
---|---|---|
platform (Required) | string | krisinformation |
latitude (Optional) | string | The latitude of the position from which the sensor should look for messages. Default home zone latitude |
longitude (Optional) | string | The longitude of the position from which the sensor should look for messages. Default home zone longitude |
name (Optional) | string | Custom name for the sensor. Default krisinformation . (If country is configured the default will be sensor.krisinformation_sverige for country: 'Sverige' .) |
county (Optional) | string | The county from where the sensor should look for messages. Works in conjunction with coordinates. Get your county from this list and make sure spelling is correct. |
radius (Optional) | number | The radius in km from your position that the sensor should look for messages. Default 50 |
country (Optional) | string | Configuring this option will make the sensor only take country wide alerts. |
Example minimal configuration.yaml
sensor:
- platform: krisinformation
Example country alerts configuration.yaml
sensor:
- platform: krisinformation
country: 'Sverige'
Example advanced configuration.yaml:
sensor:
- platform: krisinformation
name: "Krisinformation Stockholm"
county: "Stockholms län"
latitude: !secret lat_coord
longitude: !secret long_coord
radius: 100
Example automation for getting a notification when the sensor has an alert: Make sure you change the sensor name if you didn't use the default name.
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.attributes.messages[0].Headline}} - {{states.sensor.krisinformation.attributes.messages[0].Message}} {{states.sensor.krisinformation.attributes.messages[0].Web}}
Like my work and want to say thanks? Do it here:
- 0.0.10 - Added fix for backwards compatibility for older python versions.
- 0.0.9 - Added option for a country specific sensor
- 0.0.8 - Made latitude and longitude optional now getting coords from Home Assistant base configuration if not specified.
- 0.0.7 - Added option to configury county in sensor