We have moved at community.getvera.com

Author Topic: emoncms link to vera edge ui7  (Read 4229 times)

Offline Velectris

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
emoncms link to vera edge ui7
« on: October 13, 2015, 06:34:54 pm »
Hi to all,

As i need a perfect visual handling of my energy ( solar pv production and general energy monitoring ), i choosed emoncms as visualisation mode.
I'm not familiar with lua programming, but i have some code running for a vera 3 ui5, and i try to tranpose, for the moment with no sucsess.
I have two owl cm160 plugs mesuring my pv and genral power thrue a rfxtrx, and this is running fine.
Here is the code i use for a scene wich is posting my data to emoncms every minute :

local id = 25
local type = "urn:schemas-micasaverde-com:device:PowerMeter:1"
local fields = {"Watts", "KWH"}
local apikey = "95fe5bdb8f6f28cefdbdbbddd6c1315c"
local voltage = 225
 
for i,field in ipairs(fields) do
  local value = luup.variable_get(type, field, id)
  value = tostring(value)
 
  luup.inet.wget("http://emoncms/input/post.json?node=0&json={"..field..":"..value.."}&apikey="..apikey)
 
  if field == "Watts" then
    local iinst = tostring(luup.variable_get(type, field, id) / voltage)
    luup.inet.wget("http://emoncms/input/post.json?node=0&json={IINST:"..iinst.."}&apikey="..apikey)
  end
end

I have no error message, the scene is running fine, but i have no value stored in my emoncms acount....

Is it possible to have some help to find what is wrong in my code, or at least a debug feature ?

If someone can send me code for at least one variable, i could accomodate by running two scenes, one for watts and one for kwh, but for now, i'm in the fog !  ;D

I think emoncms is a very good solution to value energy data, so i will swap for another system if it is not possible to link with vera, but i think vera is also a good system, so i want best of both worlds.   8)

Thanks on advance for any help !

Offline cybrmage

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1104
  • Karma: +113/-43
Re: emoncms link to vera edge ui7
« Reply #1 on: October 13, 2015, 08:28:55 pm »
I took a quick look at the documentation for posting data... and it appears that they use a "json like" data format and not true json...

Try changing your wget command to:
Code: [Select]
luup.inet.wget("http://emoncms/input/post.json?node=0&json="..field..":"..value.."&apikey="..apikey)

and

Code: [Select]
luup.inet.wget("http://emoncms/input/post.json?node=0&json=IINST:"..iinst.."&apikey="..apikey)
« Last Edit: October 13, 2015, 08:31:10 pm by cybrmage »

Offline Velectris

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #2 on: October 14, 2015, 03:21:40 am »
Hi, Cybrmage

Thanks a lot for this aproach . Unfortunately, this no more work, i have still no error, but no data on emonscms input... ??? ::)

I sent a request to Brian from support, and i've sent "personal mail" to  a senior menber of this forum who developped a pluigin for ui5.

I'm so crossing the fingers now !




Offline cybrmage

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1104
  • Karma: +113/-43
Re: emoncms link to vera edge ui7
« Reply #3 on: October 14, 2015, 05:37:48 am »
Hi, Cybrmage

Thanks a lot for this aproach . Unfortunately, this no more work, i have still no error, but no data on emonscms input... ??? ::)

You MIGHT want to put in the correct URL...

instead of http://emoncms/, use http://emoncms.org/

With the correct URL it DOES work.

Offline Velectris

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #4 on: October 14, 2015, 07:37:16 am »
 ;D I agree with you my friend that with the correct url, this is way far better !!!!

Now i have a Watt input on emoncms page, but the KWH is not created, and the value for watt is each time zero, so i guess i have still two troubles, one on the data input, and on the creation of the value "KWH" .

But, there is very big step passed !

You can view the inputs with the apikey wich is in the software .
Here are the resulting line codes :

local id = 25
local type = "urn:schemas-micasaverde-com:device:PowerMeter:1"
local fields = {"Watts", "KWH"}
local apikey = "95fe5bdb8f6f28cefdbdbbddd6c1315c"
local voltage = 225
 
for i,field in ipairs(fields) do
  local value = luup.variable_get(type, field, id)
  value = tostring(value)
 
  luup.inet.wget("http://emoncms.org/input/post.json?node=0&json="..field..":"..value.."&apikey="..apikey)
 
  if field == "Watts" then
    local iinst = tostring(luup.variable_get(type, field, id) / voltage)
    luup.inet.wget("http://emoncms.org/input/post.json?node=0&json=IINST:"..iinst.."&apikey="..apikey)
  end
end

I'm sure with one or two steps, you can help me to fix this feature. Of course, everibody will have this capability also, there will just a need to adjust the device ID ( clamp meter ) and device URN .
So, i guess we are also working for the hole vera community !  :D

Offline cybrmage

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1104
  • Karma: +113/-43
Re: emoncms link to vera edge ui7
« Reply #5 on: October 14, 2015, 07:49:52 am »
Now i have a Watt input on emoncms page, but the KWH is not created, and the value for watt is each time zero, so i guess i have still two troubles, one on the data input, and on the creation of the value "KWH" .

That would be due to you "type" parameter....

You are using the device urn instead of the service id...

try using "urn:micasaverde-com:serviceId:EnergyMetering1" instead.

Offline Velectris

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #6 on: October 14, 2015, 09:00:43 am »
You are a magician !
more seriously, you have a very good knowledge of these "details", congratulations !

This works now like a charme, many thanks !

I publish here the running code if any other guy want to try this solution :

local id = 25
local type = "urn:micasaverde-com:serviceId:EnergyMetering1"
local fields = {"Watts", "KWH"}
local apikey = "95fe5bdb8f6f28cefdbdbbddd6c1315c"
local voltage = 225
 
for i,field in ipairs(fields) do
  local value = luup.variable_get(type, field, id)
  value = tostring(value)
 
  luup.inet.wget("http://emoncms.org/input/post.json?node=0&json="..field..":"..value.."&apikey="..apikey)
 
  if field == "Watts" then
    local iinst = tostring(luup.variable_get(type, field, id) / voltage)
    luup.inet.wget("http://emoncms.org/input/post.json?node=0&json=IINST:"..iinst.."&apikey="..apikey)
  end
end

You need just to edit the id of the mesuring device, and his type , and of course, your apikey for emoncms .

I have now some job to do for displaying the data correctly, i will follow an url when finished .

Cheers !  ;D
« Last Edit: October 17, 2015, 01:17:22 pm by Velectris »

Offline JanneSjo

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #7 on: October 17, 2015, 09:26:50 am »
Hi

I am new to Vera - I have a Vera Edge.

Sorry for the newie question:

Where do I find the type of my device - to replace    EnergyMetering1    ?

Offline Velectris

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #8 on: October 17, 2015, 01:22:19 pm »
Hi, JanneSjo,

You just go to you device in vera, and click on settings, then "advanced", and you have the device type in front of you, you just have to copy the end of the sentence in the code.
Don't forget to change the device ID also.

Good experimentation, here is my result page on emoncms with 5mn tuning :
http://emoncms.org/app?apikey=95fe5bdb8f6f28cefdbdbbddd6c1315c#mysolarpv

Cheers !  ;D

Offline tmaster

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #9 on: December 06, 2015, 01:59:12 pm »
So many magicians here :)

I'm trying to finishing my "Mysensors" powermeter and send values from vera to emoncms right now.
but i can't understand what is the wget adress???  i already change the other values second my sensor


Code: [Select]
local id = 49
local type = "urn:micasaverde-com:serviceId:EnergyMetering1"
local fields = {"Watts", "KWH"}
local apikey = "b2492222b5************5dd9f775"
local voltage = 230
 
for i,field in ipairs(fields) do
  local value = luup.variable_get(type, field, id)
  value = tostring(value)
 
  luup.inet.wget("http://emoncms.org/input/post.json?node=0&json="..field..":"..value.."&apikey="..apikey)     < WHATS THAT?AND CHANGE BY WHAT???
 
  if field == "Watts" then
    local iinst = tostring(luup.variable_get(type, field, id) / voltage)
    luup.inet.wget("http://emoncms.org/input/post.json?node=0&json=IINST:"..iinst.."&apikey="..apikey)       < WHATS THAT?
  end
end

EDIT:
ITS WORKInG ALREADY.  was supose leave it as it is :)

there are  any problem if i decrease the vera scene update from 1 min to less time? will that overcharge vera lite powerfull cpu? :P
« Last Edit: December 06, 2015, 03:10:37 pm by tmaster »

Offline Velectris

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #10 on: December 06, 2015, 03:29:30 pm »
Hi, happy to know that it works also for you !
The 1mn latence is there to avoid too much traffic on emoncms server : this is free, and we need to be fair with the open source world, isn't it ?

But, unfortunately, i have another experimentation on ? esp8266 posting to emon cms, and this is ok with 10 seconds.

You just need to respect this minimum delay.

Good tuning ! 8)

Offline tmaster

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #11 on: December 07, 2015, 01:12:16 pm »
ye,you are right, even on sensor , i will put 1 min interval for not overload my gateway.

good work  8)

Offline kulfsson

  • Jr. Member
  • **
  • Posts: 59
  • Karma: +2/-0
Re: emoncms link to vera edge ui7
« Reply #12 on: December 20, 2015, 05:53:10 am »
I like this approach and I have been testing it out for a little while. I am only wanting to log my watts usage from my fibaro wall plugs to EmonCMS and I don?t need any calculation in the lua, but what I was wondering is if I could have one Scene that pulls all of my plugs instead of a seperate scene for each but of course it should post each plug seperately.

I am not a programmer, so I can unfortunately not figure this out by myself.

I was initially going to use the built-in Ergy, which to me looks a lot like EmonCMS, but unfortunately this is not working well at the moment.

Offline Velectris

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: emoncms link to vera edge ui7
« Reply #13 on: December 20, 2015, 10:25:40 am »
Hi Kulfsson,

You describe a good solution when you have many watt values to feed to emoncms.
I'm sure this is possible, and not too hard to code.
Unfortunately, i have a bad knowledge of "how to read and describe the variable names in vera", and in this case, this is a requirement.

I'm sure a lot of people here can help you to write the running code.
Emoncms can accept a lot of variable in one shot, any node number, so you can just create nodes according to your requirements, and send all the data on one line / http json transaction .

Chuss !  8)