{"id":5039,"date":"2021-04-22T20:34:03","date_gmt":"2021-04-22T18:34:03","guid":{"rendered":"https:\/\/grodansparadis.com\/wordpress\/?p=5039"},"modified":"2026-02-11T13:25:26","modified_gmt":"2026-02-11T12:25:26","slug":"howto-smart-p1-power-meter-ellevio","status":"publish","type":"post","link":"https:\/\/grodansparadis.com\/wordpress\/?p=5039","title":{"rendered":"Howto: Smart P1 power  meter (Ellevio)"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/Screenshot-from-2021-04-21-21-06-37.png?w=580&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is Screenshot-from-2021-04-21-21-06-37.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A Swedish version of this document is <a href=\"https:\/\/www.akehedman.se\/wordpress\/?p=38542\">here<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A PCB to interface the smartmeter is available <a href=\"https:\/\/github.com\/grodansparadis\/vscp-p1-pulse-interface\" data-type=\"URL\" data-id=\"https:\/\/github.com\/grodansparadis\/vscp-p1-pulse-interface\">here<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is how the new electricity meter look slike that was installed here this week. Apparently, <a href=\"https:\/\/www.energiforetagen.se\/medlemsnyheter\/2019\/januari\/54-miljoner-nya-elmatare-senast-den-1-januari-2025\/\">5.4 million new meters will be out before 2025 (Swedish)<\/a>. Yes, I have been collecting data from its predecessor (which was only installed here for two years) for quite some time. S0 pulse was not available to ordinary people like me but the flashing IR diode was. So power and energy I have logged. I have another meter in my office too. Reads S0 and IR there and can thus distinguish between the house&#8217;s total electricity consumption and the office&#8217;s electricity consumption.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But the new electricity meter promised more. A serial interface for customers. A HAN gate. Yep, definitely something that definitely start a guy like me up. A few minutes after it was installed, the customer interface was activated. Just go to <a href=\"https:\/\/www.ellevio.se\/privat\/\">Ellevio&#8217;s<\/a> &#8220;my pages&#8221; and activate. Smooth.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Unfortunately I did not go ahead with building the interface logic required to be able to read out values from the interface the day it got installed. Had to (impatiently) wait to the next day because I had other things to do. But it was very simple. A transistor, some resistors and a USB to series converter are all that is needed. After it is built a Raspberry Pi could read the information that the meter sends out. You could just as easily use an ESP32&#8217;a or an ESP8266, Arduino, or a PC of course. Nothing strange, expensive or advanced here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The new meter provides current and voltage and active and reactive load on all phases separately. Add summed energy to that. Yes, both in and out. If you are someone who has a wind turbine or solar panels in the yard the in readings is for you. Goddies for those of us that like data. All data is sent out every ten seconds from the meter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So what does the meter send?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As far as I understand, the protocol is called &#8220;<strong>P1 Companion Standard<\/strong>&#8221; which is based on IEC 62056-21 Mode D. The energy companies have issued an<a href=\"https:\/\/www.energiforetagen.se\/globalassets\/energiforetagen\/det-erbjuder-vi\/kurser-och-konferenser\/elnat\/branschrekommendation-lokalt-granssnitt-v2_0-201912.pdf\"> Industry Recommendation for local customer interface for electricity meters<\/a> that describes function and protocol.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The serial format is unencrypted with speed and format 115200, N, 8.1. Just standard. However, it is sent inverted and with TTL levels so you have to take care of that.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The contact on the electricity meter is an RJ12 as below<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/upload_2020-9-29_11-11-43.png?w=580&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is upload_2020-9-29_11-11-43.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The meter sends data on pin 5 when <strong>D_Rqst<\/strong> (RTS) is high. I have tested the  circuit below with both 5V and 3.3V and both work great so interfacing most hardware should be no problem as long as it has a serial port or can emulate one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you look at what the interface on the meter looks like, you understand that both 3.3V and 5V work.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/htb1z7hnxznuk1rksmfpq6auzfxal.jpg?w=580&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is htb1z7hnxznuk1rksmfpq6auzfxal.jpg\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A simple circuit is all that is needed to adapt this to a USB TTL serial adapter I used or to the serial channels on a Raspberry Pi, Arduino or other device.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" height=\"335\" width=\"580\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/Screenshot-from-2021-04-21-20-56-50-1024x591.png?resize=580%2C335&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is Screenshot-from-2021-04-21-20-56-50-1024x591.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Select 5V for VCC if rx is to be connected to a 5V input (Arduino etc), otherwise select 3.3V (ESP32 \/ ESP8266 \/ Raspberry Pi etc). In my case, <a href=\"https:\/\/frogshop.se\/product\/usb-ttl-serial-adapter\/?v=f003c44deab6\" data-type=\"URL\" data-id=\"https:\/\/frogshop.se\/product\/usb-ttl-serial-adapter\/?v=f003c44deab6\">I use a USB to series adapter that can handle TTL levels<\/a>. Remember to also connect the earth to the device that will read the data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you use a USB to series adapter like me and Raspberry Pi, it will be available as \/dev\/ttyUSB0, \/dev\/ttyUSB1, etc when connected. With the Minicom program you can look at the raw data. Install Minicom with<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\">sudo apt install minicom<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you want to be able to open the port without &#8220;sudo&#8221;, you should add the user you are running under (usually &#8220;<strong>pi<\/strong>&#8220;) to <strong>dialout<\/strong> in the file <em>\/dev\/group<\/em><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/Screenshot-from-2021-04-21-21-17-14.png?w=580&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is Screenshot-from-2021-04-21-21-17-14.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Use the <em>nano<\/em> or <em>vim<\/em> editor or your own favorite editor to do this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now run Minicom with<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\">minicom -b115200 -D\/dev\/ttyUSB0<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Change the serial port to the port you use and add <em>sudo<\/em> if you did not do the change in \/dev\/group.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The command line  switches speak for themselves. But for safety&#8217;s sake, we take them. <strong>-b<\/strong> sets the baud rate. <em>-D<\/em> indicates the port you want to communicate on. Of course you change to the port you use. If all goes well, the following is printed on the screen every ten seconds.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/Screenshot-from-2021-04-21-21-25-34.png?w=580&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is Screenshot-from-2021-04-21-21-25-34.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the linked document above, there is an appendix 3 that tells what the type of data is for each line. Easy to parse with our code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> To exit Minicom, type<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\">ctrl-A Z X<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and select &#8220;yes&#8221; when asked &#8220;Leave Minicom?&#8221; Best to write it because the sequence is not the first one you come up with. Trivial if you know it, not so if you don&#8217;t. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is not more than that. Now just write a program that reads these values and lists them in charts and tables. <a href=\"https:\/\/nodered.org\/\">node-red<\/a> is a great tool to use for this. node-red can read from a serial port directly or you can write a script like this in Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\">import serial\n\nsio = serial.Serial(\nport='\/dev\/ttyUSB1',\\\nbaudrate=115200,\\\nparity=serial.PARITY_NONE,\\\nstopbits=serial.STOPBITS_ONE,\\\nbytesize=serial.EIGHTBITS,\\\ntimeout=12)\n\nprint(\"connected to: \" + sio.portstr)\ncount=1\n\nwhile True:\nline = sio.readline().decode('ascii')\nif (-1 != line.find(\"1-0:31.7.0\")):\nprint(\"&#91;\" + line + \"]\")\nprint(\"Fas L1:\"+line&#91;11:-5]+ \" \" + line&#91;-4])\nprint(float(line&#91;11:-5]))<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Preferably, you then send the data to an MQTT broker or similar instead of printing it. A little fun coding for a boring evening maybe.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I have put together the project <a href=\"https:\/\/github.com\/grodansparadis\/vscp-python-p1-power-meter\">vscp-python-p1-power-meter<\/a> which sends sensor values to any MQTT broker. If you do not like VSCP, the code can be easily adapted for other formats. I think the code is pretty easy to understand. Configuration takes place in the <a href=\"https:\/\/github.com\/grodansparadis\/vscp-python-p1-power-meter\/blob\/main\/config.ini\">config.ini <\/a>file and you have documentation on the code page. Below is a screenshot from <a href=\"http:\/\/mqtt-explorer.com\/\">MQTT explorer <\/a>showing MQTT VSCP data for voltage, phase 1 delivered in real time<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" height=\"336\" width=\"580\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/Screenshot-from-2021-04-21-22-51-43-1024x594.png?resize=580%2C336&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is Screenshot-from-2021-04-21-22-51-43-1024x594.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And below the current data for the same phase<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" height=\"357\" width=\"580\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/Screenshot-from-2021-04-21-22-56-10-1024x630.png?resize=580%2C357&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is Screenshot-from-2021-04-21-22-56-10-1024x630.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Note the diagram at the bottom right. A smooth feature in MQTT explorer to quickly visualize data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is what it can look like when data is presented in node-red<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.akehedman.se\/wordpress\/wp-content\/uploads\/2021\/04\/Screenshot-from-2021-04-21-21-59-57.png?w=580&#038;ssl=1\" alt=\"This image has an empty alt attribute; its file name is Screenshot-from-2021-04-21-21-59-57.png\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">But it is very easy to create your own website and present live data there if you first send it to an MQTT broker taht havae websockets enabled. If you send VSCP events over that interface instead of some other random data, you have a solution that is both scaleable and reusable at all levels. I may do a howto on that to later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is how it looks in node-red<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2021\/09\/Screenshot-from-2021-09-01-10-31-20.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"518\" height=\"569\" data-attachment-id=\"5274\" data-permalink=\"https:\/\/grodansparadis.com\/wordpress\/?attachment_id=5274\" data-orig-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2021\/09\/Screenshot-from-2021-09-01-10-31-20.png?fit=518%2C569&amp;ssl=1\" data-orig-size=\"518,569\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-from-2021-09-01-10-31-20\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2021\/09\/Screenshot-from-2021-09-01-10-31-20.png?fit=518%2C569&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2021\/09\/Screenshot-from-2021-09-01-10-31-20.png?resize=518%2C569&#038;ssl=1\" alt=\"\" class=\"wp-image-5274\" srcset=\"https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2021\/09\/Screenshot-from-2021-09-01-10-31-20.png?w=518&amp;ssl=1 518w, https:\/\/i0.wp.com\/grodansparadis.com\/wordpress\/wp-content\/uploads\/2021\/09\/Screenshot-from-2021-09-01-10-31-20.png?resize=273%2C300&amp;ssl=1 273w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For a live demo check <a href=\"http:\/\/demo.vscp.org\">here<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A driver for the VSCP daemon is <a href=\"https:\/\/github.com\/grodansparadis\/vscpl2drv-energy-p1\" data-type=\"URL\" data-id=\"https:\/\/github.com\/grodansparadis\/vscpl2drv-energy-p1\">here<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Swedish version of this document is here A PCB to interface the smartmeter is available here This is how the new electricity meter look slike that was installed here this week. Apparently, 5.4 million new meters will be out before 2025 (Swedish). Yes, I have been collecting data from its predecessor (which was only [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[53,13],"tags":[],"class_list":["post-5039","post","type-post","status-publish","format-standard","hentry","category-howtos","category-vscp"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4raCZ-1jh","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5039"}],"version-history":[{"count":9,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5039\/revisions"}],"predecessor-version":[{"id":6254,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/5039\/revisions\/6254"}],"wp:attachment":[{"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/grodansparadis.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}