Homey Community Forum

P1 smartmeter (API)


#1

P1 smartmeter

NOTE: This app doesn’t get information out of the smartmeter, you have to use an external service that push data to the the app.

Introduction

This app adds the P1 smartmeter into Homey and add an api to update the data.

Usage

  1. Install the app com.p1.smartmeter .
  2. Add device p1 smartmeter .
  3. Use the endpoint /update to push data to Homey.

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"
       }
   }

Another developer ask the community for support
#2

Its currently in review for beta release


#3

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


#4

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.


#5

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.


Energy (electricity & gas) generic app
#6

I’ve just published the app in beta!


#7

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.


#8

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)


#9

Did you made this working?


#10

For Domoticz @herrieman could use Domoticz app


#11

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


#12

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


#13

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.


#14

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?


#15

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


#16

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


#17

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


#18

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.


#19

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!


#20

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