Lua script
-
I have made a simple lua script to count pellet and show this on a virtuell counter in Domoticz. The problem is that the counter dont shows decimals. Can anyone tell me if it is some more i have to write in the script. Here it is
counter = otherdevices_svalues['Counter']
counter = tonumber(counter)commandArray = {}
if
devicechanged['Pellets'] == 'On'
then
counter = counter + 0.015
commandArray['UpdateDevice'] = 82 .. '|0|' .. tostring(counter)
endreturn commandArray
-
@Dragon I must have misunderstood what you are trying to accomplish. In lua 5.1.5, here is the result for what I thought you were trying to accomplish.

Perhaps you should
print(commandArray['UpdateDevice'])after you set it to confirm the value at that point. If the value of commandArray contains the string with decimals, as I suspect it will, then it must be something else or a Domoticoz issue. I also believe that tostring(counter) will include the decimals; the advantage of string.format() is that you can control the format of the resulting string... -
I can try explain more how i made it. Sorry for my bad English, on my pellet boiler i have a switch that sends on to domoticz every turn with is 15 gram pellet. In domoticz is the switch called Pellets. Then i made a viruell counter in domoticz with name Counter. I want the lua script to + 0.015 to every turn the boiler do to Count how mutch pellet it use. It works now but shows without decimals like 2kg, 3kg and so. I can have so but it would be fun to se more exact weight.
-
I have made a simple lua script to count pellet and show this on a virtuell counter in Domoticz. The problem is that the counter dont shows decimals. Can anyone tell me if it is some more i have to write in the script. Here it is
counter = otherdevices_svalues['Counter']
counter = tonumber(counter)commandArray = {}
if
devicechanged['Pellets'] == 'On'
then
counter = counter + 0.015
commandArray['UpdateDevice'] = 82 .. '|0|' .. tostring(counter)
endreturn commandArray
@Dragon said:
counter = otherdevices_svalues['Counter']
print(counter)
counter = tonumber(counter)
print(counter)
commandArray = {}
if
devicechanged['Pellets'] == 'On'
then
counter = counter + 0.015print(counter)
commandArray['UpdateDevice'] = 82 .. '|0|' .. tostring(counter)
endreturn commandArray
put print after each change you do with counter to see what actually happen with your values, as @blacey wrote -
@Dragon said:
counter = otherdevices_svalues['Counter']
print(counter)
counter = tonumber(counter)
print(counter)
commandArray = {}
if
devicechanged['Pellets'] == 'On'
then
counter = counter + 0.015print(counter)
commandArray['UpdateDevice'] = 82 .. '|0|' .. tostring(counter)
endreturn commandArray
put print after each change you do with counter to see what actually happen with your values, as @blacey wrote -
Interesting projects
I'm looking to create a counter that counts the number of times the temperature reaches above 30 degrees.
Intend to use it when I bonfiresHave you learned LUA on the internet?
-
This my script with decimals
commandArray = {} if devicechanged['Panna_V'] or devicechanged['Huset_V'] then local panna_v = otherdevices_svalues["Panna_V"] local huset_v = otherdevices_svalues["Huset_V"] local hushall_kwh = uservariables['Hushåll_kWh'] local huset_kwh = uservariables['Huset_kWh'] local panna_kwh = uservariables['Panna_kWh'] local panna, energy, huset, energy2 --print(pan) --print(hus) _,_,panna, energy = string.find(panna_v, "(.+);(.+)") _,_,huset, energy2 = string.find(huset_v, "(.+);(.+)") --print(panna) --print(huset) --print(energy) --print ("energy2="..energy2) --print ("huset_kwh="..huset_kwh) husetdiff_kwh = energy2 - huset_kwh --print ("husetdiff kwh") --print (husetdiff_kwh) --print ("energy="..energy) --print ("panna_kwh="..panna_kwh) pannadiff_kwh = energy - panna_kwh --print ("pannadiff kwh") --print (pannadiff_kwh) hushal_kwh = husetdiff_kwh - pannadiff_kwh hushall_kwh = hushall_kwh + hushal_kwh --print ("hushåll_kwh") --print (hushall_kwh) panna = tonumber(panna) huset = tonumber(huset) hush = huset - panna ener = energy2 - energy --print(hush) --print(ener) if hush > 0 then --print(el) commandArray['Variable:Hushåll_kWh']= tostring(hushall_kwh) commandArray['Variable:Huset_kWh']= tostring(energy2) commandArray['Variable:Panna_kWh']= tostring(energy) abc = tostring(hush) def = tostring(hushall_kwh) commandArray['UpdateDevice'] = '272|0|'..abc..';'..def..'' else end end return commandArrayI am using Dummy, Electric(Instant&Counter) version 3.5721 of DZ
Panna_V(heating system) and Huset_V(whole house) is electric usage meters that report every 5 minute. I use my Dummy to show my electric consumption without(minus) my heating system
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login