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


  • 0

Energy manager connected to a smart meter, Values in a VD


Question

Posted

Just started with the HC2 and for sure completly new to LUA.
I already had an Iungo Energy manager to get the usage on electricity and gas from the smart meter, and also the water usage.
At this stage I managed to get a reponse from the energy manager, but didn't succeed to get the values for use in a virtual device.
 
I hope someone can give me a suggestion to put me in the right direction on how to get the values from the response.

Please login or register to see this code.

Response received is:

 

[DEBUG] 15:07:30: 200
[DEBUG] 15:07:30: 0

[DEBUG] 15:07:30: ENCODE RESULT :"{\"ok\":true,\"type\":\"response\",\"time\":0.001937499968335,\"rv\":{\"propsval\":[{\"id\":\"name\",\"value\":\"Smart meter\"},{\"id\":\"usage\",\"value\":362},{\"id\":\"T1\",\"value\":4113.167},{\"id\":\"T2\",\"value\":2884.556},{\"id\":\"-T1\",\"value\":0},{\"id\":\"-T2\",\"value\":0},{\"id\":\"L1I\",\"value\":1},{\"id\":\"L1Pimp\",\"value\":0.362},{\"id\":\"L1Pexp\",\"value\":0},{\"id\":\"c_tariff\",\"value\":2},{\"id\":\"gas_usage\",\"value\":0},{\"id\":\"gas\",\"value\":1681.49},{\"id\":\"Cost-T1\",\"value\":0.2166},{\"id\":\"Cost-T2\",\"value\":0.2166},{\"id\":\"Cost-nT1\",\"value\":0},{\"id\":\"Cost-nT2\",\"value\":0},{\"id\":\"Cost-gas\",\"value\":0.597},{\"id\":\"Client-blob\",\"value\":\"\"},{\"id\":\"available\",\"value\":true}]},\"systime\":1456149950,\"seq\":1,\"error\":false}"

 

Recommended Posts

  • 0
  • Inquirer
  • Posted

    Thx, it works...

    Nice one Twan.

     

    Looks like the weather isn't that bad today in Tilburg at the moment 

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    Love the Iungo as a gateway for electricity, gas and water measures, and the capability for integrating EV charging stations and heat pumps.

     

    Jack

    • 0
    Posted

    Hi Jack,

     

    Do you have the solution for the VD, that stops reporting after xx minutes.

    My VD stops after 40 minutes, when I open and save it's ok.

     

    I use no other meters, so my code is not so big.

     

    Twan

     

    -- Virtual Device: Get data from Iungo Energy manager
    -- Version       : 1.3.1
    -- Release Date  : 1.3.0  13 March 2016
    -- 15-3-2016 : 1.3.1  Added new devices
    -- Compatibility : Home Center 2, v4.070
    -- www.iungo.nl
    -- <ipiungo>/iungo/control?cmd=api_list
    --

    Please login or register to see this link.

     
     
    --SMARTMETER 538d72d9
    local smartmeter= Net.FHttp('192.xxx.xxx.xx');
    response,status,errorCode = smartmeter:POST("/iungo/api_request/", '{"seq":1,"method":"object_list_props_values","arguments":{"oid":"538d72d9"}}')
    local jTe = json.decode(response)
    usage = jTe.rv.propsval[1].value
    T1=jTe.rv.propsval[2].value
    T2=jTe.rv.propsval[3].value
    T1r=jTe.rv.propsval[4].value
    T2r=jTe.rv.propsval[5].value
    gas_usage=jTe.rv.propsval[16].value
    gas=jTe.rv.propsval[17].value
        ETotal=T1+T2-T1r-T2r
    ZTotal=T1r+T2r
      -- fibaro:setGlobal('IungoUsage', usage)
     
    if usage <0 then 
          fibaro:call(595, "setProperty", "currentIcon", "1013")
        else
    if usage >0 and usage <737 then 
          fibaro:call(595, "setProperty", "currentIcon", "1012")
         else
           if usage >736 and usage <2209 then 
             fibaro:call(595, "setProperty", "currentIcon", "1011")
           else
             if usage >2208 and usage <3681 then 
               fibaro:call(595, "setProperty", "currentIcon", "1010")
             else
               if usage >3680 and usage <5153 then 
                 fibaro:call(595, "setProperty", "currentIcon", "1009")
               else
                 if usage >5152 and usage <6625 then 
                   fibaro:call(595, "setProperty", "currentIcon", "1008")
                 else
                   if usage >6624 then 
                     fibaro:call(118, "setProperty", "currentIcon", "1007")
                   end
                 end
               end
             end
           end
         end
    end
     
    -- deviceid 595 Iungo dit VD nummer
    fibaro:call(595, "setProperty", "ui.Label1.value", usage.." Watt")
    fibaro:call(595, "setProperty", "ui.Label2.value", T1.." kWh")
    fibaro:call(595, "setProperty", "ui.Label3.value", T2.." kWh")
    fibaro:call(595, "setProperty", "ui.Label4.value", T1r.." kWh")
    fibaro:call(595, "setProperty", "ui.Label5.value", T2r.." kWh")
    fibaro:call(595, "setProperty", "ui.Label6.value", ETotal.." kWh")
    fibaro:call(595, "setProperty", "ui.Label9.value", ZTotal.." kWh")
    fibaro:call(595, "setProperty", "ui.Label7.value", gas_usage.." m3")
    fibaro:call(595, "setProperty", "ui.Label8.value", gas.." m3")
    fibaro:log("Td: "..T1.." - Tn: "..T2.." - Zon: "..ZTotal.." kWh - Gas:"..gas.." m3");
     
    fibaro:debug(usage) 
    fibaro:sleep(1000*5) --wait 5 second
    • 0
  • Inquirer
  • Posted

    Hi Twan

     

    I had the same issue in the beginning.

     

    The first part of the code needs to be the following

     

    if(HC2==nil) then
    HC2=Net.FHttp('xxx.xxx.xxx.xxx'); --IP Address Iungo
    else

     

    and then at the end of the code you need to add:   end

     

    See the code you posted with the changes below

    Please login or register to see this code.

    • 0
    Posted

    mmm, get this error: 

    [ERROR] 15:39:37: line 7: attempt to index global 'smartmeter' (a nil value)

     

    Strange; at line 7 at this moment:

    local jTe = json.decode(response)

    • 0
  • Inquirer
  • Posted

    mmm, get this error: 

    [ERROR] 15:39:37: line 7: attempt to index global 'smartmeter' (a nil value)

     

    Strange; at line 7 at this moment:

    local jTe = json.decode(response)

    Sorry HC2 in the first line must be smartmeter

    if(smartmeter==nil) then

    • 0
  • Inquirer
  • Posted

    Updated above post

    • 0
    Posted

    thx for you quick response....

     

    When I change HC2 in only this line, its not working.

     

    Now I make this below, and it runs again, pjoe:-)

    Now hopen its not freeze again.

     

    if(smartmeter==nil) then

    smartmeter=Net.FHttp('xxx.xxx.xxx.xx'); --IP Address Iungo
    else
    • 0
  • Inquirer
  • Posted

     

    thx for you quick response....

     

    When I change HC2 in only this line, its not working.

     

    Now I make this below, and it runs again, pjoe:-)

    Now hopen its not freeze again.

     

    if(smartmeter==nil) then

    smartmeter=Net.FHttp('xxx.xxx.xxx.xx'); --IP Address Iungo
    else

     

    My response was to quick, and then you make mistakes.

    Please login or register to see this image.

    /emoticons/default_icon_redface.gif" alt=":oops:" /> or forget a part. Sorry

    You already found the correct solution.

    Now it will stay up and running.

    It might stop when you are working on an other VD which runs into an error. Don't know why

    But normaly it will not freeze

    • 0
    Guest samuelboerhoop
    Posted

    good topic.

    • 0
  • Inquirer
  • Posted

    good topic.

    Thank you

    Dank u

    • 0
    Posted

    Yesterday I upgrade the iungo with a 3 phase consumption meter for Solar panels.

    This meter works with a S0 bus, to read the puls for one kWh.

     

    Now I will show the consumption for this meter with a formula. The consumption output ("Meterstand") give me "21.22383456677899"

    Is it possible, to show the output with 2 decimals?

     

    I tried this; (from

    Please login or register to see this link.

    topic), but give a error with debug

     

    fibaro:call(596, "setProperty", "ui.Label2.value", string.format ( "%6.2f", Meterstand.. " kWh"));

     

    Twan

    • 0
    Posted

    Please login or register to see this code.

    • 0
    Posted

    or try 

    fibaro:call(596, "setProperty", "ui.Label2.value", string.format( "%6.2f", tonumber(Meterstand)) .. " kWh");

    • 0
    Posted

    or try 

    fibaro:call(596, "setProperty", "ui.Label2.value", string.format( "%6.2f", tonumber(Meterstand)) .. " kWh");

     

    It's so simple for a Lua expert...

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

     

    Thx, It works....

     

    Twan

    • 0
  • Inquirer
  • Posted

    Small improvement, made the VD more reliable, and keeps it running while working on other VD's

    Changed the IP address of the HC2 to 127.0.0.1, 1111

    Removed the authentication"line "HC2:setBasicAuthentication("login","password")

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    @chatboy

    As promissed

    Please login or register to see this link.

    Please login or register to see this link.

    Have fun

    Jack

    • 0
    Posted

    After reading this... I want to buy a Iungo lite aswell.

    Nice work guys.

    • 0
    Posted

    Jack,

     

    how did you acces the IUNGO API, is there documentation? Where do I find the OID for the connected devices?

     

    thx

     

    Henk

    • 0
    Posted

    In the post jun 6 from Jack, you can download the VD. Only Change you IP iungo

    See also: http://IP_iungo/control?cmd=api_list --> object_list_props_values

    • 0
    Posted (edited)

    @twanve, correct, and this works.

    however I would like to extend the code. 

     

    Iungo supports Zwave powerplugs with metering and once connected to the gateway theorie values should also be retrievable from the API. To do that you need the unique OID for that device.

     

    therefore my question was how you could use the api to retrieve the OID's

     

    thx for the reaction though.

     

    see also for examples; 

    Please login or register to see this link.

     (sorry it is in dutch for all the international users) Not my personal website, just aan infosource.

     

     

     

    HC2 @ 4.100

    Hue inetgration

    SONOS integration

    Netatmo thermostat integration

    Logitech Harmony Hub integration

    IFTTT integration

    Edited by H.Lourens
    Clarification

    Join the conversation

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

    Guest
    Answer this question...

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