New to this, and am trying a simple (or so I thought ) script.
I have a distance sensor in a oil tank, and decided to convert this into volume in Domoticz, rather than the sensor.
I have created a dummy holder for this value.
the script I have is
Code: Select all
return {
on = {
devices = {
'OilTankLevel'
}
},
execute = function(domoticz, OilTankLevel)
domoticz.log('Oil Tank Volume Calculated ' .. OilTankLevel.name .. ' was calculated', domoticz.LOG_INFO)
if ( domoticz.devices('OilTankLevel').distance >57) then
local OilTankLitres = (domoticz.devices('OilTankLevel').distance - 57 * 9.36) + (57 * 12.6)
elseif (domoticz.devices('OilTankLevel').distance<=57) then
local OilTankLitres = (domoticz.devices('OilTankLevel').distance * 12.6)
end
OilTankLitres.dump()
domoticz.log('Oil Tank Volume Calculated ' .. (domoticz.devices('OilTankLitres')) .. ' Litres', domoticz.LOG_INFO)
end
}
I have tried to put OilTankLitres.value, which isn't valid.
I'm sure it is a simple answer to this, but search as I might, I can't find references to set a value .
the log output is
2018-03-27 15:10:11.735 dzVents: Info: Handling events for: "OilTankLevel", value: "84.0"
2018-03-27 15:10:11.735 dzVents: Info: ------ Start internal script: OilVolume: Device: "OilTankLevel (MySensorsSerial)", Index: 1
2018-03-27 15:10:11.735 dzVents: Info: Oil Tank Volume Calculated OilTankLevel was calculated
2018-03-27 15:10:11.735 dzVents: Error (2.4.1): An error occured when calling event handler OilVolume
2018-03-27 15:10:11.735 dzVents: Error (2.4.1): ...ticz/var/scripts/dzVents/generated_scripts/OilVolume.lua:10: attempt to index global 'OilTankLitres' (a nil value)
2018-03-27 15:10:11.735 dzVents: Info: ------ Finished OilVolume
Where am I going wrong please?
Eventually Sorted it, if any one wants to Know, it is as below.
Code: Select all
return {
on = {
devices = {
'OilTankLevel'
},
timer = {
'every 10 minute'
},
},
execute = function(domoticz, OilTankLevel)
-- domoticz.log('Oil Tank Volume Calculated ' .. OilTankLevel.name .. ' was calculated', domoticz.LOG_INFO)
if ( domoticz.devices('OilTankLevel').distance >57) then
domoticz.devices('OilTankLitres').update(0,math.floor(((domoticz.devices('OilTankLevel').distance)-57 )*9.36) +(57*12.6))
elseif (domoticz.devices('OilTankLevel').distance<=57) then
domoticz.devices('OilTankLitres').update(0,math.floor(domoticz.devices('OilTankLevel').distance) * 12.6)
end
end
}