P1 smartmeter (API)

P1 smartmeter

NOTE: This app doesn’t get information out of the smartmeter , you have to use an device (a raspberry pi for example) that push data to the app.

Introduction

This app adds the P1 smartmeter into Homey and add an api to update the data. The repository https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader reads the data from the p1 and push it to the com.p1.smartmeter api.

Support

Do you like the app? Donate me a beer!

Requirements of the device that reads data from the smartmeter (a raspberry pi for example)

  1. A working internet connection.
  2. A serial (usb) connection with the p1 port of the p1 smartmeter.
  3. Power.
  4. Cli access to the device.

Script for reading the data and push it to the api (Standalone)

NOTE: This example is for DSMR 4.0 supported devices.

  1. Install the script https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader on the device connected to the serial p1.
  2. Run npm install
  3. Change the HomeyId as described in src/p1.js .
  4. Change the config.serialPort for your situation (you should check your smartmeter or google around…)
  5. Run the script by calling: node src/p1.js

Script for reading the data and push it to the api (DSMR-Reader)

  1. Install the script https://gist.github.com/steffjenl/31bd083eeb9d0be04375b7695b9f2eaf as plugin for DSM-Reader.
  2. More information about installing plugin’s can be found on https://dsmr-reader.readthedocs.io/nl/v3/plugins.html
  3. Change the HOMEY_ID as described in forward_raw_telegram_to_api.py .
  4. Execute as user dsmr in the dsmr directory ./post-deploy.sh

Usage of the Homey app

  1. Install the app com.p1.smartmeter .
  2. Add device p1 smartmeter .
  3. Use the package com.p1.smartmeter-dsmr.reader to push data com.p1.smartmeter 's endpoint /update or /update/dsmrreader .

Endpoint

POST: /update

body:

{
	"electricity": {
		"delivered": {
			"tariff2": {
				"reading": 0,
				"unit": "kWh"
			},
			"actual": {
				"reading": 0,
				"unit": "kW"
			},
			"tariff1": {
				"reading": 0,
				"unit": "kWh"
			}
		},
		"received": {
			"tariff2": {
				"reading": 0,
				"unit": "kWh"
			},
			"actual": {
				"reading": 0,
				"unit": "kW"
			},
			"tariff1": {
				"reading": 0,
				"unit": "kWh"
			}
		}
	},
	"gas": {
		"reading": 0,
		"unit": "m3"
	}
}

POST: /update/dsmrreader

body:

{
	"telegram": "1-3:0.2.8(50)
0-0:1.0.0(200622135714S)
0-0:96.1.1(4530303531303034343038313136383138)
1-0:1.8.1(002224.280*kWh)
1-0:1.8.2(002908.808*kWh)
1-0:2.8.1(000000.311*kWh)
1-0:2.8.2(000000.000*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(00.557*kW)
1-0:2.7.0(00.000*kW)
0-0:96.7.21(00017)
0-0:96.7.9(00004)
1-0:99.97.0(3)(0-0:96.7.19)(181029081549W)(0000001311*s)(181029084407W)(0000001688*s)(200119090253W)(0000005158*s)
1-0:32.32.0(00007)
1-0:32.36.0(00005)
0-0:96.13.0()
1-0:32.7.0(235.2*V)
1-0:31.7.0(003*A)
1-0:21.7.0(00.557*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303339303031393034363434303139)
0-1:24.2.1(200622135506S)(01107.129*m3)"
}

The repository is available at: GitHub - koktaildotcom/com.p1.smartmeter: Integrate a smartmeter (p1) into Homey

1 Like

Its currently in review for beta release

Nice!
Can you give an example of the setup of this external service? What did you implement at home?

I use a ‘Raspberry Pi 1 Model B+’ with an p1 cable (there are types for different smartmeters) and a Mini Wireless USB WiFi Adapter (RP1 comes without wifi).

Because there are different smart meters and different versions of data they transmit there isn’t one implementation. I use a python script that i found online and push the data with a POST to the app.

Hi,
will try your app in a few days, next friday my meter will be replaced by a P1 smart meter.
I have built a small circuit to connect the smart-meter to an esp8266 device running tasmota with serial-bridge configured. My hope/goal is to use this setup to push the P1 serial messages via mqtt to Homey, or to my Domoticz server as an alternative.

I’ve just published the app in beta!

Hi Koktail,
i’ve had a quick look at your app, but sadly I think this does not really fit with my setup :frowning:
I have a simple esp8266 device running espeasy, which passes the full p1 telegram via ser2net, it does not parse the telegram or something similar. I was hoping for an app that would do the parsing on Homey, similar to what I currently use on HAssIO, or before on Domoticz, both running on raspberri pi.

Bummer, too bad that it does not meet your expectations. You can try to export the data from either hassio or domaticz (if they have the possibility to export data trough an REST api)

Did you made this working?

For Domoticz @herrieman could use Domoticz app

@Jeroen_Somhorst, sadly I’m currently on HassIO, Domoticz was not very stable (crashed every other day) so last weekend I switched to HassIO and I must say that it looks pretty nice compared to Domoticz (or even Homey…).
The setup with ESP8266 connected to the P1 meter however does need some modifications, the wifi on that module is not very stable so the connection is lost every now and then, and as a result the energy data has some gaps…
I will check if a beefier controller (e.g. another raspi) connected to the P1 meter would be better, I then could also use the setup with your app @Koktail, will update my results.

2 Likes

I use multiple ESP8266’s around the house and never had any issues with that.

Very Nice!,

Small question is the Optional CRC check enabled default? or do I need to edit/run something to enable it. Looking at my output I get the feeling it’s not enabled.

I have scripting on my Raspberry that puts stuff in an RRD database, composes my usage graphs etc, but I would like to publish the information gathered to my Homey using the app there. Does somebody have a bash script or something ‘curly’ that does just the appropriate post to the Homey app from a local downloaded smarttelegram?

I don’t know if you can disable that. What software do you use to read your data?

You need to parse the telegram somehow, en then you can send an json to the rest API endpoint to the app.

not “disable” but in “enable” :slight_smile:
think I’m using you’re app in combination with a PI https://apps.athom.com/app/com.p1

The com.p1 only shows you the data you push to it. I think you should look into the service you use for calling that data.

I will post my script after I am done with it (to save another soul from figuring this out), but there’s a question preceeding it:


This 13590.7 KWh (which might be improved as kWh since a lowercase k is the correct abbreviation for kilo) is an addition of the “delivery” of tariff1 and tariff2, which puzzled me a bit at first. It’s the electricity used. Would it be an idea to put “ELECTRICITY USED” below it? And for the 4707.68 “ELECTRICITY DELIVERED” to keep it in style?

Another thing might be that my meter has no clue about gas usage. Would it be an idea to put those values as an option in a configuration field to either show or not show them?

Lot’s of questions, and I haven’t even thanked you for the work you put in. Let’s set that straight: thanks!

1 Like

Not sure if this is the best place for it, but here’s the script that is feeding com.p1 from my previously (and seperately) created smarttelegram (click on the :arrow_forward: sign below for the script):

bash script used
#!/bin/bash
# This script is started via cron and sends smartmeter data to homey
# The P1.py daemon is updating the smart telegram in /tmp/smarttelegram.txt at appropriate intervals
#

# Check if smarttelegram > 0
if [ -s /tmp/smarttelegram.txt ]
then
# Get all the parameters needed
# 1-0:2.8.2 delivered_tariff2, strip all crap
tdelivered_tariff2=`/bin/grep "1-0:2.8.2" /tmp/smarttelegram.txt | /bin/sed "s/.*(//;s/\*.*//"`
delivered_tariff2=$(/usr/bin/awk "BEGIN {printf \"%.3f\",$tdelivered_tariff2}")
# 1-0:2.7.0 delivered_actual, strip all crap
tdelivered_actual=`/bin/grep "1-0:2.7.0" /tmp/smarttelegram.txt | /bin/sed "s/.*(//;s/\*.*//"`
delivered_actual=$(/usr/bin/awk "BEGIN {printf \"%.2f\",$tdelivered_actual}")
# 1-0:2.8.1 delivered_tariff1, strip all crap
tdelivered_tariff1=`/bin/grep "1-0:2.8.1" /tmp/smarttelegram.txt | /bin/sed "s/.*(//;s/\*.*//"`
delivered_tariff1=$(/usr/bin/awk "BEGIN {printf \"%.3f\",$tdelivered_tariff1}")
# 1-0:1.8.2 received_tariff2, strip all crap
treceived_tariff2=`/bin/grep "1-0:1.8.2" /tmp/smarttelegram.txt | /bin/sed "s/.*(//;s/\*.*//"`
received_tariff2=$(/usr/bin/awk "BEGIN {printf \"%.3f\",$treceived_tariff2}")
# 1-0:1.7.0 received_actual, strip all crap
treceived_actual=`/bin/grep "1-0:1.7.0" /tmp/smarttelegram.txt | /bin/sed "s/.*(//;s/\*.*//"`
received_actual=$(/usr/bin/awk "BEGIN {printf \"%.2f\",$treceived_actual}")
# 1-0:1.8.1 received_tariff2, strip all crap
treceived_tariff1=`/bin/grep "1-0:1.8.1" /tmp/smarttelegram.txt | /bin/sed "s/.*(//;s/\*.*//"`
received_tariff1=$(/usr/bin/awk "BEGIN {printf \"%.3f\",$treceived_tariff1}")

# Prepare the post data
generate_post_data()
{
 cat <<EOF
   {
   "electricity": {
      "delivered": {
         "tariff2": {
            "reading": $delivered_tariff2,
            "unit": "kWh"
         },
         "actual": {
            "reading": $delivered_actual,
            "unit": "kW"
         },
         "tariff1": {
            "reading": $delivered_tariff1,
            "unit": "kWh"
         }
      },
      "received": {
         "tariff2": {
            "reading": $received_tariff2,
            "unit": "kWh"
            },
         "actual": {
            "reading": $received_actual,
            "unit": "kW"
           },
         "tariff1": {
            "reading": $received_tariff1,
            "unit": "kWh"
         }
      }
     },
     "gas": {
       "reading": 0,
       "unit": "m3"
     }
   }
EOF
}

# Send post_data with curl to homey
# a curl request with the above form and data in the proper format to 
http://localip/api/app/com.p1/update
#

/usr/bin/curl -X POST -H "Content-Type: application/json" -d "$(generate_post_data)" http://192.168.1.123/api/app/com.p1/update

else
 # No smarttelegram found. We have a problem. We might loop and try again, but for now: fail.
echo `/bin/date` homeyupdate failed, no smarttelegram found >> /tmp/power_insight_log.txt
fi

Basically Q&D (quick and decent enough): grep the values, awk them to their appropriate format, push them to com.p1 with a

/usr/bin/curl -X POST -H “Content-Type: application/json” -d “$(generate_post_data)” http://192.168.1.123/api/app/com.p1/update