Page 1 of 1
Extract Energy values to local variable
Posted: Tuesday 29 May 2018 21:50
by EdddieN
Hello,
I used to have this LUA script working on the stable version, but not anymore on the beta so trying to migrate it to dzVents. Below is my poor mans attempt so far:
Code: Select all
--[[
updateEnergy
]] --
return {
on = {
--devices = { 'House Energy'} ,
timer = { 'every 1 minutes' }, -- timer or device to trigger the script. Can be both or one of them
},
execute = function(domoticz, device, trigger)
local d1_sensor = 'House Energy'
local d2_sensor = 'Oil meter (A)'
local d1_values = otherdevices_svalues[d1_sensor]
local d2_values = otherdevices_svalues[d2_sensor]
local power,energy = d1_values:match("([^,]+);([^,]+)")
local datastring = "d1," .. tostring(energy) ..";d2," .. tostring(d2_values)
print (datastring)
local myUrl= 'customuserurl' .. datastring
domoticz.openURL(myUrl)
end
}
I looked into the dzVents wiki but could not find a way to read the value of a meter. It was reference to update its current value for a virtual device, but not to read it. Any ideas?
Re: Extract Energy values to local variable
Posted: Tuesday 29 May 2018 22:36
by waaren
@EdddieN
it depends on what kind of meter you have. For most meters a dzVents device adapter is available.
you can always find if such an adapter is available (and much more) by using domoticz.devices(nnn).dump() in your script
or in dzVents >= 2.4
Code: Select all
local _ = domoticz.utils._
_.print(domoticz.devices(nnn)._adapters)
domoticz.log( domoticz.devices(nnn).deviceType .. "; state: " .. domoticz.devices(nnn).state)
Re: Extract Energy values to local variable
Posted: Wednesday 30 May 2018 8:08
by dannybloe
And of course, if a new adapter is needed I'm happy to add it. The more the merrier.
Re: Extract Energy values to local variable
Posted: Wednesday 30 May 2018 14:14
by EdddieN
Thanks, but I think I'm been a bit clumsy here, you mean something like this:
Code: Select all
return {
on = {
timer = { 'every 1 minutes' }, -- timer or device to trigger the script. Can be both or one of them
},
execute = function(domoticz, device, trigger)
local energy_meter = domoticz.utils.d1_sensor
energy_meter.print(domoticz.devices(energy)._adapters)
domoticz.log( domoticz.devices(energy).deviceType .. "; state: " .. domoticz.devices(energy).state)
print ("ENERGY ============= " ..energy_meter)
Re: Extract Energy values to local variable
Posted: Wednesday 30 May 2018 20:19
by waaren
@EddieN,
No my code snippet was literal; you only have to replace the nnn with the actual device numbers.
it would help me understand if you could send me the original lua and a screenprint of the [SETUP] --> Devices screen for the devices at hand
Re: Extract Energy values to local variable
Posted: Wednesday 30 May 2018 21:03
by EdddieN
Of course! Thanks.
This my device (idx 130)

- Screen Shot 2018-05-30 at 20.01.33.png (105.02 KiB) Viewed 2265 times
and I took your code and replaced the nnn value:
Code: Select all
local _ = domoticz.utils._
_.print(domoticz.devices(130)._adapters)
domoticz.log( domoticz.devices(130).deviceType .. "; state: " .. domoticz.devices(130).state)
which gives me a LUA error code: attempt to index field 'utils' (a nil value)
what I'm trying to do is just to push that value (kWh from the house meter) to an external server, something like
local myurl = '
http://www.server.com/savemydata.php?data=' .. ThekWhEnergyfromHouseEnergy
domoticz.openURL(myUrl)
that way I can see the house energy usage without having to have remote access to Domoticz.
Re: Extract Energy values to local variable
Posted: Friday 01 June 2018 0:49
by waaren
@EddieN,
OK sounds not to complicated but I first have to know how dzVents see this device. Can you please send me the log output of this script.
Code: Select all
return {
on = { timer = { 'every minute' }},
logging = { level = domoticz.LOG_DEBUG, marker = "updateEnergy" },
execute = function(dz, trigger)
local houseEnergyDevice = dz.devices("House Energy")
houseEnergyDevice.dump()
dz.log("\n\nDevicetype :" .. houseEnergyDevice.deviceType ..
"\nDevicesubtype: :" .. houseEnergyDevice.deviceSubType .."\n",dz.LOG_DEBUG)
end
}
Re: Extract Energy values to local variable
Posted: Friday 01 June 2018 11:15
by EdddieN
Thanks a lot for helping on this.
I had this working using LUA except for the Co2 sensor:
- Spoiler: show
- local d1_values = otherdevices_svalues['House Energy']
local d2_values = otherdevices_svalues['Oil meter (A)']
local d3_values = otherdevices_utility['Co2']
local d4_values = otherdevices_svalues['TH / RH Co2']
local t1 = os.date("%M")
-- returns a date time like 2013-07-11 17:23:12
commandArray = {}
if t1%10 == 0 then
local power,energy = d1_values:match("([^,]+);([^,]+)")
print ("ENERGY ======> " ..energy)
local temperature,humidity = d4_values:match("([^,]+);([^,]+);([^,]+)")
print ("TEMP ======== ".. temperature)
print ("humidity===== ".. humidity)
end
return commandArray
Until I found that that for svalue was working for meters but not Co2, it had to be utility...
Anyway, since dzVents seems a lot easier to use, I was hoping to replicate the above in dzVents but cannot get my head around how to read the svalue of devices in dzVents. That is all I need
