[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:
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}
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).
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.
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]
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 ?
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]
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 ?