# P1 smartmeter (API)

**URL:** <https://community.homey.app/t/p1-smartmeter-api/6150>\
**Category:** Apps\
**Created:** [January 1, 2019, 12:22pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150 "2019-01-01T12:22:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 1, 2019, 12:22pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/1 "2019-01-01T12:22:22Z")

</div>

# 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!](https://www.paypal.me/koktaildotcom)

### 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:

```auto
{
	"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:

```auto
{
	"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](https://github.com/koktaildotcom/com.p1.smartmeter)

---

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 1, 2019, 12:22pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/2 "2019-01-01T12:22:49Z")

</div>

Its currently in review for beta release

---

<div class="post-metadata">

**Author:** ![TedTolboom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tedtolboom/32/12081_2.png) [@TedTolboom](https://community.homey.app/u/TedTolboom)\
**Post date:** [January 1, 2019, 12:45pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/3 "2019-01-01T12:45:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 1, 2019, 2:25pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/4 "2019-01-01T14:25:19Z")

</div>

I use a ‘Raspberry Pi 1 Model B+’ with an [p1 cable](https://nl.aliexpress.com/w/wholesale-USB-P1-Poort-Nederlandse-Slimme-Meter.html?spm=a2g0z.search0104.0.0.590362bcgIIpLH&initiative_id=SB_20190101055643&site=nld&SortType=price_asc&g=y&SearchText=USB+P1+Poort+Nederlandse+Slimme+Meter) (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.

---

<div class="post-metadata">

**Author:** ![HerrieMan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herrieman/32/3613_2.png) [@HerrieMan](https://community.homey.app/u/HerrieMan)\
**Post date:** [January 1, 2019, 4:17pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/5 "2019-01-01T16:17:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 12, 2019, 11:06am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/6 "2019-01-12T11:06:59Z")

</div>

I’ve just published the app in beta!

---

<div class="post-metadata">

**Author:** ![HerrieMan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herrieman/32/3613_2.png) [@HerrieMan](https://community.homey.app/u/HerrieMan)\
**Post date:** [January 13, 2019, 9:01pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/7 "2019-01-13T21:01:41Z")

</div>

Hi Koktail,  
i’ve had a quick look at your app, but sadly I think this does not really fit with my setup ☹  
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.

---

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 14, 2019, 8:06am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/8 "2019-01-14T08:06:10Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Slof](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/slof/32/1318_2.png) [@Slof](https://community.homey.app/u/Slof)\
**Post date:** [January 14, 2019, 8:42am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/9 "2019-01-14T08:42:00Z")

</div>

Did you made this working?

---

<div class="post-metadata">

**Author:** ![Jeroen\_Somhorst](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jeroen_somhorst/32/184_2.png) [@Jeroen\_Somhorst](https://community.homey.app/u/Jeroen_Somhorst)\
**Post date:** [January 14, 2019, 8:46am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/10 "2019-01-14T08:46:12Z")

</div>

For Domoticz @herrieman could use [Domoticz app](https://community.homey.app/t/domoticz-app/6034)

---

<div class="post-metadata">

**Author:** ![HerrieMan](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/herrieman/32/3613_2.png) [@HerrieMan](https://community.homey.app/u/HerrieMan)\
**Post date:** [January 14, 2019, 11:23am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/11 "2019-01-14T11:23:25Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 14, 2019, 2:09pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/12 "2019-01-14T14:09:42Z")

</div>

> [@HerrieMan](#):
>
> the wifi on that module is not very stable

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

---

<div class="post-metadata">

**Author:** ![sjoerd](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sjoerd/32/6139_2.png) [@sjoerd](https://community.homey.app/u/sjoerd)\
**Post date:** [January 29, 2019, 2:22pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/13 "2019-01-29T14:22:53Z")

</div>

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.

 ![Smartmeter](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/b/b780d7ce8dec8dcfc1af3a2c50ddced13638b172.jpeg)

---

<div class="post-metadata">

**Author:** ![Gerard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gerard/32/8846_2.png) [@Gerard](https://community.homey.app/u/Gerard)\
**Post date:** [January 29, 2019, 8:35pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/14 "2019-01-29T20:35:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 30, 2019, 5:42am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/15 "2019-01-30T05:42:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 30, 2019, 5:45am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/16 "2019-01-30T05:45:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sjoerd](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sjoerd/32/6139_2.png) [@sjoerd](https://community.homey.app/u/sjoerd)\
**Post date:** [January 30, 2019, 7:05am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/17 "2019-01-30T07:05:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Koktail](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/koktail/32/51498_2.png) [@Koktail](https://community.homey.app/u/Koktail)\
**Post date:** [January 30, 2019, 7:12am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/18 "2019-01-30T07:12:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Gerard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gerard/32/8846_2.png) [@Gerard](https://community.homey.app/u/Gerard)\
**Post date:** [January 31, 2019, 2:28pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/19 "2019-01-31T14:28:11Z")

</div>

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:

 ![usage](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/e/eb40a613df06ef048576e65e0e3f8692656a36ab.jpeg)  
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!

---

<div class="post-metadata">

**Author:** ![Gerard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/gerard/32/8846_2.png) [@Gerard](https://community.homey.app/u/Gerard)\
**Post date:** [January 31, 2019, 3:21pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/20 "2019-01-31T15:21:32Z")

</div>

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 ▶ 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](http://192.168.1.123/api/app/com.p1/update)

[Next page](https://community.homey.app/t/p1-smartmeter-api/6150.md?page=2)
