Page 1 of 1
simple multiplication
Posted: Saturday 10 August 2019 21:29
by EdddieN
Hello,
I think is one of those days that I'm missing something very obvious... what I'm doing wrong?
Code: Select all
--[[
Update OIL
]]
return {
on = {
-- timer riggers
timer = {
'every 1 minutes'
}
},
-- custom logging level for this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "Update OIL"
},
execute = function(domoticz)
-- domoticz.devices
domoticz.log('Running OIL updater...', domoticz.LOG_INFO)
local oilCounter = domoticz.devices('Oil tank')
local oil = domoticz.devices('AIN1') -- oil sensor (machinon analogue signal)
local oilconversion = tonumber(oil) * 14 -- convert to Litres
if oilconversion ~= oilCounter.value then
dz.log("OilCounter updated to " .. oilconversion ,dz.LOG_DEBUG)
oilCounter.updateCustomSensor(oilconversion)
else
dz.log("No update of oilCounter necessary. It is still " .. oil ,dz.LOG_DEBUG)
end
end
}
This results on
019-08-10 20:28:00.180 Status: dzVents: Error (2.4.10): Update OIL: ...omoticz/scripts/dzVents/generated_scripts/Oil sensor.lua:27: attempt to perform arithmetic on a nil value
Re: simple multiplication
Posted: Saturday 10 August 2019 21:41
by Thorgal789
line 27 > local oilconversion = tonumber(oil) * 14 -- convert to Litres
print the oil value to debug, I think the value is "nil"
Re: simple multiplication
Posted: Saturday 10 August 2019 21:51
by hoeby
What gives 'AIN1' for value?
The script says it goes wrong in line 27. But line 27 starts at line 26 with making the local oil. When 'AIN1' is nil, than line 27 will also be nill
Also change dz.log into domoticz.log
Or change everything to dz instead of domoticz.
Re: simple multiplication
Posted: Saturday 10 August 2019 22:02
by EdddieN
I'm very very rusty... got lazy and most of my scripts are in Blockly.
Ok, this is what I have now:
Code: Select all
--[[
Update OIL
]]
return {
on = {
-- timer riggers
timer = {
'every 1 minutes'
}
},
-- custom logging level for this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "Update OIL"
},
execute = function(domoticz, devices)
-- domoticz.devices
domoticz.log('Running OIL updater...', domoticz.LOG_INFO)
local oilCounter = domoticz.devices('Oil tank')
local oil = domoticz.devices('AIN1') -- oil sensor (machinon analogue signal)
domoticz.log("SENSOR value is " .. oil)
local oilconversion = tonumber(oil) * 14 -- convert to Litres
if oilconversion ~= oilCounter.value then
domoticz.log("OilCounter updated to " .. oilconversion)
oilCounter.updateCustomSensor(oilconversion)
else
domoticz.log("No update of oilCounter necessary. It is still " .. oil)
end
end
}
and still gives me
2019-08-10 21:02:00.252 Status: dzVents: Info: Update OIL: ------ Start internal script: Oil sensor:, trigger: every 1 minutes
2019-08-10 21:02:00.252 Status: dzVents: Info: Update OIL: Running OIL updater...
2019-08-10 21:02:00.270 Status: dzVents: Debug: Update OIL: Processing device-adapter for Oil tank: Custom sensor device adapter
2019-08-10 21:02:00.271 Status: dzVents: Debug: Update OIL: Processing device-adapter for AIN1: Voltage device adapter
2019-08-10 21:02:00.271 Status: dzVents: Error (2.4.10): Update OIL: An error occured when calling event handler Oil sensor
2019-08-10 21:02:00.271 Status: dzVents: Error (2.4.10): Update OIL: ...omoticz/scripts/dzVents/generated_scripts/Oil sensor.lua:27: attempt to concatenate local 'oil' (a table value)
2019-08-10 21:02:00.271 Status: dzVents: Info: Update OIL: ------ Finished Oil sensor
cannot even see the value of AIN1, which in domoticz is 59 volts
Re: simple multiplication
Posted: Saturday 10 August 2019 22:18
by Thorgal789
local oil = domoticz.devices('AIN1') can't be a value (and a number), it's a table
Try
local oil = domoticz.devices('AIN1').temperature
With replacing "temperature" by the filed you need (Sorry I have never do dzevent, so hard for me to explain ^^)
Re: simple multiplication
Posted: Saturday 10 August 2019 22:26
by EdddieN
Same results. If LUA is raise, happy to use lua.
Re: simple multiplication
Posted: Sunday 11 August 2019 7:39
by hoeby
Try this.
I tested the part
oil*14 in my domoticz and it gives a value 14x bigger than oil.
I can't run the complete script, because i don't have those devices.
Also look that i added
.state in
local oilCounter
And removed
.value in the
IF
Code: Select all
--[[
Update OIL
]]
return {
on = {
-- timer riggers
timer = {
'every 1 minutes'
}
},
-- custom logging level for this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "Update OIL"
},
execute = function(domoticz, devices)
-- domoticz.devices
domoticz.log('Running OIL updater...', domoticz.LOG_INFO)
local oilCounter = domoticz.devices('Oil tank').state
local oil = domoticz.devices('AIN1').state -- oil sensor (machinon analogue signal)
domoticz.log("SENSOR value is " .. oil)
local oilconversion = oil * 14 -- convert to Litres
if oilconversion ~= oilCounter then
domoticz.log("OilCounter updated to " .. oilconversion)
oilCounter.updateCustomSensor(oilconversion)
else
domoticz.log("No update of oilCounter necessary. It is still " .. oil)
end
end
}
Re: simple multiplication
Posted: Sunday 11 August 2019 10:11
by EdddieN
Getting somewhere now!
Code: Select all
2019-08-11 09:10:00.296 Status: dzVents: Info: Update OIL: ------ Start internal script: Oil sensor:, trigger: every 1 minutes
2019-08-11 09:10:00.297 Status: dzVents: Info: Update OIL: Running OIL updater...
2019-08-11 09:10:00.332 Status: dzVents: Debug: Update OIL: Processing device-adapter for Oil tank: Custom sensor device adapter
2019-08-11 09:10:00.334 Status: dzVents: Debug: Update OIL: Processing device-adapter for AIN1: Voltage device adapter
2019-08-11 09:10:00.334 Status: dzVents: Info: Update OIL: SENSOR value is 59.687
2019-08-11 09:10:00.334 Status: dzVents: Info: Update OIL: OilCounter updated to 835.618
2019-08-11 09:10:00.334 Status: dzVents: Error (2.4.10): Update OIL: An error occured when calling event handler Oil sensor
2019-08-11 09:10:00.334 Status: dzVents: Error (2.4.10): Update OIL: ...omoticz/scripts/dzVents/generated_scripts/Oil sensor.lua:32: attempt to call field 'updateCustomSensor' (a nil value)
2019-08-11 09:10:00.334 Status: dzVents: Info: Update OIL: ------ Finished Oil sensor
Updating the counter with the new value is what it fails now.
Re: simple multiplication
Posted: Sunday 11 August 2019 10:17
by EdddieN
Ok, finally it worked! Thanks so much!!!
Here it is the code
Code: Select all
--[[
Update OIL
]]
return {
on = {
-- timer riggers
timer = {
'every 1 minutes'
}
},
-- custom logging level for this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "Update OIL"
},
execute = function(domoticz, devices)
-- domoticz.devices
domoticz.log('Running OIL updater...', domoticz.LOG_INFO)
local oilCounter = domoticz.devices('Oil tank')
local oil = domoticz.devices('AIN1').state -- oil sensor (machinon analogue signal)
domoticz.log("SENSOR value is " .. oil)
local oilconversion = tonumber(oil) * 14 -- convert to Litres
if oilconversion ~= oilCounter.value then
domoticz.log("OilCounter updated to " .. oilconversion)
oilCounter.updateCustomSensor(oilconversion)
else
domoticz.log("No update of oilCounter necessary. It is still " .. oil)
end
end
}
Re: simple multiplication
Posted: Sunday 11 August 2019 10:55
by waaren
EdddieN wrote:Ok, finally it worked! Thanks so much!!!
Code: Select all
domoticz.log("No update of oilCounter necessary. It is still " .. oil)
I guess the oil in this line also needs to be changed to oilconversion?
Re: simple multiplication
Posted: Sunday 11 August 2019 12:16
by EdddieN
Yes, and also need to find out to remove the decimals, now I get something like '834.234L' which is far too much resolution. Any suggestions?
Re: simple multiplication
Posted: Sunday 11 August 2019 12:18
by waaren
EdddieN wrote:Yes, and also need to find out to remove the decimals, now I get something like '834.234L' which is far too much resolution. Any suggestions?
Yes use domoticz.utils.round(your number var,1)
Re: simple multiplication
Posted: Sunday 11 August 2019 12:25
by EdddieN
Like this?
local oilconversion = tonumber(oil) * 14 -- convert to Litres
oilconversion = dz.utils.round(oilconversion,1)
Re: simple multiplication
Posted: Sunday 11 August 2019 12:32
by waaren
EdddieN wrote:Like this?
local oilconversion = tonumber(oil) * 14 -- convert to Litres
oilconversion = dz.utils.round(oilconversion,1)
Yes but in your script you need to change dz to domoticz because that is the name of your parm containing the domoticz object.
I use dz as the name of this object in most of my scripts (too lazy to type the full name every time

)
Re: simple multiplication [Solved]
Posted: Sunday 11 August 2019 12:37
by EdddieN
Ah! I was wondering what dz, domoticz difference it was... thanks. That did the trick!
Code: Select all
--[[
Update OIL
]]
return {
on = {
-- timer riggers
timer = {
'every 1 minutes'
}
},
-- custom logging level for this script
logging = {
level = domoticz.LOG_DEBUG,
marker = "Update OIL"
},
execute = function(domoticz, devices)
-- domoticz.devices
domoticz.log('Running OIL updater...', domoticz.LOG_INFO)
local oilCounter = domoticz.devices('Oil tank')
local oil = domoticz.devices('AIN1').state -- oil sensor (machinon analogue signal)
domoticz.log("SENSOR value is " .. oil)
local oilconversion = tonumber(oil) * 14 -- convert to Litres
oilconversion = domoticz.utils.round(oilconversion,1)
if oilconversion1 ~= oilCounter.value then
domoticz.log("OilCounter updated to " .. oilconversion)
oilCounter.updateCustomSensor(oilconversion)
else
domoticz.log("No update of oilCounter necessary. It is still " .. oilconversion)
end
end
}