After I have started the logging of my energy use with my flukso, I have some more things I want to build. One of those is that I want to make a difference between the High and Low tariff I pay for my electricity. I get my electricity from Liander, and they have some rules to decide wether it's High tariff or Low tariff:

It's always High tariff, except:
- from 23:00 to 07:00
- Saturday and Sunday
- Some hollidays, including Easter, Christmas, Pentecost and of course Kingsday.

To do this in the database, I made a php script:

<?php

//
// Laagarief volgens Liander in de regio Gelderland, Friesland en Flevoland
// op weekdagen van 23.00 tot 07.00 uur en in weekenden en op feestdagen de gehele dag
// Feestdagen zijn 1 januari, tweede paasdag, Koningsdag, Hemelvaartsdag, tweede pinksterdag, eerste kerstdag, tweede kerstdag.
//

        function laagtariefdag($day) {
                // input a timestamp
                // return H or L for High or Low tariff
                // for electricity delivered by Liander in the Netherlands
                //
                $START_DAY = "07:00";
                $END_DAY   = "23:00";

                $tijd = date('His',$day); //060000

                $result = 'H';
                //for $day make time at 00:00:00
                $dag = date('j', $day);
                $maand = date('n', $day);
                $jaar = date('Y', $day);
                $day = mktime(0, 0, 0, $maand, $dag, $jaar);
                $weekdag = date('w',$day);      //Sunday = 0, Monday = 1, Saturday = 6

                // first selection based on tine and day, later on 'feestdag'
                If (($tijd < $START_DAY) OR ($tijd > $END_DAY)){
                        $result = 'L';
                }
                else if (($weekdag == '0') OR ($weekdag == '6')) {
                        $result = 'L';
                }
                else {
                        $pasen = easter_date($jaar);
                        $paasdag = date('j', $pasen);
                        $paasmaand = date('n', $pasen);

                        $tweede_paasdag     = mktime(0, 0, 0, $paasmaand, $paasdag + 01, $jaar);
                        $hemelvaart         = mktime(0, 0, 0, $paasmaand, $paasdag + 39, $jaar);
                        $eerste_pinksterdag = mktime(0, 0, 0, $paasmaand, $paasdag + 49, $jaar);
                        $tweede_pinksterdag = mktime(0, 0, 0, $paasmaand, $paasdag + 50, $jaar);
                        $nieuwjaarsdag      = mktime(0, 0, 0, 01, 01, $jaar);
                        $koningsdag         = mktime(0, 0, 0, 04, 27, $jaar);
                        // Koningsdag never on sunday, then it's the day before that
                        if (date('w',$koningsdag) == 0) {
                                $koningsdag = mktime(0, 0, 0, 04, 26, $jaar);
                        }
                        $eerste_kerstdag    = mktime(0, 0, 0, 12, 25, $jaar);
                        $tweede_kerstdag    = mktime(0, 0, 0, 12, 26, $jaar);

                        $laagdagen = array($tweede_paasdag, $hemelvaart, $tweede_pinksterdag, $nieuwjaarsdag, $koningsdag, $eerste_kerstdag, $tweede_kerstdag);
                        sort($laagdagen);
                        foreach($laagdagen as $k => $v) {
                                // Debug
                                // echo $laagdagen[$k]."--".date('Y-m-d H:i:s',$laagdagen[$k])."<BR>";
                                if ($day == $laagdagen[$k]){
                                        $result = 'L';
                                        break;
                                }
                        }
                }
                return $result;
        }
//
// Test

//

echo laagtariefdag(strtotime("29-04-2014 08:00:00"));
echo laagtariefdag(strtotime("29-04-2014 08:00:00"));
echo laagtariefdag(strtotime("30-04-2014 08:00:00"));
echo laagtariefdag(strtotime("08-06-2014 08:00:00"));
echo laagtariefdag(strtotime("09-06-2014 08:00:00"));
echo laagtariefdag(strtotime("10-06-2014 08:00:00"));
?>