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
Posted

That was what I had in mind to try.

Please login or register to see this image.

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

Only one question what does the  end,5000)

Not shore what you mean by “what dose the end,5000).

If you mean what does it do. It’s part of the 5 second "setTimeout" delay function.

 

setTimeout(function()

                Your code to run after the delay (1000 = 1 second)

end,5000)

  • 0
Posted

Have you tried to send request only?

 

HC2 = Net.FHttp('192.168.0.15'
res, status, err = HC2:GET("/iungo/api_request/")
  • 0
  • Inquirer
  • Posted

     

    Have you tried to send request only?

     

    HC2 = Net.FHttp('192.168.0.15'
    res, status, err = HC2:GET("/iungo/api_request/")

     

    Hi cag014

     

    Tried the following script:

     

    HC2 = Net.FHttp('192.168.0.15') 
    res, status, err = HC2:GET("/iungo/api_request/")
    fibaro:debug(res)
    fibaro:debug(status)
    fibaro:debug(err)
     
    No response at all and no error.
    • 0
  • Inquirer
  • Posted

     

    Not shore what you mean by “what dose the end,5000).

    If you mean what does it do. It’s part of the 5 second "setTimeout" delay function.

     

    setTimeout(function()

                    Your code to run after the delay (1000 = 1 second)

    end,5000)

     

    Stupid me. 

    Completely missed the 2x  setTimeout(function() in your script John.

    Get direct an error on the first 

                                                  setTimeout(function()

    [ERROR] 19:50:39: line 9: attempt to call global 'setTimeout' (a nil value)

    • 0
    Posted
    --SMARTMETER 538d72d9

    local smartmeter= Net.FHttp('192.168.0.15');

    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[2].value

          T1=jTe.rv.propsval[3].value

          T2=jTe.rv.propsval[4].value

          L1I=jTe.rv.propsval[7].value

          gas_usage=jTe.rv.propsval[11].value

          gas=jTe.rv.propsval[12].value

     
    fibaro:sleep(5000)

    --WATERMETER 0908f9a8

    --local watermeter= Net.FHttp('192.168.0.15');

    --response,status,errorCode = watermeter:POST("/iungo/api_request/", '{"seq":1,"method":"object_list_props_values","arguments":{"oid":"0908f9a8"}}')

    response,status,errorCode = smartmeter:POST("/iungo/api_request/", '{"seq":1,"method":"object_list_props_values","arguments":{"oid":"0908f9a8"}}')
    local jTw = json.decode(response)

          flow=jTw.rv.propsval[1].value

          pulstotal=jTw.rv.propsval[2].value

          kfact=jTw.rv.propsval[3].value

          wused=pulstotal/kfact

           

    -- deviceid 99 Iungo VD

    fibaro:call(99, "setProperty", "ui.Label1.value", usage.." Watt")

    fibaro:call(99, "setProperty", "ui.Label2.value", T1.." kWh")

    fibaro:call(99, "setProperty", "ui.Label3.value", T2.." kWh")

    fibaro:call(99, "setProperty", "ui.Label4.value", L1I.." Amp")

    fibaro:call(99, "setProperty", "ui.Label5.value", gas_usage.." m3")

    fibaro:call(99, "setProperty", "ui.Label6.value", gas.." m3")

    fibaro:call(99, "setProperty", "ui.Label7.value", flow.." liter/min")

    fibaro:call(99, "setProperty", "ui.Label8.value", wused.." m3")

    fibaro:log("T1n : "..T1.." kWh - T2d : "..T2.." kWh - Gas :"..gas.." m3")

     

    fibaro:sleep(5000)

    Sorry Jack looks like you can't use setTimeout in vertical devices.

    I have edited the above code for you.

    • 0
  • Inquirer
  • Posted

     

    when i built my own virtual device for energy reading, i remember it stopped after few minutes...

    sadly, i don't remember what i did to correct it

     

    looking at my code and comparing it to yours, i can see that i put the Net.Fhttp statement in an if clause, to avoid opening sockets continuosly:

    Please login or register to see this code.

    Hi onesim,

     

    I have created a new VD to test your code. 

    There was only one bracket to much between the "if" and the "tonumber".

    It's running now. Let's see if it stops, or stay running.

     

    Jack

    • 0
  • Inquirer
  • Posted

    Sorry Jack looks like you can't use setTimeout in vertical devices.

    I have edited the above code for you.

    NP John,

    It's a learning curve for me

    Please login or register to see this image.

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

    I have now restructured the code first in a logical order, with still one fibaro:sleep moment.

    Test is running. If it stops again, I activate the second sleep moment.

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    @onesim

    It looks like your suggested code did the job.

    The new created VD, although only with the "usage" value, worked since it started yesterday evening.

    I just created the full script now, for all the values, like in the first VD.

    At this moment the ony thing I can do is wait 

    Please login or register to see this image.

    /emoticons/default_icon_razz.gif" alt=":-P" /> 

    • 0
  • Inquirer
  • Posted
    LOL

    Firmware upgrade of the energy manager is messing up the values at Water flow and Water used.

    There is a very technical unexpected solution to solve this.

    It will be hard to guess what this solution is. 

    • 0
    Posted

    @onesim

    It looks like your suggested code did the job.

    The new created VD, although only with the "usage" value, worked since it started yesterday evening.

    I just created the full script now, for all the values, like in the first VD.

    At this moment the ony thing I can do is wait 

    Please login or register to see this image.

    /emoticons/default_icon_razz.gif" alt=":-P" /> 

     

    My VD never stopped since i starded it more than one month ago...

    • 0
  • Inquirer
  • Posted

    My VD never stopped since i starded it more than one month ago...

    VD is running like a charm with your suggested code. Thanks onesim.

     

    Next step is to set the "usage" value to powerConsumption on double relay switch FGS222 to show the power usage in the Energy Panel

    • 0
  • Inquirer
  • Posted

    VD running smoothly 

    Please login or register to see this image.

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

    Please login or register to see this code.

    Please login or register to see this code.

    • 2
  • Inquirer
  • Posted

    Version 1.3.

     

    Added:

    Total energy usages from the Smart Meter, minus the energy values from all z-wave devices with power metering, to get the total of the remaining non measured power consumption.

    This calculated value is added to "power" of an unused relay input of a double fibaro switch. 

    Now it is shown in the energy panel and the toal enegry usages without counting values double.

    Please login or register to see this code.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    • Thanks 1
    • 0
    Posted

    this is the missing link! 

     

    I'm working on adding a module to read-out the Smile P1 smart meter interface. I'm up to the point were I've already got the meter readings in a variable in the VD. Looking good!

     

    ps. used the lua code of Robert Hekkers.

     

    cheers

    emiel

    • 0
  • Inquirer
  • Posted

    Thanks Emiel,

    With the help of this forum, it's members and Iungo, I was able to create this solution.

    It took some time to create my first real lua code, but I like learning it this way.

    Next challenge is already started. Get data via ModBus TCP IP.

    EDIT:

    It seems that I earned Stroomwafels

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    • 0
    Posted

    Hi Jack,

     

    I buy also a iungo (light), and make a VD. Everything's works perfect.
    If you have new futures, please share....

    • 0
  • Inquirer
  • Posted

    Hi Twanve

     

    Good choice the Iungo 

     

    There is a new version,

    In the new version the VD icon, a meter, will change based on the "usage" value.

     

    -- Change Icon based on the usage value 10%,30%,50%,70%,90% and 100% of 7360 Watt 32Amp at 230V
    --10% = 736W, 30% = 2208W, 50% = 3680W, 70% = 5152W, 90% = 6624W, 100% = 7360W

    Please login or register to see this code.

    Icons used

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

    You need to download these, and add them to the icons for virtual devices. Then find the number of each Icon and change the icon numbers in the above code.

    • 0
    Posted

    Yesterday the VD works great, but this morning the VD hangs, after stop en save it works again. Strange....

     

    But those icons, I load the icons up in my VD number (595), but where can I find the icon numbers

    I select one Icon in the VD, but nothing happens when the usage change.

     

    Gr. Twan

     

    ps; I have also sun panels, I must make new icons, with daylight I return power to the net 

    Please login or register to see this image.

    /emoticons/default_icon_cool.gif" alt="8-)" />

    • 0
  • Inquirer
  • Posted

    Hi Twan

     

    Right click on the Icon, and then clcik on inspect element. Then you will see in the right screen that opens the number of the icon for example

    id="Icon vdevice_icon_118" 118 is then the number you need.

     

    I am not sure what the value of "usage" will be when your solar panels return power to the grid. I asume that it will show as a negative value.

    You can add more code to have icons displayed at the moment that you are delivering back to the grid.

     

    Other suggestion could be that you use the 50% meter for 0 Watt consumed, and the icons 10% and 40% for delivering back and 70%, 90% and 100% for consumed power.

     

    Added:

     

    You can use the code below to get the Imported Power and Exported Power in kW. Multiply it by 1000 and you have watt's again.

     

    L1Pimp=jTe.rv.propsval[8].value

    L1Pexp=jTe.rv.propsval[9].value

     

    Please login or register to see this attachment.

    • 0
    Posted

    Thx, it works...

     

     

     

    Please login or register to see this attachment.

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