P1 smartmeter (API)

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

I’ll have a look to make those changes. It sound very logic indeed. Think i’ll split the P1 in two different devices: Electricity and Gas that way there is also room for the low and high channels.

Can you add this to a git repository? Then I’ll link to this in the readme of the app.

I’ve added an issue on GH: https://github.com/koktaildotcom/com.p1.smartmeter/issues/3

Seems a bit odd to start a git repository for just this Q&D script. Feel free to put the script in the example directory as an unsupported way to reproduce the steps some other guy (me :slight_smile: ) took to make use of your beautiful com.p1 app on the homey. You might want to add two lines of comment to make the steps even more clear:

# 1-0:2.8.2 delivered_tariff2, hack string to proper numeric value
# From "1-0:1.8.2(01259.637*kWh)" To: "01259.637"
tdelivered_tariff2=`/bin/grep "1-0:2.8.2" /tmp/smarttelegram.txt | /bin/sed "s/.*(//;s/\*.*//"`
# From: "01259.637" To: "1259.637"
delivered_tariff2=$(/usr/bin/awk "BEGIN {printf \"%.3f\",$tdelivered_tariff2}")

And rereading my statement from yesterday about the ELECTRICITY DELIVERED idea… we would always have a confusion about what delivered energy actually is, to the house or to the grid? On this second thought, I reckon it would be best to avoid DELIVERED altogether and go for ‘ELECTRICITY USED’ and ‘ELECTRICITY PRODUCED’. Produced is technically not correct either (since it is solar production minus electricity used in the house), but I think it is the most intuitive wording of what the value is showing.

If people ask why I use full pathnames in my scripts, I like to know what version of a command I am using and to avoid being ‘hacked’ by a script that says grep and is in my search path and does a grep and make a local user root. I typically use defines in the beginning of my shell scripts, like:
AWK=/usr/bin/awk
and use them in the commands like
delivered_tariff2=$($AWK “BEGIN {printf “%.3f”,$tdelivered_tariff2}”)

In example code that seems a bit odd however, but that is how the script is running here. If for anything, I like the fact that this bash script is providing a more or less readable explanation of what your script part on the raspberry is actually doing. Which might be helpful in debugging.