Howto use pimatic-log-reader with Plugwise Smile P1.

This howto is based on a running pimatic environment with the pimatic-log-reader installed and a working Plugwise Smile P1.
(if you don’t know how to install a plugin check the Howto section : Howto)

This is what we want to achieve
blank

Static IP for the Smile P1
First we have to set a static ip adress to the Smile.

To do this open the Plugwise app, go to settings (the 2 little gears in the right top) and here you see the current IP.

go to settings on the bottem right and scroll down until you see “WiFi-/LAN-settings”

Turn off “LAN DHCP-Client”, fill in the correct settings and save the settings.

It should look like this : (note: your settings are most likely different)
blank

Cronjob
Next step is to make a log file on the Raspberry Pi so pimatic can read the values from there.
This will be done via Cron, the log file will be updated every minute .

Use the username, password and static ip from the first step.

(info on Cron : Click here)

  • SSH into your Raspberry Pi
  • Type :
crontab -e
  • Add this line at the bottom of the file :
* * * * *  curl http://”username”:”password”@”staticip”/core/modules > /home/pi/plugwise.log
  • Exit (ctrl+x) and Safe the file.
  • Wait a minute and check if you see /home/pi/plugwise.log file, when you open this file you will see the same information that is displayed when you go to the http://ipofsmile/core/modules
    blank

The “match” (regex)
We need to make a regex to display the correct values, to make a regex we use this website : https://regex101.com/
Copy the text from the /home/pi/plugwise.log (we want to make a match from here) and put this in the “Test String”.

Now the fun part ….

These numbers are the numbers we want to match.
blank

This is how i make the match for the nl_offpeak
blank

code :

<measurement log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\+[0-9]+:[0-9]+'\s*unit='Wh'\s*directionality='consumed'\s*tariff_indicator='nl_offpeak'>([0-9]+.[0-9]+)<\/measurement>

This is how i make the match for the nl_peak
blank

code:

<measurement log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\+[0-9]+:[0-9]+'\s*unit='Wh'\s*directionality='consumed'\s*tariff_indicator='nl_offpeak'>([0-9]+.[0-9]+)<\/measurement>

Set up your device in pimatic
Now we can start to make a device in pimatic.
Edit the config file and add this device to the devices section:
All the device names\id’s are in dutch you can change them to whatever you like.
“id”: “energiemeter” can be “id”: “wattusage” and “name”: “Energie Meter” can be “name”: “This is how much you use!”

    {
      "id": "energiemeter",
      "name": "Energie Meter",
      "class": "LogWatcher",
      "file": "/home/pi/plugwise.log",
      "attributes": [
        {
          "name": "hoogtarief",
          "type": "number",
          "unit": "Wh"
        },
        {
          "name": "laagtarief",
          "type": "number",
          "unit": "Wh"
        }
      ],
      "lines": [
        {
          "match": "<measurement log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\+[0-9]+:[0-9]+'\s*unit='Wh'\s*directionality='consumed'\s*tariff_indicator='nl_offpeak'>([0-9]+.[0-9]+)<\/measurement>“,
          "hoogtarief": "$1"
        },
        {
          "match": "<measurement log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\+[0-9]+:[0-9]+'\s*unit='Wh'\s*directionality='consumed'\s*tariff_indicator='nl_offpeak'>([0-9]+.[0-9]+)<\/measurement>“,
          "laagtarief": "$1"
        }
      ]
    },

Restart pimatic and you can add this new device.
blank
you can also make separate devices for every value and everything you produce.

Device to display the total usage in kWh

To add a total usage device i used a VariablesDevice.

    {
      "id": "energiemeter_totaal",
      "class": "VariablesDevice",
      "name": "Totaal verbruik",
      "variables": [
        {
          "name": "hoogtarief+laagtarief",
          "type": "number",
          "expression": "$energiemeter.hoogtarief+$energiemeter.laagtarief",
          "unit": "Wh"
        }
      ]
    },

Restart pimatic and you can add this new device.
blank

Current usage device in Wattage

Next i want to know what the current Watt usage is we need to make a new regex for this.

These numbers are the numbers we want to match.
blank

code :

<measurement\\s*log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\\+[0-9]+:[0-9]+'\\sunit='W'\\s*directionality='consumed'>([0-9]+).[0-9]+</measurement>

Use this device

    {
      "id": "energiemeter_huidig",
      "name": "Huidig stroomverbruik",
      "class": "LogWatcher",
      "file": "/home/pi/plugwise.log",
      "attributes": [
        {
          "name": "stroom",
          "type": "number",
          "unit": "Watt"
        }
      ],
      "lines": [
        {
          "match": "<measurement\\s*log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\\+[0-9]+:[0-9]+'\\sunit='W'\\s*directionality='consumed'>([0-9]+).[0-9]+</measurement>",
          "stroom": "$1"
        }
      ]
    },

Restart pimatic and you can add this new device.
blank

How much gas do I use?

Again we have to search the right value and make a match.
![blank](I upload the picture later)

Code:

<measurement\\s*log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\\+[0-9]+:[0-9]+'\\s*unit='m3'\\s*directionality='consumed'>([0-9]+.[0-9]+)</measurement>

Use this device

 {
      "id": "gasmeter",
      "name": "Gas Meter",
      "class": "LogWatcher",
      "file": "/home/pi/plugwise.log",
      "attributes": [
        {
          "name": "gasmeter",
          "type": "number",
          "unit": "m3"
        }
      ],
      "lines": [
        {
          "match": "<measurement\\s*log_date='[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+\\+[0-9]+:[0-9]+'\\s*unit='m3'\\s*directionality='consumed'>([0-9]+.[0-9]+)</measurement>",
          "gasmeter": "$1"
        }
      ]
    },

Restart pimatic and you can add this new device.
![blank](I upload the picture later)

So now we have a overview of the current usage of our homes :) but… what did you use in the last 24 hours?

To calculate the usage we use a VariablesDevice again but we have to make some extra Variables.

To do this go to the /#variables-page of pimatic hit the gear in the right corner and add 4 new variables the value can be 0 for now :
![blank](I upload the picture later)
![blank](I upload the picture later)

  • energiemeter_dagelijksnieuw
  • energiemeter_dagelijksoud
  • gasmeter_dagelijksnieuw
  • gasmeter_dagelijksoud

These names can be changed to your languish.
!Don’t forget! If you change them here also change them in the Devices!

The Devices :

Electricity

    {
      "id": "energiemeter_24h",
      "name": "Stroomverbruik 24h in kWh",
      "class": "VariablesDevice",
      "variables": [
        {
          "name": "Stroomverbruik24h",
          "type": "number",
          "expression": "$energiemeter_dagelijksnieuw",
          "unit": "Wh"
        }
      ]
    },

Gas

    {
      "id": "gasmeter_24h",
      "name": "Gasverbruik 24h in m3",
      "class": "VariablesDevice",
      "variables": [
        {
          "name": "Gasverbruik24h",
          "type": "number",
          "expression": "$gasmeter_dagelijksnieuw",
          "unit": "m3"
        }
      ]
    },

(I upload the picture later)

Now the rules will do the magic !
We need 4 rules :
Rule name : Stroomverbruik Reset

if its 0:00 then $energiemeter_dagelijksoud = $energiemeter_totaal.hoogtarief+laagtarief and $energiemeter_dagelijksnieuw = 0

Rule name : Stroomverbruik Per 24h

if $energiemeter_totaal.hoogtarief+laagtarief changes then $energiemeter_dagelijksnieuw = $energiemeter_totaal.hoogtarief+laagtarief - $energiemeter_dagelijksoud

Rule name : Gasverbruik Reset

if its 0:00 then $gasmeter_dagelijksoud = $gasmeter.gasmeter and $gasmeter_dagelijksnieuw = 0

Rule name : Gasverbruik Per 24h

if $gasmeter.gasmeter changes then $gasmeter_dagelijksnieuw = $gasmeter.gasmeter - $gasmeter_dagelijksoud

Now we have to wait a minute to see if the values in the devices change.

If you have any questions you can post them below.