** 6 December 2015: Update of script. As KNMI updated their page and added the (wind) Chill factor (on a quite dirty way), I needed to rewrite the script and did an almost complete rewrite. Reconfiguration of devices and variables is necessary.
**
I decided to write a python script to retrieve the data from the public Dutch KNMI ftp server. I’m a Dutch user and I have also more confidence in the KNMI than in openweather.
It is still a basis script which does what it needs to do but could use a “sophisticated touch” to improve.
I will update, clean, expand, modularize, functionize etc. it in the coming time and I will also (try to) add weeractueel (see here for example). I can program in javascript but have no experience with coffeescript. Maybe it will come to a plugin and maybe never. If someone else can do it, then please do so. (And actually I’m quite lazy.)
The script retrieves “current weather” (onbewolkt, regenachtig, etc.), Temperature, humidity (RV), Wind direction and speed (m/s), visibility (m) and Pressure (hPa) from KNMI.
You can find the python script on my github.
In the heading of the script you need to set some pimatic settings for your server:
### Pimatic settings ###
# localhost is fine when running from your pimatic server. Otherwise change to suitable ip address or dns. Can be https as well.
pimatic_server = 'localhost'
# user and password. I prefer a special posting user having a role of varposter with only "variables": "write" in the varposter role. Rest to "none" or false.
pimatic_user = 'username'
pimatic_pass = 'password'
And slightly below that your preferred location from KNMI. Note that KNMI is not on all locations but other services simply pretend to be on that location by simply using the geographically closest locations:
### KNMI ###
# central public FTP page ftp://ftp.knmi.nl/pub_weerberichten/tabel_10min_data.html
# updated every 10 minutes
KNMI = "YES" # use in script: YES or NO
KNMILocation = "Heino"
Note that KNMI has not weather stations everywhere so first check the page at ftp://ftp.knmi.nl/pub_weerberichten/tabel_10min_data.html.
And when you’re ready do not forget to make the script executable:
chmod +x weeroverzicht.py
And add it to your cron or as a rule or device in pimatic. I put it un my cron and let it run every 10 minutes:
*/10 * * * * <the_path_to_the_script>/weeroverzicht.py > /dev/null 2>&1
In the config.json you need to create a VariablesDevice:
{
"id": "KNMImeting",
"//": "This variables Device is used to display the variables that will be updated by the external python script",
"name": "KNMI meting",
"class": "VariablesDevice",
"variables": [
{
"name": "knmi-locatie",
"expression": "$Station",
"type": "string",
"label": "Plaats",
"discrete": true,
"acronym": "Locatie"
},
{
"name": "knmi-weer",
"expression": "$Weer",
"type": "string",
"discrete": false
},
{
"name": "knmi-temperatuur",
"expression": "$Temp",
"type": "number",
"unit": "°C",
"label": "Temperatuur",
"discrete": false,
"acronym": "T"
},
{
"name": "knmi-chill",
"expression": "$Chill",
"type": "number",
"unit": "°C",
"label": "Chill Temperatuur",
"discrete": false,
"acronym": "T"
},
{
"name": "knmi-luchtvochtigheid",
"expression": "$RV",
"type": "number",
"unit": "%",
"label": "RV",
"discrete": false,
"acronym": "RV"
},
{
"name": "knmi-wr",
"expression": "$Wind",
"type": "string",
"discrete": false,
"acronym": "Wind"
},
{
"name": "knmi-ws",
"expression": "$Windms",
"type": "number",
"unit": "m/s",
"label": "wind",
"discrete": false,
"acronym": "Wind (m/s)"
},
{
"name": "knmi-zicht",
"expression": "$Zicht",
"type": "number",
"unit": "m",
"label": "zicht",
"discrete": false,
"acronym": "Zicht (m)"
},
{
"name": "knmi-druk",
"expression": "$Druk",
"type": "number",
"unit": "hPa",
"label": "Druk",
"discrete": false,
"acronym": "Druk (hPa)"
}
],
"xAttributeOptions": [
{
"name": "knmi-locatie",
"displaySparkline": false,
"hidden": false
},
{
"name": "knmi-weer",
"displaySparkline": false,
"hidden": true
},
{
"name": "knmi-temperatuur",
"displaySparkline": true,
"hidden": false
},
{
"name": "knmi-chill",
"displaySparkline": true,
"hidden": false
},
{
"name": "knmi-luchtvochtigheid",
"displaySparkline": true,
"hidden": false
},
{
"name": "knmi-wr",
"displaySparkline": false,
"hidden": false
},
{
"name": "knmi-ws",
"displaySparkline": false,
"hidden": false
},
{
"name": "knmi-zicht",
"displaySparkline": false,
"hidden": true
},
{
"name": "knmi-druk",
"displaySparkline": false,
"hidden": true
}
]
},
And a set of variables:
{
"name": "Station",
"value": "Heino"
},
{
"name": "Weer",
"value": ""
},
{
"name": "Temp",
"value": 12
},
{
"name": "Chill",
"value": ""
},
{
"name": "RV",
"value": 75
},
{
"name": "Wind",
"value": "ZW"
},
{
"name": "Windms",
"value": 6
},
{
"name": "Zicht",
"value": ""
},
{
"name": "Druk",
"value": ""
},
As not all KNMI weather stations collect all variables, you need to play a little with what you want to see on the screen and simply what is available. Use the xAttributeOptions to do that.
The default storage value is 7 days. If you want your data to be stored for a year or longer you also need to add one or more entries to the database->deviceAttributeLogging section.
Like:
{
"deviceId": "KNMImeting",
"attributeName": "*",
"type": "number",
"expire": "1y"
},
Another option is to simply rename knmi-temperatuur to temperature in your device. In that case it wil automatically be logged for a year.