Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


[SOLVED]Smart Meter reading with P1Monitor


evanbeem

Recommended Posts

Hi all,

 

The wife and I have done some work on getting  json data from a Raspberry PI, running PI1Monitor.

The Pi is reading the data from a smart meter P1 port and we built a virtual device that shows the meter readings in a VD screen.

I included the VD and LUA-code. It's not pretty, but it works.

 

We would like to take this to the next level, but here is where we need help.

 

- Would it be possible to change the VD so it delivers the current usage to the power metering of the HC2. Right now, we have only some switches and dimmers that are counted in the power panel and we would like to have all power usage visible and we're not so interested in the usage of individual lights. We could use "some" help with that.

 

- How can we add icons to the labels. We've seen some examples with beautiful screenshots, but we are stuck with plain text.

 

Feel free to use the code. We're happy to share it with you.

 

Regards, Erwin & Linda

 

 

Please login or register to see this attachment.

Please login or register to see this attachment.

  • Like 1
Link to comment
Share on other sites

Hi @evanbeem,

 

I use something similar. What I have done is the following. Basic idea is to use one of the z-wave modules which does not have an actual power usage measurement to store/report the difference between the total actual power (W) as reported by the p1/smartmeter and the total power usage as reported by the other zwave modules. This way fibaro will report the correct total kW/kWh, etc.

 

I have added some lines in your lua script to make this happen. I made edits line 45-63.

 

Hope this help. Rene.

 

Please login or register to see this code.

 

Edited by ReneNL
  • Thanks 1
Link to comment
Share on other sites

  • Topic Author
  • Hi Rene, 

     

    That's should probablly work! Will try it out and let you know. Thanks!

     

    Regards, Erwin

    Link to comment
    Share on other sites

  • Topic Author
  • Hi Rene,

     

    I tried your solution and it works like a charm. I now have all power usage visible in my main fibaro screen, as intended.

    Thanks again! ;D

     

    Regards, Erwin

     

    A few remarks for other readers: the device I sent the data to, obviously needs to have a power attribute, so a switch, dimmer, etc.

    Also, you need to disable the display of all the other power values in that power grid, or you will get double readings.

     

     

    Link to comment
    Share on other sites

    • evanbeem changed the title to [SOLVED]Smart Meter reading with P1Monitor
    • 2 months later...
    • 1 year later...

    hello,

    i downloaded the p1monitor to my raspberry pi and its working.

    i make the virtual device and changed the lua code for the right ip adress and device id.

    its not starting when i check the debug function it says:

     

    [DEBUG] 13:30:26: Error in calling apiV3basic.php ; apiStatus 404; apiErrorCode 0; apiResult 

    404 Not Found

    nginx/1.14.2

     

    what could i do to make it work?

     

    thanks in advance

    Link to comment
    Share on other sites

    On 5/29/2018 at 10:08 PM, evanbeem said:

    Also, you need to disable the display of all the other power values in that power grid, or you will get double readings.


    I think Rene already did with:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    I just bought a Raspberry PI to experiment. 
     

    interested in the Lua code. Mayby the Plugwise is also a Raspberry PI under the hood?

    Link to comment
    Share on other sites

    Aha, You're connecting the PI directly to the Smart Meter?! Than the Plugwise will likely do something similar to make smart meter readings actually readable ;-)

     

    here's the lua code with many thanks to Mr. Hekker's blog:

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    I have the idea that the json string of p1monitor is changed after a few versions.

    But i don't know how to change the lua script for the new json string.

     

     

     

    the old have this names:

    Please login or register to see this code.

    and the new have this:

     

    API lijst
    1. Please login or register to see this link.

    2. Please login or register to see this link.

    3. Please login or register to see this link.

    4. Please login or register to see this link.

    5. Please login or register to see this link.

    6. Please login or register to see this link.

    7. Please login or register to see this link.

    8. Please login or register to see this link.

    9. Please login or register to see this link.

    10. Please login or register to see this link.

    11. Please login or register to see this link.

    12. Please login or register to see this link.

    13. Please login or register to see this link.

    14. Please login or register to see this link.

    15. Please login or register to see this link.

    16. Please login or register to see this link.

    17. Please login or register to see this link.

    18. Please login or register to see this link.

    19. Please login or register to see this link.

    20. Please login or register to see this link.

    21. Please login or register to see this link.

    22. Please login or register to see this link.

    23. Please login or register to see this link.

    24. Please login or register to see this link.

    25. Please login or register to see this link.

    26. Please login or register to see this link.

    27. Please login or register to see this link.

    28. Please login or register to see this link.

    29. Please login or register to see this link.

    30. Please login or register to see this link.

    31. Please login or register to see this link.

    32. Please login or register to see this link.

    33. Please login or register to see this link.

    34. Please login or register to see this link.

    35. Please login or register to see this link.

    36. Please login or register to see this link.

    37. Please login or register to see this link.

    38. Please login or register to see this link.

    39. Please login or register to see this link.

    40. Please login or register to see this link.

    41. Please login or register to see this link.

    42. Please login or register to see this link.

    43. Please login or register to see this link.

    44. Please login or register to see this link.

    45. Please login or register to see this link.

    46. Please login or register to see this link.

    47. Please login or register to see this link.

    48. Please login or register to see this link.

    49. Please login or register to see this link.

    50. Please login or register to see this link.

    51. Please login or register to see this link.

    52. Please login or register to see this link.

    53. Please login or register to see this link.

    54. Please login or register to see this link.

    Link to comment
    Share on other sites

    Last week i created the scriot below and works with the latest version.

     

     

    --[[
    %% properties
    %% events
    %% globals
    --]]
    -- Virtual device id
    vDevId = 71
    local vDevId = fibaro:getSelfId(); 

    --fibaro:debug(vDevId);  

    -- url van PI met meterconnectie
    PI1 = Net.FHttp("ipadres");
    PI1:setBasicAuthentication("smile", "id nummer smile");
     
    -- ophalen JSON info
    response, status, errorCode = PI1:GET("/core/modules");
    --fibaro:debug(response);
    --fibaro:debug(status);
    --fibaro:debug(errorCode);

    -- Meter info ophalen
    local a = string.match(response, "^.+<vendor_name>(.+)</vendor_name>.+$");
    local b = string.match(response, "^.+<vendor_model>(.+)</vendor_model>.+$");
    local c = string.match(response, "^.+<modified_date>(.+)</modified_date>.+$");
    local d = string.match(response, "^.+<created_date>(.+)</created_date>.+$");

    --fibaro:debug("vendor name :" .. a);
    --fibaro:debug("vendor_model :" .. b);
    --fibaro:debug("modified date :" .. c);
    --fibaro:debug("created date :" .. d);

    local e = string.match(response, "unit='W' directionality='consumed'>(.+)</measurement>.+$")
    local VerbruikActueel= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='W' directionality='produced'>(.+)</measurement>.+$")
    local LeveringActueel= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='consumed' tariff_indicator='nl_peak'>(.+)</measurement>.+$")
    local VerbruikHoog= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='consumed' tariff_indicator='nl_offpeak'>(.+)</measurement>.+$")
    local VerbruikLaag= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='produced' tariff_indicator='nl_peak'>(.+)</measurement>.+$")
    local LeveringHoog= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='produced' tariff_indicator='nl_offpeak'>(.+)</measurement>.+$")
    local LeveringLaag= string.match(e, "(%d+.%d+)");

    -- totaal tellers (dag+nacht-teruglevering)
    local ActueelTotaal = VerbruikActueel - LeveringActueel
    local MeterTotaal = VerbruikHoog + VerbruikLaag - LeveringHoog - LeveringLaag

    -- omzetten naar decimalen
    local VerbruikActueel = tonumber(string.match(VerbruikActueel, '%d+'))
    local LeveringActueel = tonumber(string.match(LeveringActueel, '%d+'))
    local VerbruikHoog = tonumber(string.match(VerbruikHoog, '%d+'))/1000
    local VerbruikLaag = tonumber(string.match(VerbruikLaag, '%d+'))/1000
    local LeveringHoog = tonumber(string.match(LeveringHoog, '%d+'))/1000
    local LeveringLaag = tonumber(string.match(LeveringLaag, '%d+'))/1000
    local ActueelTotaal = tonumber(string.match(ActueelTotaal, '%d+'))
    local MeterTotaal = tonumber(string.match(MeterTotaal, '%d+'))/1000

    -- afronden op 2 decimalen
    local VerbruikHoog = string.format("%.2f", VerbruikHoog)
    local VerbruikLaag = string.format("%.2f", VerbruikLaag)
    local LeveringHoog = string.format("%.2f", LeveringHoog)
    local LeveringLaag = string.format("%.2f", LeveringLaag)
    local MeterTotaal = string.format("%.2f", MeterTotaal)

    --fibaro:debug("Elektriciteit actueel verbruik :" .. VerbruikActueel);
    --fibaro:debug("Elektriciteit actueel levering :" .. LeveringActueel);
    --fibaro:debug("Elektriciteit Meter verbruik Hoog :" .. VerbruikHoog);
    --fibaro:debug("Elektriciteit Meter verbruik Laag :" .. VerbruikLaag);
    --fibaro:debug("Elektriciteit Meter levering Hoog :" .. LeveringHoog);
    --fibaro:debug("Elektriciteit Meter levering Laag :" .. LeveringLaag);
    fibaro:debug("Elektriciteit Meter Actueel Totaal :" .. ActueelTotaal);
    --fibaro:debug("Elektriciteit Meter Totaal :" .. MeterTotaal);

    -- update virtual device
    fibaro:call(vDevId, "setProperty", "ui.ActueelTotaal.value", ActueelTotaal.." Watt");
    fibaro:call(vDevId, "setProperty", "ui.MeterTotaal.value", MeterTotaal.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.VerbruikHoog.value", VerbruikHoog.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.VerbruikLaag.value", VerbruikLaag.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.LeveringHoog.value", LeveringHoog.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.LeveringLaag.value", LeveringLaag.." kWh");

    -- ff 3 seconden slapen
    fibaro:sleep(3000)
     

    Link to comment
    Share on other sites

    On 1/1/2020 at 3:19 PM, MichelVuik said:

    Last week i created the scriot below and works with the latest version.

     

     

    --[[
    %% properties
    %% events
    %% globals
    --]]
    -- Virtual device id
    vDevId = 71
    local vDevId = fibaro:getSelfId(); 

    --fibaro:debug(vDevId);  

    -- url van PI met meterconnectie
    PI1 = Net.FHttp("ipadres");
    PI1:setBasicAuthentication("smile", "id nummer smile");
     
    -- ophalen JSON info
    response, status, errorCode = PI1:GET("/core/modules");
    --fibaro:debug(response);
    --fibaro:debug(status);
    --fibaro:debug(errorCode);

    -- Meter info ophalen
    local a = string.match(response, "^.+<vendor_name>(.+)</vendor_name>.+$");
    local b = string.match(response, "^.+<vendor_model>(.+)</vendor_model>.+$");
    local c = string.match(response, "^.+<modified_date>(.+)</modified_date>.+$");
    local d = string.match(response, "^.+<created_date>(.+)</created_date>.+$");

    --fibaro:debug("vendor name :" .. a);
    --fibaro:debug("vendor_model :" .. b);
    --fibaro:debug("modified date :" .. c);
    --fibaro:debug("created date :" .. d);

    local e = string.match(response, "unit='W' directionality='consumed'>(.+)</measurement>.+$")
    local VerbruikActueel= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='W' directionality='produced'>(.+)</measurement>.+$")
    local LeveringActueel= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='consumed' tariff_indicator='nl_peak'>(.+)</measurement>.+$")
    local VerbruikHoog= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='consumed' tariff_indicator='nl_offpeak'>(.+)</measurement>.+$")
    local VerbruikLaag= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='produced' tariff_indicator='nl_peak'>(.+)</measurement>.+$")
    local LeveringHoog= string.match(e, "(%d+.%d+)");
    local e = string.match(response, "unit='Wh' directionality='produced' tariff_indicator='nl_offpeak'>(.+)</measurement>.+$")
    local LeveringLaag= string.match(e, "(%d+.%d+)");

    -- totaal tellers (dag+nacht-teruglevering)
    local ActueelTotaal = VerbruikActueel - LeveringActueel
    local MeterTotaal = VerbruikHoog + VerbruikLaag - LeveringHoog - LeveringLaag

    -- omzetten naar decimalen
    local VerbruikActueel = tonumber(string.match(VerbruikActueel, '%d+'))
    local LeveringActueel = tonumber(string.match(LeveringActueel, '%d+'))
    local VerbruikHoog = tonumber(string.match(VerbruikHoog, '%d+'))/1000
    local VerbruikLaag = tonumber(string.match(VerbruikLaag, '%d+'))/1000
    local LeveringHoog = tonumber(string.match(LeveringHoog, '%d+'))/1000
    local LeveringLaag = tonumber(string.match(LeveringLaag, '%d+'))/1000
    local ActueelTotaal = tonumber(string.match(ActueelTotaal, '%d+'))
    local MeterTotaal = tonumber(string.match(MeterTotaal, '%d+'))/1000

    -- afronden op 2 decimalen
    local VerbruikHoog = string.format("%.2f", VerbruikHoog)
    local VerbruikLaag = string.format("%.2f", VerbruikLaag)
    local LeveringHoog = string.format("%.2f", LeveringHoog)
    local LeveringLaag = string.format("%.2f", LeveringLaag)
    local MeterTotaal = string.format("%.2f", MeterTotaal)

    --fibaro:debug("Elektriciteit actueel verbruik :" .. VerbruikActueel);
    --fibaro:debug("Elektriciteit actueel levering :" .. LeveringActueel);
    --fibaro:debug("Elektriciteit Meter verbruik Hoog :" .. VerbruikHoog);
    --fibaro:debug("Elektriciteit Meter verbruik Laag :" .. VerbruikLaag);
    --fibaro:debug("Elektriciteit Meter levering Hoog :" .. LeveringHoog);
    --fibaro:debug("Elektriciteit Meter levering Laag :" .. LeveringLaag);
    fibaro:debug("Elektriciteit Meter Actueel Totaal :" .. ActueelTotaal);
    --fibaro:debug("Elektriciteit Meter Totaal :" .. MeterTotaal);

    -- update virtual device
    fibaro:call(vDevId, "setProperty", "ui.ActueelTotaal.value", ActueelTotaal.." Watt");
    fibaro:call(vDevId, "setProperty", "ui.MeterTotaal.value", MeterTotaal.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.VerbruikHoog.value", VerbruikHoog.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.VerbruikLaag.value", VerbruikLaag.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.LeveringHoog.value", LeveringHoog.." kWh");
    fibaro:call(vDevId, "setProperty", "ui.LeveringLaag.value", LeveringLaag.." kWh");

    -- ff 3 seconden slapen
    fibaro:sleep(3000)
     

    is this code for p1monitor or the plugwise smile? 

     

    i like to connect my raspberrypi with p1monitor to my hc2. 

    so my totalpower usage from the meter is displayed on the original page of the hc2.

    Link to comment
    Share on other sites

    On 5/27/2018 at 10:20 PM, ReneNL said:

    Hi @evanbeem,

     

    I use something similar. What I have done is the following. Basic idea is to use one of the z-wave modules which does not have an actual power usage measurement to store/report the difference between the total actual power (W) as reported by the p1/smartmeter and the total power usage as reported by the other zwave modules. This way fibaro will report the correct total kW/kWh, etc.

     

    I have added some lines in your lua script to make this happen. I made edits line 45-63.

    ...


    hi Rene,

     

    do you still have this working on your Raspberry PI ?

    Link to comment
    Share on other sites

    3 hours ago, ReneNL said:

    Yup, still working perfectly. 

    what software and version do you have on the raspberry pi?

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...