DataYours - monitoring energy usage

[quote=“d55m14, post:60, topic:186813”]must the follwing instruction :

module ("L_DataUser", package.seeall)

remain in the L_Datauser.lua module ?[/quote]

It’s really there to satisfy constraints when the module is used in Vera, it’s otherwise not the way I’d choose to write a module. If you remove it, you have to export the global function explicitly in a return statement at the end of the module like so:

return {run = run}

Does this give you a problem?

No problem.

So the L_Datauser.lua routine will be :

function run (metric, value, time)  
  
  local x,n = metric: gsub ("Variable", "kwdaily")
  
  local i = 0
  local metrics = {metric, n>0 and x or nil}
 
  return function ()
    i = i + 1
    return metrics[i], value, time
  end
end

return {run = run}

Is it correct ?

tnks

donato

Yes, except that you should now make the run function local, since you explicitly export it.

local function run (metric, value, time)  

ok thanks!!

In fact, I’ve just spotted another error in your translation of my code.

This line

 return metrics, value, time

Should be

 return metrics[i], value, time

as in my original.

AH! I see that you typed the code in correctly, but this

metrics[i]

Was interpreted as the start of italic script by the BB software because you had not enclosed the code in a [tt]code[/tt] section !!

Yes it’s a my mistake.

I did a first test and the files were correctly generated. Tomorrow I’ll continue with the tests.

tnks

donato

Hi akbooer,

I’m using successfully the following your DataUser routine to duplicate wsp files with different schemas and aggregation rules :

local function run (metric, value, time)  
  
  local x,n = metric: gsub ("Variable", "kwdaily")
  
  local i = 0
  local metrics = {metric, n>0 and x or nil}
 
  return function ()
    i = i + 1
    return metrics[i], value, time
  end
end

return {run = run} 

How do I have to modify it to add another wsp file, for example “hourly” .
To explain: I want to write the wsp file with the “Variable” string in the name and write other two wsp files (daily and hourly).

tnks

donato

local function run (metric, value, time) 

  local target = "Variable"
  local names = {"kwdaily", "kwhourly"}

  local metrics = {metric}
  for i, name in ipairs (names) do
    local x,n = metric: gsub (target, name)
    metrics[#metrics+1] = n>0 and x or nil
  end

  local i = 0
 
  return function ()
    i = i + 1
    return metrics[i], value, time
  end
end

return {run = run}

[hr]

Edit: updated to correct an error in case the template didn’t match

Akbooer thanks you very much for your precious support. What do you mean with the … template didn’t match. Which template ? or the “Variable” substring is not found ?

tnks

[quote=“akbooer, post:69, topic:186813”][code]
local function run (metric, value, time)

local target = “Variable”
local names = {“kwdaily”, “kwhourly”}

local metrics = {metric}
for i, name in ipairs (names) do
local x,n = metric: gsub (target, name)
metrics[#metrics+1] = n>0 and x or nil
end

local i = 0

return function ()
i = i + 1
return metrics[i], value, time
end
end

return {run = run}
[/code]

[hr]

Edit: updated to correct an error in case the template didn’t match[/quote]

Yes, the target “Variable” which is a template for the gsub() function. In the event of no match, it would return the original in triplicate… but this is fixed now and the code bears more than a passing resemblance to the original.

ok tnks

Yes, the target “Variable” which is a template for the gsub() function. In the event of no match, it would return the original in triplicate… but this is fixed now and the code bears more than a passing resemblance to the original.[/quote]

Hi akbooer,

in your opinion with the power meter described at this link :

http://www.emanager.eu/en/products/smartpi

and with the available API is it difficult to get the energy values measured (Watt, Kwh, Kvar, Kvarh, etc.) into a Openluup/DY environment installed on the same RPI machine ?

tnks

donato

What I don’t see in the definition of the API is the format of the returned data. If this is reasonable, then I really don’t see a problem with using it. Lots of other plugins use REST APIs to retrieve data from other hardware : Sonos, Netatmo, …

So you’d have a simple plugin, or just a scene, which reads the data and puts it into device variables, and the rest is standard.

[quote=“akbooer, post:74, topic:186813”]What I don’t see in the definition of the API is the format of the returned data. If this is reasonable, then I really don’t see a problem with using it. Lots of other plugins use REST APIs to retrieve data from other hardware : Sonos, Netatmo, …

So you’d have a simple plugin, or just a scene, which reads the data and puts it into device variables, and the rest is standard.[/quote]

Ok tnks for your reply

I’ll verify the format of returned data.

Hi akbooer,

I hope everything’s ok .

I want to add another variable to DataUser.lua routine to duplicate the whisper file : for example Temperature and generate a MaxTemp file with another Schemas/Aggregation. Could the attached routine be ok ?

tnks

donato

Hi akbooer,

excuse me when not busy can you check the modified datauser routine I modified ?

Tnks very much

Donato

I completely missed your original post, so thanks for the reminder.

Yes, that looks OK. Have you tried it yet?

Hi akbooer,

no problem. not yet tested. now after your check I’ll try it :wink:

tnks tnks

donato

Hi akbooer,

I’ve tested the modified Datauser.lua but I get an error msg. I’ve attached the relative log.

I suppose an error in the code.

tnks

donato