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

<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:** [November 12, 2019, 11:46am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/41 "2019-11-12T11:46:15Z")

</div>

It’s likely fixable by changing the code of the script, but I haven’t taken a closer look at it to see where it might be leaking.

---

<div class="post-metadata">

**Author:** ![Onno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/onno/32/12663_2.png) [@Onno](https://community.homey.app/u/Onno)\
**Post date:** [November 12, 2019, 1:07pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/42 "2019-11-12T13:07:28Z")

</div>

What i’m doing now (all other things commented out).

var P1Reader = require(’…/main’)

const fs = require(‘fs’)  
const fetch = require(‘node-fetch’)

const homeyId = 'HOMEYID  
const homeyEndpoint = ‘/update’  
const homeyHost = ‘https://’ + homeyId + ‘.connect.athom.com/api/app/com.p1’ + homeyEndpoint  
const config = {}

const p1Reader = new P1Reader(config)

p1Reader.on(‘connected’, portConfig =\> {  
console.log(  
'Connection with the Smart Meter has been established on port: ’ +  
portConfig.port  
+ ’ (BaudRate: ’ + portConfig.baudRate + ', Parity: ’ +  
portConfig.parity + ', Databits: ’  
+ portConfig.dataBits + 'Stopbits: ’ + portConfig.stopBits + ‘)’)  
})

p1Reader.on(‘reading’, data =\> {  
const requestJson = JSON.stringify(data)

```
fetch(homeyHost, {
    method: 'post',
    body: requestJson,
    headers: {'Content-Type': 'application/json'},
})

```

})

process.on(‘uncaughtException’, error =\> {  
console.error(error)  
})

---

<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:** [November 12, 2019, 1:27pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/43 "2019-11-12T13:27:58Z")

</div>

Assuming that `P1Reader` is leak-free, try removing the call to `fetch` and see if that solves the memory leak.

---

<div class="post-metadata">

**Author:** ![Onno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/onno/32/12663_2.png) [@Onno](https://community.homey.app/u/Onno)\
**Post date:** [November 12, 2019, 1:30pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/44 "2019-11-12T13:30:30Z")

</div>

Going to try later this day, thanks so far.

---

<div class="post-metadata">

**Author:** ![Onno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/onno/32/12663_2.png) [@Onno](https://community.homey.app/u/Onno)\
**Post date:** [November 13, 2019, 2:37pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/45 "2019-11-13T14:37:52Z")

</div>

Allright, i’m now down to the bare bones as far as I can see.  
var P1Reader = require(’…/main’)

const fs = require(‘fs’)  
const fetch = require(‘node-fetch’)

const config = {}

const p1Reader = new P1Reader(config)

p1Reader.on(‘connected’, portConfig =\> {  
console.log(  
'Connection with the Smart Meter has been established on port: ’ +  
portConfig.port  
+ ’ (BaudRate: ’ + portConfig.baudRate + ', Parity: ’ +  
portConfig.parity + ', Databits: ’  
+ portConfig.dataBits + 'Stopbits: ’ + portConfig.stopBits + ‘)’)  
})

Issue seems to be in P1Reader. Not easily fixable by me.

Could it also be the node.js memory management being to bad for a raspberry pi zero?  
It only has 512 megs of memory…

---

<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:** [November 13, 2019, 3:09pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/46 "2019-11-13T15:09:20Z")

</div>

> [@Onno](#):
>
> Could it also be the node.js memory management being to bad for a raspberry pi zero?

Shouldn’t be a problem, a bare bones Node.js process takes up about 15 to 20MB at most. When you ran the bare bones test, how long until it started to run out of memory?

---

<div class="post-metadata">

**Author:** ![Onno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/onno/32/12663_2.png) [@Onno](https://community.homey.app/u/Onno)\
**Post date:** [November 13, 2019, 3:23pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/47 "2019-11-13T15:23:01Z")

</div>

Appr half an hour after starting the script the pizero’s memory is filled.

---

<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:** [November 13, 2019, 3:28pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/48 "2019-11-13T15:28:15Z")

</div>

Yeah, sounds like a memory leak ☹

---

<div class="post-metadata">

**Author:** ![Onno](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/onno/32/12663_2.png) [@Onno](https://community.homey.app/u/Onno)\
**Post date:** [November 13, 2019, 3:39pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/49 "2019-11-13T15:39:03Z")

</div>

Just tried installing domoticz, and installed the domoticz app in homey.  
It’s an extra step but is working flawlessly.

Maybe i’ll try this later on, but for now I’m done.

Thanks for the replies!

---

<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:** [December 20, 2019, 7:22am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/50 "2019-12-20T07:22:58Z")

</div>

I updated my app `com.p1` for reading out your smartmeter. The app has an new implementation of the script that pushes the data to homey.

The push script is almost real-time and uses less CPU and mem (@RP3 mem: 4 MB CPU: 10% ). Due to incompatibility there is an new driver. The current one is deprecated and will be removed after some time.

The app in test: [https://homey.app/a/com.p1/test/](https://slack-redir.net/link?url=https%3A%2F%2Fhomey.app%2Fa%2Fcom.p1%2Ftest%2F)  
The pusher script: [https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader](https://slack-redir.net/link?url=https%3A%2F%2Fgithub.com%2Fkoktaildotcom%2Fcom.p1.smartmeter-dsmr.reader)

---

<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:** [December 20, 2019, 7:27am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/51 "2019-12-20T07:27:41Z")

</div>

You can try the new implementation, it use way less resources: [https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader](https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader)

---

<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:** [December 20, 2019, 7:28am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/52 "2019-12-20T07:28:40Z")

</div>

You can try: [https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader](https://github.com/koktaildotcom/com.p1.smartmeter-dsmr.reader)

---

<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:** [December 22, 2019, 11:01am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/53 "2019-12-22T11:01:21Z")

</div>

I’ve fixed a bug in the pusher script. That will now work on the old driver now too.

---

<div class="post-metadata">

**Author:** ![VvBemmel](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/vvbemmel/32/9098_2.png) [@VvBemmel](https://community.homey.app/u/VvBemmel)\
**Post date:** [April 30, 2020, 12:59pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/54 "2020-04-30T12:59:37Z")

</div>

Hi Koktail,

I’ve set up the DSMR Reader on a VM, works OK. I installed your app on my Homey, works also OK.  
But when i add the smart meter, i see all the info, except current energy consumption. What can be wrong?

Thanks in advance.

---

<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:** [May 14, 2020, 11:32am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/55 "2020-05-14T11:32:15Z")

</div>

I’ve just released v3.1.3 to tests

---

<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:** [May 20, 2020, 10:40am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/56 "2020-05-20T10:40:08Z")

</div>

I’ve released v3.1.4 to tests. Is there any feedback?

---

<div class="post-metadata">

**Author:** ![VvBemmel](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/vvbemmel/32/9098_2.png) [@VvBemmel](https://community.homey.app/u/VvBemmel)\
**Post date:** [May 21, 2020, 11:54am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/57 "2020-05-21T11:54:21Z")

</div>

Hi Koktail,  
Thanks for your reply. I want to test the new version, but i cannot see the new version in the apps section of Homey. How can i test the new version?

Thanks!

---

<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:** [May 25, 2020, 7:19am UTC](https://community.homey.app/t/p1-smartmeter-api/6150/58 "2020-05-25T07:19:44Z")

</div>

You can find v3.1.4 here: [P1 Slimme meter App voor Homey | Homey](https://homey.app/nl-nl/app/com.p1/P1-Slimme-meter/test/)

---

<div class="post-metadata">

**Author:** ![VvBemmel](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/vvbemmel/32/9098_2.png) [@VvBemmel](https://community.homey.app/u/VvBemmel)\
**Post date:** [May 26, 2020, 12:11pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/59 "2020-05-26T12:11:37Z")

</div>

Hi Koktail,  
Thanks for your reply.  
I installed the v3.1.4. test version, but there’s no difference in showing the actual power consumption. There is only a dash sign at the current consumption.

I rebooted the app on homey and i restarted the p1 script on the VM.

Can i test some more? i.e. Output on the VM or something else?

---

<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:** [May 28, 2020, 8:22pm UTC](https://community.homey.app/t/p1-smartmeter-api/6150/60 "2020-05-28T20:22:32Z")

</div>

Did the value exist in the post you send?

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

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