Skip to content

Covid-19 county news as push notifications to your smartphone

  • by

In the actual situation, we (my wife and I) are interested in the current corona case numbers in our county. Until now, we have always done this via the website of the RKI. Since this can be very tedious, I decided to automate the process and send push notifications. I would like to describe in this post in more detail on how did it.

Preface

We use IP Symcon as a control center for our SmartHome. The IP Symcon runs on a Raspberry Pi* in a control cabinet. The programming is written in the programming language PHP. Also, the sending of push messages is controlled by IP Symcon (Cloud Service of Symcon + APP). This article is not only for IP Symcon users, but the database is also supported by other systems such as OpenHab or Node-Red.

IP Symcon Dashboard
Dashboard of our IP Symcon installation

Where does the data come from?

Everyone probably knows the Covid-19 dashboard of the Robert Koch Institute. What might not be so well known, is the Covid-19 Data Hub. This service makes all the information about Covid-19 case numbers available as a REST API. Using the data hub, external websites or programs can access the current case counts. We are using the county data for this article.

RKI Dashboard county

How do we get the data?

The Covid-19 data hub uses a so-called “API Explorer”, which can be used to build a URL query. The interesting information for us are:

  • Incidence
  • Number of currently ill people
  • Deaths
  • Last update

To get this information, we now create parameter query in the API Explorer. To display only our county Germersheim, it is important to set a filter in the query to “GEN |TEXT”. Here you enter the county and press the Enter key to add the filter.

query settings


To keep the query response as small as possible, we only enable the following outer fields in the query:

  • cases
  • deaths
  • last_update
  • cases7_per_100k_txt
RKI Data hub outer fields


Now we can copy the query URL to the clipboard.

RKI Dashboard copy to clipboard

When we display the URL in the browser, we get a text in JSON format. This text is of course difficult to read for us humans, but perfect for data processing.

JSON response from RKI data hub

This query can now be used in other systems as described before. Decoding of the JSON string is possible in OpenHab as well as in Node-Red.

Data processing in IP Symcon

As mentioned above, IP Symcon uses the programming language PHP for programming. To read the data into IP Symcon, some preliminary work is required. First, we create variables, in which the values can be written later. For this we choose a category and click on “Add object”→”Variable”.

IP Symcon variables


We do this for a total of 5 variables and select the appropriate type of variable for each. To send the push notifications only the variables: “lastUpdate” and “message” are necessary. We use the other 3 variables to display the values later in the dashboard.

IP Symcon variables


Then we create a script that retrieves the data from the Covid-19 data hub, decodes the values from the JSON string, and then writes them to the variables we created earlier. To do this, we again select the category and create a script called “getRKIData”.

ip symcon create script


The code editor will open automatically. Here we copy and paste the following script. Then we copy the previously copied “Query URL” behind “Sys_GetURLContent”.

<?php

//load json response in $content variable 
$content = Sys_GetURLContent("https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=GEN%20%3D%20%27GERMERSHEIM%27&outFields=cases,deaths,OBJECTID,last_update,cases7_per_100k_txt&outSR=4326&f=json");

//decode json
$json = json_decode($content);

//set values
SetValueString(31965,$json->features[0]->attributes->cases7_per_100k_txt);
SetValueInteger(41808,$json->features[0]->attributes->cases);
SetValueInteger(40691,$json->features[0]->attributes->deaths);
SetValueString(41217,$json->features[0]->attributes->last_update);
SetValueString(43961,"LK Germersheim -> Inzidenz: ".$json->features[0]->attributes->cases7_per_100k_txt." | Aktuell Erkrankte: ".$json->features[0]->attributes->cases." | Totesfälle: ".$json->features[0]->attributes->deaths);

?>

Since RKI updates the data only once a day, it is sufficient to run the script every 60 minutes. To do this, we assign an event to the script by right-clicking on the script and then clicking on “Add object” → “Event” → “Cyclic”.

IP Symcon creating a Script


In the following popup we set the script to run every day for every 60 minutes.

IP Symcon script periodic


As soon as the script is now executed every 60 minutes, the created variables are written.

Create Push notifications

Now we still need the push notification to our smartphone. For this we create a script as we did before, only this time with the name “send_message” directly under the variable “lastUpdate”.

IP Symcon create script for push notifications


Copy the following code into the code editor.

<?php

WFC_PushNotification(49262,"Aktuelle Covid News", GetValueString(43961), "connected",0);

?>

Here, a push notification with the title “Latest Covid News” and the text from variable 43961, which was written by the previous script, is sent to our smartphones. To avoid sending a push message every 60 minutes, we must make sure that the message is only sent when the variable “lastUpdate” changes. For this we click on the created “send_message” script and add a “triggered event”.

IP Symcon prepare script for push notifications


In the following popup, we select “lastUpdate” as the triggering variable and set “Trigger” → “On Change” and then click OK.

IP Symcon when triggered send push notifications

Send Push notifications

Sending of push notifications is done automatically by IP Symcon. As soon as the variable “lastUpdate” changes, IP Symcon executes the script “send_message” and we receive our push notification.

Received Push notification

This is the end of my first guest article on the Mojo blog. I hope the contribution was interesting for one or the other and maybe even useful 🙂

Best regards
Kay

Leave a Reply

Your email address will not be published.