Domoticz : How to add your Smart Power Meter ?

Background

To the topic of energy consumption and reduction, I always came to the same point : "How can you reduce your energy fingerprint if you have no idea about what your are currently consuming ?!?" This is the reason why I'm monitoring almost every energy I'm consuming. I'm monitoring my water usage, my solar production, and since recently, my electricity usage. I recently been providing by my energy provider with a smart meter and this is a great opportunity to create nice graphs !

Siconia

My explanation below are all related to the Siconia meter provided to residential customers in Belgium and I think in The Netherlands too. Any other smart meter should behave the same with some minimalistic differences though.

This is mine for context : 


The meter comes with a communication port hidden behind the lower left green-ich cap :


It actually hides a RJ-11 port. You need to get a cable with RJ-11 on one side and USB-A on the other side. I get mine from this site : https://www.sossolutions.nl/slimme-meter-kabel (no sponsorship, just quick and easy google search) .
Note : by default, the P1 port is not always activated. Ideally, you should ask the technician coming to setup your meter to open it. In Belgium, if you do it afterwards, it has a fee. Always good to know !

Now, you can plug the USB-A part in your monitoring platform. Mine is a Raspberry running Domoticz (if you are following me for a while, you should already be aware ;))

Domoticz configuration

Now, on the Domoticz side, go to Settings/Hardware and add a new hardware. with the following parameters : 


This is straightforward, no need to install any driver, this is all plug an play. Be sure to select the right USB port in the configuration and when data are recognized, they will be decrypted by Domoticz.

It will add 8 new entries in the device list. Feel free to use the one you need.

Overview

The Overview device is showing all usage metrics on a single graph. If you have a on-peak off-peak tariff scheme (which is my case), you will see the usage for each period in different colors : 


The Return 1 and Return 2 are the metrics for the extra production during on-peak and off-peak. Yes, I have solar panels on my roof and I can follow when I'm sending extra to the grid.

Digging a bit further ...

Domoticz sensor can be accessed with an API call and then, I can follow my usage/production almost in real time. I created 2 scripts one is reporting the usage since the meter has been installed and the other one is a real time usage reported every seconds.

Reading the existing indexes : 

<?php

/* 
    _________.__                    .__        
   /   _____/|__| ____  ____   ____ |__|____   
   \_____  \ |  |/ ___\/  _ \ /    \|  \__  \  
   /        \|  \  \__(  <_> )   |  \  |/ __ \_
  /_______  /|__|\___  >____/|___|  /__(____  /
  \/         \/           \/        \/ 
*/ 

// Init parameters

$domoticzIP="192.168.x.x";
$deviceIDX=7467;

/*
Peak usage : 1.8.1
Off-peak usage : 1.8.2
Peak injection : 2.8.1
Off-peak injection : 2.8.2
*/

$index=array(
"1.8.1" => 0,
"1.8.2" => 0,
"2.8.1" => 0,
"2.8.2" => 0
);

//---------------------------------------------------------------
// Function retrieving the values from a specific Domoticz sensor
//---------------------------------------------------------------

function dzGetSensor($domoticzIP,$idx)
{
    $api="/json.htm?type=devices&rid=".$idx;

         $curl = curl_init($api);
            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_URL, "https://".$domoticzIP.$api);

    $result = json_decode(curl_exec($curl));
            curl_close($curl);

    return($result);
}

$values=dzGetSensor($domoticzIP,$deviceIDX)->result[0]->Data;
$tmp=explode(";",$values);

$index["1.8.1"]=$tmp[0];
$index["1.8.2"]=$tmp[1];
$index["2.8.1"]=$tmp[2];
$index["2.8.2"]=$tmp[3];
$index["realTimeUsage"]=$tmp[4];
$index["realTimeInjection"]=$tmp[5];

print("\nMeter Index :");
print("\n-----------\n\n");

$peak=$index["1.8.1"]/1000;
print("Peak Usage : \t\t".$peak." kWh\n");
$offPeak=$index["1.8.2"]/1000;
print("Off Peak Usage : \t".$offPeak." kWh\n");
$peakInject=$index["2.8.1"]/1000;
print("Peak Injection : \t".$peakInject." kWh\n");
$offPeakInject=$index["2.8.2"]/1000;
print("Off Peak Injection : \t".$offPeakInject." kWh\n");
$totalUsage=$peak+$offPeak;
print("\nTotal Usage : \t\t".$totalUsage." kWh");
$totalInjection=$peakInject+$offPeakInject;
print("\nTotal Injection : \t".$totalInjection." kWh");
$balance=$totalUsage-$totalInjection;
print("\n\nBalance is : \t\t".$balance." kWh   <- must be as low as possible but positive value is a must.\n");

print("\nRealtime Power from Grid : ".$index["realTimeUsage"]." W\n");
print("Realtime Power sent to Grid : ".$index["realTimeInjection"]." W\n");
print("\n");

?>


Sample output :


Real time usage reporting :

<?php

/* 
    _________.__                    .__        
   /   _____/|__| ____  ____   ____ |__|____   
   \_____  \ |  |/ ___\/  _ \ /    \|  \__  \  
   /        \|  \  \__(  <_> )   |  \  |/ __ \_
  /_______  /|__|\___  >____/|___|  /__(____  /
  \/         \/           \/        \/ 
*/ 

// Init parameters

$domoticzIP="192.168.x.x";
$deviceIDX=7467;

/*
Peak usage : 1.8.1
Off-peak usage : 1.8.2
Peak injection : 2.8.1
Off-peak injection : 2.8.2
*/

//---------------------------------------------------------------
// Function retrieving the values from a specific Domoticz sensor
//---------------------------------------------------------------

function dzGetSensor($domoticzIP,$idx)
{
    $api="/json.htm?type=devices&rid=".$idx;

    $curl = curl_init($api);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_URL, "https://".$domoticzIP.$api);

    $result = json_decode(curl_exec($curl));
    curl_close($curl);

    /*
                $result structure :                 "2050275;2658721;887466;327835;301;0"                 1.8.1;1.8.2;2.8.1;2.8.2;CONS;PROD
    */

    return($result);
}

//---------------------------------------------------------------
// Main entry point
//---------------------------------------------------------------

while(TRUE)
{
    $values=dzGetSensor($domoticzIP,$deviceIDX)->result[0]->Data;
    $tmp=explode(";",$values);
    $realtimeUsage=$tmp[4];
    $realtimeInjection=$tmp[5];
    echo "\033[2J\033[H"; // Clears screen and moves cursor to top-left
    print("Siconia Power Meter real time usage\n");
    print("===================================\n\n");
    print("\nRealtime Power received from Grid : ".$realtimeUsage." W\n");
    print("Realtime Power sent to Grid : ".$realtimeInjection." W\n");
    print("\n\n");
    print("Ctrl+C to exit ");

    sleep(1);
}

?>


Sample script output : 


I hope this will help you to configure your Siconia smart meter and monitor your energy usage.

See you next time ! ;)







Comments

What's hot ?

Nutanix : CVM stuck into Phoenix

Mac OS X : Display images in-line with terminal