Jump to content
  • 0

? Reading out the all-over energy status and inputting it into HC2


Question

Hi there,

 

I just got my poweropti from https://www.powerfox.energy. This device reads out the current power consumption of the whole house via infrared on the measurement device. There is an API (German manual here) so I thought about reading this out every now and then and inputting it into my HC2, so I have the overall consumption status. 

To be honest, I have no clue on how I can do this. Here is a german manual in how to connect this to OpenHAB. Are there any similarities between OpenHAB and fibaro HC2, so I could adapt this script to my HC2?

 

Would be great if somebody could give me a hint!

 

Best regards,

Rolf

Link to post
Share on other sites

Recommended Posts

  • 1

You could start with studying this VD. I read actual power usage and put it in a “spare” device (but with a different P1 power monitor). 
 

I think with some copy, past and adjust you could get it running. 
 

 

 

Link to post
Share on other sites
  • 1

In the VD I calculate the difference between the power used by z-wave devices and the total power usage. The difference I put in a double switch (I only use one of the two) so the HC2 can use it in the energy panel. 
 

This is the line to put the power usage in a device:

 

api.put("/devices/"..powerID, {["properties"]={["power"]=delta_power}})


(powerID is the device to put the power usage in, delta_power is the variable that contains the power usage I calculated)

Link to post
Share on other sites
  • 1

I calculate the power consumption from all devices with this lines of code. (I know the total power consumption from the P1 Meter, so I can calculate the power consumption from the other devices in the house.) 

 

    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

 

I don't think, but I don't know much from Hue, Hue devices have a power property you can read out this way. 

 

Link to post
Share on other sites
  • 1
5 hours ago, Twannie said:

api.put("/devices/"..728, {["properties"]={["power"]=10}})

 

api.put("/devices/"..powerID, {["properties"]={["power"]=delta_power}})

 

They look the same. I don't think the difference in variables versus the value will change the behavior. I use(d) it in a VD (now in a QuickApp). 

Link to post
Share on other sites
  • 1

It was a VD, to measure every 10 seconds the power usage from the P1 Monitor and the power usage calculation from all devices. 

Link to post
Share on other sites
  • 1
On 11/18/2020 at 7:23 PM, Twannie said:

And what sort of device is POWERID in your case?


(it is the device where you put the power measurement in)

Link to post
Share on other sites
  • 1
18 minutes ago, rowi said:

I now get it from the server (every 3 or so seconds, can I change this?)


you can put in

fibaro:sleep(8000)

For a 8 second pauze, for example

 

20 minutes ago, rowi said:

but I can't put it as a green value in the lower left corner of the VD, so it doesn't get recognized as a value

 

maybe you have to make it a value with

delta_power = tonumber(apiResult)

 

 

Link to post
Share on other sites
  • 1

The idea is to put every for example 10 seconds the power usage of all non device consumption in a not used but active device. So you have all power consumption of your house in your homecenter. And hopefully there comes an HC3 energy panel to see all power consumption. 
 

On my HC3:
 

67D4BA82-EFD5-4888-9602-5960536CE13B.jpeg.f96e18795fcff89aa467142d766fe500.jpeg

 

 

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

I still didn't get it work. As of now I already get what I want from my energy meter, especially the current amount of Watts I'm pulling. 

I thought of simply using a http-request to the HC2 for inputting it every 10 seconds, something like described here:

 

https://manuals.fibaro.com/knowledge-base-browse/rest-api/

 

But using something like http://192.168.111.111/api/energy/now-3600/now/single/devices/power/999 just reads out from the HC2, but I need it the other way around.

 

Isn't there an easier way so even I could do this? 

Edited by rowi
Link to post
Share on other sites
  • 0

Hue devices do not have power property as far as I know

I get my total power through 2 Youless and VD's I created so I have total power, solar output and even water

There is always a difference in total power from the HC2 and the P1 port in my case because the HUE is not monitored

I notice the HUE has power so I can put it into the HUE maybe, i will try

Link to post
Share on other sites
  • 0

If I do:

api.put("/devices/"..728, {["properties"]={["power"]=10}})

that is the exact code to put 10W into device 728, right?

Link to post
Share on other sites
  • 0

It stays 0 with that code or do I have to put something above of does the HC2 LUA recognize api.put in a scene like that?

Link to post
Share on other sites
  • 0

Now I simplified the original code as much as I could to understand. I have an external server where ich can get a value (just three bytes like "123", this is the amount of watts I'm currently using in my house). I now get it from the server (every 3 or so seconds, can I change this?) but I can't put it as a green value in the lower left corner of the VD, so it doesn't get recognized as a value. I'm aware my other devices will simply add to that overall amount and I would need to subtract, but I just wanna get stared here first.

 

MyId = fibaro:getSelfId()

local PI1 = Net.FHttp("api.myserver.org", 80)
apiResult, apiStatus, apiErrorCode = PI1:GET("/watts.php");
 
if (apiStatus ~= "200") then
    fibaro:debug("Error in calling watts.php ; apiStatus "..apiStatus.."; apiErrorCode ".. apiErrorCode.."; apiResult ".. apiResult)
else
  fibaro:debug("apiResult, current consumption in W: ".. apiResult)
  powerID = MyId
  delta_power = apiResult

  -- here it should set the amount of watts currently pulled into the system variable:
  api.put("/devices/"..powerID, {["properties"]={["power"]=delta_power}})

  -- here I can see the data as "123" watts (just the number) correctly in the VD:
  fibaro:call(MyId, "setProperty", "ui.Label1.value", apiResult.." W")
  
end

 

Bildschirmfoto 2020-11-21 um 11.10.31.png

Link to post
Share on other sites
  • 0

Still doesn't work. I just have imported the .vfib from the working example, not the LUA. Is that a problem? 

I read somewhere that you need to have a "power capable device" to use power metering, so some people used another device that is capable but is not using that. I just use my virtual device, nothing else. Is that the problem?

 

I guess I'm really close to my solution, just the power consumption needs to be recognized as such in the virtual device. 

 

Anything else I can do? Also printed out the device ID, this is correct.

Maybe there's a http request where I can check the device? 

 

Edit: http://192.168.1.100/api/energy/now-3600/now/single/devices/power/234 gives me:
{"id":1,"kWh":0.0,"W":0.0,"min":0.0,"max":0.0,"avg":0.0}

 

but an existing device on ID 20 (fibaro wallplug gives me):

{"id":1,"kWh":0.03,"W":35.5,"min":17.3,"max":73.3,"avg":0.0}

 

Is this a must to fill out all of the values that it works?

 

I use the HC2, Ver 4.600

Edited by rowi
Additional info
Link to post
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
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...