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
 Share

Recommended Posts

Hi Eddy,

Thanks for the reply, however I am not a programmer like you so where should I put that?

The VD gets the values from the variables in that strange long way..

 

Eric

Link to comment
Share on other sites

3 minutes ago, Wiers99 said:

however I am not a programmer

My neither 

 

Can you post the code you use? Then we can insert the example code "prod_high = string.format("%.3f", prod_high)" in the right place and context.

 

 

 

 

 

Link to comment
Share on other sites

 

Hi Eddy,

 

Here the LUA from the main loop.

588 is my VD with gives me the info from the variables which are pushed from Domiticz-Fibarolink.

590 is my dummy Poer switch which I only use to get the energy readings in the Fibaro Energy Panel.

As you can see in my previous post, I can see The "Stroom"  and other readings in a label but with a weird long number.

I wand a Clean nummer to read and then send that to my dummy switch.

 

 

 

fibaro:call(588, "setProperty", "ui.Label1.value", tostring(fibaro:getGlobalValue("Gas")));
fibaro:call(588, "setProperty", "ui.Label2.value", tostring(fibaro:getGlobalValue("KamerTemp")));
fibaro:call(588, "setProperty", "ui.Label3.value", tostring(fibaro:getGlobalValue("Stroom")));
fibaro:call(588, "setProperty", "ui.Label4.value", tostring(fibaro:getGlobalValue("Water")));

-- START OF LINES I ADDED
--  local i=0
--    local total_devices = 0
--    local maxNodeID = 350 -- maximum node ID in your z-wave network
--    local deviceValue = 0
--    local delta_power = 0
--    local powerID = 590 -- change to ID where you want to capture the 'delta' power

--    for i = 0, maxNodeID do
--        if fibaro:get(i, 'power') ~= nil and i~=powerID then
--            deviceValue = fibaro:get(i, 'power')
 --           total_devices = total_devices + deviceValue 
--        end
--    end

--    delta_power = tonumber(Stroom) - total_devices
    --fibaro:debug(delta_power)
--    api.put("/devices/"..powerID, {["properties"]={["power"]=delta_power}})
-- END OF LINES I ADDED

And here is the VD I use

Please login or register to see this attachment.

Link to comment
Share on other sites

Should be something like this, to prevent the weird numbers:

 

5 hours ago, Wiers99 said:

fibaro:call(588, "setProperty", "ui.Label1.value", string.format("%.3f", fibaro:getGlobalValue("Gas")));
fibaro:call(588, "setProperty", "ui.Label2.value", string.format("%.3f", fibaro:getGlobalValue("KamerTemp")));
fibaro:call(588, "setProperty", "ui.Label3.value", string.format("%.3f", fibaro:getGlobalValue("Stroom")));
fibaro:call(588, "setProperty", "ui.Label4.value", string.format("%.3f", fibaro:getGlobalValue("Water")));

-- START OF LINES I ADDED
--  local i=0
--    local total_devices = 0
--    local maxNodeID = 350 -- maximum node ID in your z-wave network
--    local deviceValue = 0
--    local delta_power = 0
--    local powerID = 590 -- change to ID where you want to capture the 'delta' power

--    for i = 0, maxNodeID do
--        if fibaro:get(i, 'power') ~= nil and i~=powerID then
--            deviceValue = fibaro:get(i, 'power')
 --           total_devices = total_devices + deviceValue 
--        end
--    end

--    delta_power = tonumber(Stroom) - total_devices
    --fibaro:debug(delta_power)
--    api.put("/devices/"..powerID, {["properties"]={["power"]=delta_power}})
-- END OF LINES I ADDED

 

(If you want two decimals, just change the 3f in a 2f)

Link to comment
Share on other sites

That worked on the "normal" numbers and I can adjust it like you mentioned.

However the "Stroom" and "Kamertemp" are send by Domoticz by a strange "%20" at the end.

How can I clean that up?

 

2021-11-04 20:27:57.274 FibaroLink: sending global variable Water with value: 184330
2021-11-04 20:28:00.690 FibaroLink: sending global variable Stroom with value: 425.0%20Watt
2021-11-04 20:28:00.739 FibaroLink: sending global variable Gas with value: 344.435
 

 

Link to comment
Share on other sites

Looks like a space character. If Domoticz can’t solve it, you could solve it more the hard way 😃

 

Stroom = string.gsub( “”, ”%%20”, Stroom)

 

Put it on top of the code 🤞🏻
 

 

 

Edited by SmartHomeEddy
Link to comment
Share on other sites

@Wiers99 Looks like the quotes aren’t ok. I think the forum messes them up. 
 

Please replace the quotes with the double quotes.

(Two double quotes before the komma and double quotes around the %%20)

 

 

 

Edited by SmartHomeEddy
Link to comment
Share on other sites

  • 4 weeks later...

Hi Eddy, sorry for the late reaction but have been rather busy lately.

Putting double quotes gave me the following debug:

 

[ERROR] 11:19:22: line 2: unexpected symbol near '%'
 

I have been using the modified "slimme meter" VD instead and that works OK but because of my TOON keeps restarting and sometimes disconnecting from my wifi, the VD stops working.

Also there is too much information in the VD, I only need the Stroom usage to display.

This is what works so far...

 

--  Toon Data v0.23 for a rooted toon by fkruis ™.
--  fill in the headers the ip and port number of your toon (port number is normally 10080 or 80).

---------------------------- user adjustable parameters ----------------------------------------------
local Standaard_debug_info  = false; -- Debug in geel.
local Extra_debug_info      = true;  -- Debug in oranje.
local Test_debug_info       = false; -- Debug in rood.                 -- polling time, default is 1 minute
local SleepTime = 10;                -- polling time, default is 10 minutes

------------------ local settings ----------------------------
local ThisModule=fibaro:getSelfId();
local _IPAddress = fibaro:getValue(ThisModule, "IPAddress" );
local _TCPPort = fibaro:getValue(ThisModule, "TCPPort" );
Toon = Net.FHttp( _IPAddress, tonumber( _TCPPort ));
local ElecUsage = 0;
local ElecProduction = 0;
local ElecDeliveredNt = 0;
local ElecDeliveredLt = 0;
local TotalElecDelivered  = 0;
local GasUsage = 0;
local TotalGasUsage =0;
local Date = os.date("%d-%m-%Y");
local Time = os.date("%H:%M:%S");

--------------------- funcions -------------------------------
Debug = function ( Kleur, Bericht )
 fibaro:debug( string.format("<%s style='color:%s;'>%s</%s>", "span", Kleur, Bericht, "span" ) ); 
end
  
Standaard_debug = function ( Bericht )
if ( Standaard_debug_info )
   then Debug( "yellow", Bericht);
 end
end
  
Extra_debug = function ( Bericht )
if ( Extra_debug_info )
   then Debug( "orange", Bericht);
 end
end

Test_debug = function ( Bericht )
if ( Test_debug_info )
   then Debug( "red", Bericht );
 end
end 

--------------------- begin scene ---------------------------
Test_debug(" The ThisModule value is ".. ThisModule );
Test_debug(" The _IPAdress value is " .. _IPAddress );
Test_debug(" The _TCPPort value is " .. _TCPPort );

---------- getting elec_quantity_ntdsta from toon -----------
local response, status, errorcode = Toon:GET( "/hcb_rrd?action=getRrdData&loggerName=elec_quantity_nt&rra=5yrhours&readableTime=1&nullForNaN=1&samples=1&from=".. Date .."" );

if errorcode == 0
   then fibaro:log(" Verbonden " );
        Test_debug(" The status value of Toon:GET is " .. status );
        else Test_debug (" The errorcode of Toon:GET is " .. errorcode );
             fibaro:log (" Verbindings fout! " );
             Extra_debug(" There is no connection with toon! please check your settings " );
             _abort = true;
end
if _abort
   then Extra_debug (" The Scene is stopped because of error " .. errorcode )
        fibaro:log  (" The Scene is stopped" );
        fibaro:abort()
end
Standaard_debug (" The response values of Toon:hcb_rrd are ".. response );

local response = ( response:gsub(".*:",""))
local response = ( response:gsub("}",""))
local ElecDeliveredNt = response

---------- getting elec_quantity_lt dsta from toon ----------
local response, status, errorcode = Toon:GET( "/hcb_rrd?action=getRrdData&loggerName=elec_quantity_lt&rra=5yrhours&readableTime=1&nullForNaN=1&samples=1&from=".. Date );

if errorcode == 0
   then fibaro:log(" Verbonden " );
        Test_debug(" The status value of Toon:GET is " .. status );
        else Test_debug (" The errorcode of Toon:GET is " .. errorcode );
             fibaro:log (" Verbindings fout! " );
             Extra_debug(" There is no connection with toon! please check your settings " );
             _abort = true;
end
if _abort
   then Extra_debug (" The Scene is stopped because of error " .. errorcode )
        fibaro:log  (" The Scene is stopped" );
        fibaro:abort()
end
Standaard_debug (" The response values of Toon:hcb_rrd are ".. response );

local response = ( response:gsub(".*:",""))
local response = ( response:gsub("}",""))
local ElecDeliveredLt = response
local TotalElecDelivered = ElecDeliveredNt + ElecDeliveredLt;

------------------- Debug ------------------------------------
Extra_debug (" The value of ElecDeliveredNt is " .. ElecDeliveredNt .."" )
Extra_debug (" The value of ElecDeliveredLt is " .. ElecDeliveredLt .."" )
Extra_debug (" The value of TotalElecDelivered is " .. TotalElecDelivered.."" )

---------- Getting GetCurrentUsage data from toon -----------
local response, status, errorcode = Toon:GET( "/happ_pwrusage?action=GetCurrentUsage" );

if errorcode == 0
   then fibaro:log(" Verbonden " );
        Test_debug(" The status value of Toon:GET is " .. status );
        else Test_debug (" The errorcode of Toon:GET is " .. errorcode );
             fibaro:log (" Verbindings fout! " );
             Extra_debug(" There is no connection with toon! please check your settings " );
             _abort = true;
end
if _abort
   then Extra_debug(" The Scene is stopped because of error " .. errorcode )
        fibaro:log (" The Scene is stopped" );
        fibaro:abort()
end
Standaard_debug (" The response values of Toon:GetCurrentUsage are ".. response );
local JsonToon = json.decode(response);

------------ converting toon data ---------------------------
local ElecUsage =(JsonToon.powerUsage.value);
local ElecProduction = (JsonToon.powerProduction.value);
local GasUsage = (JsonToon.gasUsage.value);
fibaro:debug (GasUsage)
if (JsonToon.gasUsage.value == json.null)
    then GasUsage = 0;
end

------------------- Debug -----------------------------------
Extra_debug(" The value of Electricity Usage is " .. ElecUsage )
Extra_debug(" The value of Electricity Production is " .. ElecProduction )
Extra_debug(" The value of Gas Usage is " .. GasUsage )

--------- Getting gas_quantity data from toon ---------------
local response, status, errorcode = Toon:GET( "/hcb_rrd?action=getRrdData&loggerName=gas_quantity&rra=5yrhours&readableTime=1&nullForNaN=1&samples=1&from=".. Date );

if errorcode == 0
   then fibaro:log(" Verbonden " );
        Test_debug(" The status value of Toon:GET is " .. status );
        else Test_debug (" The errorcode of Toon:GET is " .. errorcode );
             fibaro:log (" Verbindings fout! " );
             Extra_debug(" There is no connection with toon! please check your settings " );
             _abort = true;
end
if _abort
   then Extra_debug(" The Scene is stopped because of error " .. errorcode )
        fibaro:log (" The Scene is stopped " );
        fibaro:abort()
end
Standaard_debug (" The response values of Toon:/hcb_rrd are ".. response );

---------------- converting toon data  ----------------------
local response = (response:gsub(".*:",""))
local response = (response:gsub("}",""))
local response = (response:gsub("null","0"))
local TotalGasUsage = (response)

------------------- Debug -----------------------------------
Extra_debug (" The value of TotalGasUsage is " .. TotalGasUsage )

------------------ Set property labels -----------------------
fibaro:call(fibaro:getSelfId(),"setProperty","ui.ElecUsage.value",tostring(ElecUsage ));
fibaro:call(fibaro:getSelfId(),"setProperty","ui.ElecProduction.value",tostring(ElecProduction));
fibaro:call(fibaro:getSelfId(),"setProperty","ui.ElecDeliveredNt.value",tostring(ElecDeliveredNt ));
fibaro:call(fibaro:getSelfId(),"setProperty","ui.ElecDeliveredLt.value",tostring(ElecDeliveredLt));
fibaro:call(fibaro:getSelfId(),"setProperty","ui.TotalElecDelivered.value",tostring(TotalElecDelivered, "KWH"));
fibaro:call(fibaro:getSelfId(),"setProperty","ui.GasUsage.value",tostring(GasUsage));
fibaro:call(fibaro:getSelfId(),"setProperty","ui.TotalGasUsage.value",tostring(TotalGasUsage));
fibaro:call(fibaro:getSelfId(),"setProperty","ui.RefreshTime.value",tostring( Time ));
----------------------------- wait time until next polling --------------------------------

fibaro:sleep(12000);

-- START OF LINES I ADDED
  local i=0
    local total_devices = 0
    local maxNodeID = 350 -- maximum node ID in your z-wave network
    local deviceValue = 0
    local delta_power = 0
    local powerID = 590 -- change to ID where you want to capture the 'delta' power

    for i = 0, maxNodeID do
        if fibaro:get(i, 'power') ~= nil and i~=powerID then
            deviceValue = fibaro:get(i, 'power')
            total_devices = total_devices + deviceValue 
        end
end

    delta_power = tonumber(ElecUsage) - total_devices
    fibaro:debug(delta_power)
    api.put("/devices/"..powerID, {["properties"]={["power"]=delta_power}})
-- END OF LINES I ADDED

 

 

This gives me a working energy panel in the fibaro app with an update every 20 seconds until the the wifi from TOON disconnects or a fault with "Elecproduction" kicks in.

I tried to remove as much as possible information which I do not need but than the VD stops working.

Can this VD be modified into something simple so that it only gives me the "ElecUsage"?

 

Thanks

Eric

Link to comment
Share on other sites

Eddy, your my hero!

 

Working great so far.

Now waiting how the connection with the TOON holds up.

 

Thanks for helping me out.

 

Eric

  • Like 1
Link to comment
Share on other sites

It is working great until it disconnects from TOON due to some hiccup.

Then I have to restart?save the VD and it is back to normal.

I there  a simple solution so that it is trying to reconnect when the connection with TOON temporarily stops?

 

 

Please login or register to see this attachment.

Link to comment
Share on other sites

@Wiers99 Not that familiar with the VD’s. I would delete (put comment -- in front of it) this code:

 

Please login or register to see this code.


or comment out

Please login or register to see this code.

 

 

Edited by SmartHomeEddy
  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Still working great!

Found the problem with the constant  restarting Toon, it was the app that monitors the Boilerstatus.

This was overflowing the memory so it kept restarting and made the Toon very slow to react.

So I removed the app and now hardly any restarts and a quick responding Toon.

 

Still a question:

 

Can I Turn on the "show energy consumption measurements" on the individual light switches etc without adding this to the total consumption of the dummy?

Will this part     (delta_power = tonumber(ElecUsage) - total_devices) in the VD take care of it?

Because I like it when you can see also the individual power consumption of the switches etc.

Link to comment
Share on other sites

good to hear it works and Toon is running ok again

 

4 hours ago, Wiers99 said:

Can I Turn on the "show energy consumption measurements" on the individual light switches etc without adding this to the total consumption of the dummy?

Will this part     (delta_power = tonumber(ElecUsage) - total_devices) in the VD take care of it?

Because I like it when you can see also the individual power consumption of the switches etc.

 

yes,

 

in this part:

(delta_power = tonumber(ElecUsage) - total_devices)

the energy usage from all your power consumption devices is deducted from the Toon measured total energy consumption (to put the “rest” energy consumption, not directly recorded by the HC2, in a “spair” device).
 

So the HC2 can show all energy usage from power devices and the from your “spair” device with the “rest” power consumption. 

 

 

  • Like 1
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.

 Share

×
×
  • Create New...