Poor man’s weather station

  • December 21, 2017
  • 0 Comments

I found the blog below Some years ago while looping for a alternative for the weather services of Loxone http://www.sinnema.ch/?p=392.

With all the money invested in our Loxone home automation project there currently is no room for a weather station. I need one to steer the heating system. The KNX OT Box of Theben I bought has a program which can take outdoor temperatures into account.

Currently Loxone has a weather service but it is limited to certain countries and the Netherlands is not included (yet). So I started thinking, can I not use weather services on the internet to tell me my local temperature, mold that into a PicoC program and have the service tell my heating the outdoor temperature?
The answer is “Yes you can!”. I’ve cooked up a little PicoC program which will do exactly that. Here’s how to do that:

A WARNING IS IN PLACE HERE! PicoC is not very strict in its syntax checking. A missing curly bracket will still run but gives unpredictable behavior. At one time I had to remove the SD card from the server, format it and reinsert it because my server did not respond to anything anymore. Be careful with what you program and check double check your code before committing it to the server!

You will need an account at a weather service. I used ‘aerisapi.com’. Go to their website and create an account. After you have created your account, register your application and you will get a UserID and UserSecret which will you will need in the code below.

Add a ‘Program’ module to a page in your Loxone Config program.

I use a lot of Memory flags which help me organize the programming. Here are the settings for the outdoor temperature memory flag. Uncheck the ‘Use as digital flag’. Now you can also change the ‘Unit’ value to reflect the value.

Doubleclick the module and paste the program below into the edit window and change the values of <your id> and <your secret> to the values obtained from the website mentioned above.

// This programm calls the aerisapi.com weather web service.
// The return value is a JSON string. Since PicoC does not support
// JSON I use scraping of the string to find the values.
enum OutputPorts
{
    Temperature,        // AQ1
    Humidity,            // AQ2
    windKPH             // AQ3
};
int GetIntValue(char *name, int def)
{
    int value = def;
int pos = strfind(result, name, 0);
if(pos &gt; 0)
    {
        char *stemp = calloc(1, 10);
        int lenName = strlen(name);
strncpy(stemp, result + pos + lenName, 5);
value = atoi(stemp);
setoutput(Temperature, temp);
free(stemp);
        stemp = 0;
    }
printf ("%s = %d", name, value);
return value;
}
/// 
 
/// Main loop.
///
while(TRUE)
{
    char *host = "api.aerisapi.com";
    char *page = "/observations/apeldoorn,nl?client_id=&amp;client_secret=";
char *result = httpget(host, page);
if(result != 0)
    {
        int temp = GetIntValue("\"tempC\":", -100);
if(temp != -100)
        {
            setoutput(Temperature, temp);
        }
int humidity = GetIntValue("\"humidity\":", -100);
if(temp != -100)
        {
            setoutput(Humidity, humidity);
        }
int wind = GetIntValue("\"windKPH\":", -100);
if(temp != -100)
        {
            setoutput(windKPH, wind);
        }
free(result);
    }
// Slow the loop down 10 minutes
    int sleepTime = 10 * 60 * 1000;
    sleep(sleepTime);
}

When you run the code in the server you will see the following in the Log. And the memory flags will show Temperature Celsius, Humidity and Wind velocity.

Leave a Comment

Your email address will not be published. Required fields are marked *