capture and import smartmeter data from Web Solar Log
Posted: Friday 08 August 2014 17:07
I use Web Solar Log (http://websolarlog.com) on a Raspberry Pi to monitor, gather and display data from my PV inverter (Omnik 3K-TL) using the Omnik-Data-Logger script https://github.com/Woutrrr/Omnik-Data-Logger and from my Dutch Smart Meter (ISKRA ME382) using an USB/serial cable attached to the P1 port.
This in itself works great and gives great insight into my solar energy production data and my household consumption of electricity and gas.
WSL also uploads the data to PVoutput, but in it's interpretation of what consumption is differs from mine. It graphs and uploads consumption as negative when production is higher than consumption. I want to see my actual consumption as how much energy my household is consuming, wether it be produced, imported or a combination of both, (hope this makes sense to you). Since negative figures are ignored by PVoutput this results in inacurate energy usage figures there.
Perhaps I should add that the smart meter records totals of imported energy and exported energy and power levels at the grid, but is not aware of my inverter's production.
I also run Domoticz on the raspi and of course I want to display my PV production and smart meter readings, mainly energy usage (and perhaps use that to trigger some automagic later on).I tried monitoring the smart meter from Domoticz simultaneously, but this disturbs WSL completely, making it sending out alarms every few minutes about not recieving data from the smart meter. I experimented a little with the polling rate, but I found out that it's just a bad idea to poll the meter from both WSL and from Domotics.
Since WSL does not have an option to query Domoticz, but does have a webpage that shows smart meter data (among others) that can be queried through JSON, I now want to use that to feed "virtual meters" in Domoticz with the elctricity and gas consumption data.
I (think I) managed to create a meters with virtual sensors for energy and gas, and I gues I will have to create a lua script (or two) now to query WSL and feed them. My problem is, I don't know how. I found some posts like http://www.domoticz.com/wiki/Capturing_ ... ua_Scripts that treat part of what I want, but I get confused and can't put two and two together.
I'm (still) a noob on lua and JSON, but know a (tiny) little bit about php and bash scripting.
Can I put everything in one lua script or do I need one for both meters? Can it only be used for updating Domoticz or also for querying WSL? Should it be a device- or a time script? Will I need a temporary file to store the values? etc.
What should be my next steps?
I also started a discussion athttps://groups.google.com/forum/#!topic ... Z9xS8rqw5E about where to retrieve what (smart meter) data to export to Domoticz.
It seems the WSL summary page provides some of the needed daily (actually current) values but not the "totals" and the power levels of the smart meter which I'd also like to export to the virtual meters in Domoticz:
- Total (lifetime) amount of imported electricity at low rate in kWh (1.8.1),
- Total (lifetime) amount of imported electricity at high rate in kWh (1.8.2)
- Total (lifetime) amount of exported electricity at low rate, in KWh (2.8.1)
- Total (lifetime) amount of exported electricity at high rate in KWh (2.8.2)
- Total (lifetime) amount of gas used in m3 (beneath 24.3.0)
- Current power usage in kW (1.7.0)
- Currently power returns in kW
My WSL page http://ip.adress.of.wsl/websolarlog/api.php/Summary/ will display:
{"data":{"metering":[{"lowReturn":0,"lowReturnCO2":0,"lowReturnTrees":0,"lowUsage":2.647,"lowUsageCO2":1164.68,"lowUsageTrees":43.14,"highReturn":2.33,"highReturnCO2":1025.2,"highReturnTrees":37.97,"highUsage":0.153,"highUsageCO2":67.32,"highUsageTrees":2.49,"gasUsage":0.439,"gasUsageCO2":0.97,"gasUsageTrees":0.04,"gasUsageCosts":" u20ac 0,29","returnKWH":2.33,"returnCO2":1.03,"returnCosts":" \u20ac 0,47","usageKWH":2.8,"usageCosts":" \u20ac 0,14","usageCO2":1232,"effUsageKWH":0.47,"effUsageCosts":" \u20ac 0,00"}],"weather":
[{"time":"1407495000","weatherSamples":70,"beaufort":3,"avgBeaufort":2,"avgTemp":18,"avgWindSpeed":3.2,"avgWindChill":21.5,"currentTemp":
21.5,"currentWindChill":0,"countTemp":70,"sunInfo":{"sunrise":1407471164,"sunset":1407525599,"transit":1407498382,"civil_twilight_begin":1407468766,"civil_twilight_end":1407527997,"nautica
l_twilight_begin":1407465592,"nautical_twilight_end":1407531172,"astronomical_twilight_begin":1407461402,"astronomical_twilight_end":1407535361},"minTemp":20.9,"maxTemp":22.4,"degreeDays":0.030000000000001,"windDirection":100,"humidity":"77","pressure":"1012","conditionId":"800","wind_speed":"4.6","rain1h":0,"rain3h":0,"clouds":"0"}],"production":[{"KWH":3.6,"costs":" \u20ac 0,72","CO2avoid":1.58,"trees":97.2}]},"total":{"metering":{"lowReturn":0,"lowReturnCO2":0,"lowReturnTrees":0,"lowUsage":2.647,"lowUsageCO2":1164.68,"lowUsageTrees":43.14,"highReturn":2.33,"highReturnCO2":1025.2,"highReturnTrees":37.97,"highUsage":0.153,"highUsageCO2":67.32,"highUsageTrees":2.49,"gasUsage":0.439,"gasUsageCO2":0.97,"gasUsageTrees":0.04,"gasUsageCosts":" \u20ac 0,29","returnKWH":2.33,"returnCO2":1.03,"returnCosts":" \u20ac 0,47","usageKWH":2.8,"usageCosts":" \u20ac 0,14","usageCO2":1232,"effUsageKWH":0.47,"effUsageCosts":" \u20ac 0,00"},"weather":{"time":1407495000,"weatherSamples":70,"beaufort":3,"avgBeaufort":2,"avgTemp":18,"avgWindSpeed":3.2,"avgWindChill":21.5,"currentTemp":21.5,"currentWindChill":0,"countTemp":70,"sunrise":1407471164,"sunset":1407525599,"transit":1407498382,"civil_twilight_begin":1407468766,"civil_twilight_end":1407527997,"nautical_twilight_begin":1407465592,"nautical_twilight_end":1407531172,"astronomical_twilight_begin":1407461402,"astronomical_twilight_end":1407535361,"minTemp":20.9,"maxTemp":22.4,"degreeDays":0.030000000000001,"windDirection":100,"humidity":77,"pressure":1012,"conditionId":800,"wind_speed":4.6,"rain1h":0,"rain3h":0,"clouds":0},"production":{"KWH":3.6,"costs":" \u20ac 0,72","CO2avoid":1.58,"trees":97.2},"totalUsagekWh":4.07,"totalUsageKWHCosts":" \u20ac 0,81","totalUsageKWHCO2":1.79,"totalUsageKWHTrees":66.3,"usedBeforeMeterKWH":1.27,"usedBeforeMeterCosts":" \u20ac 0,01","usedBeforeMeterCO2":0.56,"usedBeforeMeterTrees":20.7,"householdCO2":2.76,"householdUsage":2.8,"householdCosts":" \u20ac 0,56","householdTrees":102,"trees":102,"co2CompensationTree":27,"degreeDays":0.03,"m3PerdegreeDays":14.633,"costkwh":0.2,"costGas":0.65,"sunDown":false},"lang":
{"subscriptTrees":"nodig","usage":"verbruik","used":"gebruikt","gas":"gas","harvested":"Opgewekt","generated":"gegenereerd","trees":"bomen","power":"Vermogen","weather":"weer"},"timezoneOffset":2}
Below is a php script I made to retrieve and output the array and some of it's values:
#!/usr/bin/php
<?php
//$date=date +"%d-%m-%y";
$today = date ('mm-dd-Y');
$time = time ('H-i-s');
echo "date: " . $today . PHP_EOL;
echo "time: " . $time . PHP_EOL;
$json_string = file_get_contents("http://127.0.0.1/websolarlog/api.php/Summary/'. urlencode($today) . '");
//$json_string = file_get_contents("http://127.0.0.1/websolarlog/api.php/Summary/");
$parsed_json = json_decode($json_string, true);
$STDOUT = fopen("php://stdout", "w");
fwrite($STDOUT, print_r($parsed_json, TRUE));
fclose($STDOUT);
$parsed_json = $parsed_json['data']['weather'][0];
$time = $parsed_json['time'];
echo "Time ".$time."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$lowUsage = $parsed_json['lowUsage'];
echo "Low Import Today ".$lowUsage."kWh"."\n";
echo "Lifetime Low Import ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$highUsage = $parsed_json['highUsage'];
echo "High Import Today ".$highUsage."kWh"."\n";
echo "Lifetime High Import ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$usageKWH = $parsed_json['usageKWH'];
echo "Total Import Today ".$usageKWH."kWh"."\n";
echo "Lifetime Total Import ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$lowReturn = $parsed_json['lowReturn'];
echo "Low Return Today ".$lowReturn."kWh"."\n";
echo "Lifetime Low Export ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$highReturn = $parsed_json['highReturn'];
echo "High Return Today ".$highReturn."kWh"."\n";
echo "Lifetime High Export ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$returnKWH = $parsed_json['returnKWH'];
echo "Total Return Today ".$returnKWH."kWh"."\n";
echo "Lifetime Export Total ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$gasUsage = $parsed_json['gasUsage'];
echo "Gas Usage Today ".$gasUsage."m3"."\n";
echo "Gas Lifetime Usage ??? m3"."\n";
?>
This in itself works great and gives great insight into my solar energy production data and my household consumption of electricity and gas.
WSL also uploads the data to PVoutput, but in it's interpretation of what consumption is differs from mine. It graphs and uploads consumption as negative when production is higher than consumption. I want to see my actual consumption as how much energy my household is consuming, wether it be produced, imported or a combination of both, (hope this makes sense to you). Since negative figures are ignored by PVoutput this results in inacurate energy usage figures there.
Perhaps I should add that the smart meter records totals of imported energy and exported energy and power levels at the grid, but is not aware of my inverter's production.
I also run Domoticz on the raspi and of course I want to display my PV production and smart meter readings, mainly energy usage (and perhaps use that to trigger some automagic later on).I tried monitoring the smart meter from Domoticz simultaneously, but this disturbs WSL completely, making it sending out alarms every few minutes about not recieving data from the smart meter. I experimented a little with the polling rate, but I found out that it's just a bad idea to poll the meter from both WSL and from Domotics.
Since WSL does not have an option to query Domoticz, but does have a webpage that shows smart meter data (among others) that can be queried through JSON, I now want to use that to feed "virtual meters" in Domoticz with the elctricity and gas consumption data.
I (think I) managed to create a meters with virtual sensors for energy and gas, and I gues I will have to create a lua script (or two) now to query WSL and feed them. My problem is, I don't know how. I found some posts like http://www.domoticz.com/wiki/Capturing_ ... ua_Scripts that treat part of what I want, but I get confused and can't put two and two together.
I'm (still) a noob on lua and JSON, but know a (tiny) little bit about php and bash scripting.
Can I put everything in one lua script or do I need one for both meters? Can it only be used for updating Domoticz or also for querying WSL? Should it be a device- or a time script? Will I need a temporary file to store the values? etc.
What should be my next steps?
I also started a discussion athttps://groups.google.com/forum/#!topic ... Z9xS8rqw5E about where to retrieve what (smart meter) data to export to Domoticz.
It seems the WSL summary page provides some of the needed daily (actually current) values but not the "totals" and the power levels of the smart meter which I'd also like to export to the virtual meters in Domoticz:
- Total (lifetime) amount of imported electricity at low rate in kWh (1.8.1),
- Total (lifetime) amount of imported electricity at high rate in kWh (1.8.2)
- Total (lifetime) amount of exported electricity at low rate, in KWh (2.8.1)
- Total (lifetime) amount of exported electricity at high rate in KWh (2.8.2)
- Total (lifetime) amount of gas used in m3 (beneath 24.3.0)
- Current power usage in kW (1.7.0)
- Currently power returns in kW
My WSL page http://ip.adress.of.wsl/websolarlog/api.php/Summary/ will display:
{"data":{"metering":[{"lowReturn":0,"lowReturnCO2":0,"lowReturnTrees":0,"lowUsage":2.647,"lowUsageCO2":1164.68,"lowUsageTrees":43.14,"highReturn":2.33,"highReturnCO2":1025.2,"highReturnTrees":37.97,"highUsage":0.153,"highUsageCO2":67.32,"highUsageTrees":2.49,"gasUsage":0.439,"gasUsageCO2":0.97,"gasUsageTrees":0.04,"gasUsageCosts":" u20ac 0,29","returnKWH":2.33,"returnCO2":1.03,"returnCosts":" \u20ac 0,47","usageKWH":2.8,"usageCosts":" \u20ac 0,14","usageCO2":1232,"effUsageKWH":0.47,"effUsageCosts":" \u20ac 0,00"}],"weather":
[{"time":"1407495000","weatherSamples":70,"beaufort":3,"avgBeaufort":2,"avgTemp":18,"avgWindSpeed":3.2,"avgWindChill":21.5,"currentTemp":
21.5,"currentWindChill":0,"countTemp":70,"sunInfo":{"sunrise":1407471164,"sunset":1407525599,"transit":1407498382,"civil_twilight_begin":1407468766,"civil_twilight_end":1407527997,"nautica
l_twilight_begin":1407465592,"nautical_twilight_end":1407531172,"astronomical_twilight_begin":1407461402,"astronomical_twilight_end":1407535361},"minTemp":20.9,"maxTemp":22.4,"degreeDays":0.030000000000001,"windDirection":100,"humidity":"77","pressure":"1012","conditionId":"800","wind_speed":"4.6","rain1h":0,"rain3h":0,"clouds":"0"}],"production":[{"KWH":3.6,"costs":" \u20ac 0,72","CO2avoid":1.58,"trees":97.2}]},"total":{"metering":{"lowReturn":0,"lowReturnCO2":0,"lowReturnTrees":0,"lowUsage":2.647,"lowUsageCO2":1164.68,"lowUsageTrees":43.14,"highReturn":2.33,"highReturnCO2":1025.2,"highReturnTrees":37.97,"highUsage":0.153,"highUsageCO2":67.32,"highUsageTrees":2.49,"gasUsage":0.439,"gasUsageCO2":0.97,"gasUsageTrees":0.04,"gasUsageCosts":" \u20ac 0,29","returnKWH":2.33,"returnCO2":1.03,"returnCosts":" \u20ac 0,47","usageKWH":2.8,"usageCosts":" \u20ac 0,14","usageCO2":1232,"effUsageKWH":0.47,"effUsageCosts":" \u20ac 0,00"},"weather":{"time":1407495000,"weatherSamples":70,"beaufort":3,"avgBeaufort":2,"avgTemp":18,"avgWindSpeed":3.2,"avgWindChill":21.5,"currentTemp":21.5,"currentWindChill":0,"countTemp":70,"sunrise":1407471164,"sunset":1407525599,"transit":1407498382,"civil_twilight_begin":1407468766,"civil_twilight_end":1407527997,"nautical_twilight_begin":1407465592,"nautical_twilight_end":1407531172,"astronomical_twilight_begin":1407461402,"astronomical_twilight_end":1407535361,"minTemp":20.9,"maxTemp":22.4,"degreeDays":0.030000000000001,"windDirection":100,"humidity":77,"pressure":1012,"conditionId":800,"wind_speed":4.6,"rain1h":0,"rain3h":0,"clouds":0},"production":{"KWH":3.6,"costs":" \u20ac 0,72","CO2avoid":1.58,"trees":97.2},"totalUsagekWh":4.07,"totalUsageKWHCosts":" \u20ac 0,81","totalUsageKWHCO2":1.79,"totalUsageKWHTrees":66.3,"usedBeforeMeterKWH":1.27,"usedBeforeMeterCosts":" \u20ac 0,01","usedBeforeMeterCO2":0.56,"usedBeforeMeterTrees":20.7,"householdCO2":2.76,"householdUsage":2.8,"householdCosts":" \u20ac 0,56","householdTrees":102,"trees":102,"co2CompensationTree":27,"degreeDays":0.03,"m3PerdegreeDays":14.633,"costkwh":0.2,"costGas":0.65,"sunDown":false},"lang":
{"subscriptTrees":"nodig","usage":"verbruik","used":"gebruikt","gas":"gas","harvested":"Opgewekt","generated":"gegenereerd","trees":"bomen","power":"Vermogen","weather":"weer"},"timezoneOffset":2}
Below is a php script I made to retrieve and output the array and some of it's values:
#!/usr/bin/php
<?php
//$date=date +"%d-%m-%y";
$today = date ('mm-dd-Y');
$time = time ('H-i-s');
echo "date: " . $today . PHP_EOL;
echo "time: " . $time . PHP_EOL;
$json_string = file_get_contents("http://127.0.0.1/websolarlog/api.php/Summary/'. urlencode($today) . '");
//$json_string = file_get_contents("http://127.0.0.1/websolarlog/api.php/Summary/");
$parsed_json = json_decode($json_string, true);
$STDOUT = fopen("php://stdout", "w");
fwrite($STDOUT, print_r($parsed_json, TRUE));
fclose($STDOUT);
$parsed_json = $parsed_json['data']['weather'][0];
$time = $parsed_json['time'];
echo "Time ".$time."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$lowUsage = $parsed_json['lowUsage'];
echo "Low Import Today ".$lowUsage."kWh"."\n";
echo "Lifetime Low Import ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$highUsage = $parsed_json['highUsage'];
echo "High Import Today ".$highUsage."kWh"."\n";
echo "Lifetime High Import ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$usageKWH = $parsed_json['usageKWH'];
echo "Total Import Today ".$usageKWH."kWh"."\n";
echo "Lifetime Total Import ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$lowReturn = $parsed_json['lowReturn'];
echo "Low Return Today ".$lowReturn."kWh"."\n";
echo "Lifetime Low Export ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$highReturn = $parsed_json['highReturn'];
echo "High Return Today ".$highReturn."kWh"."\n";
echo "Lifetime High Export ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$returnKWH = $parsed_json['returnKWH'];
echo "Total Return Today ".$returnKWH."kWh"."\n";
echo "Lifetime Export Total ??? kWh"."\n";
$parsed_json = json_decode($json_string, true);
$parsed_json = $parsed_json['data']['metering'][0];
$gasUsage = $parsed_json['gasUsage'];
echo "Gas Usage Today ".$gasUsage."m3"."\n";
echo "Gas Lifetime Usage ??? m3"."\n";
?>