Page 1 of 1

updating percentage

Posted: Friday 19 July 2024 23:24
by tiga
hello...i am trying to update a virtual % device in lua but can not get it to work.
definitely couse of my lack of skills so hoping for your help

so i have a virtual percentage device setup called "wtw filter levensduur (9mnd)" idx = 10526
9 months = 9 x 30 x 24 = 6480 hours
i receive a filter counter called "itho filter teller" in hours

so this is one version i have tried:(of many unsuccessfull)

Code: Select all

local itho_filter_teller        = tonumber(otherdevices_svalues['itho filter teller'])

commandArray = {}

if devicechanged['itho filter teller'] then
    percentage = itho_filter_teller / 6480
    commandArray['UpdateDevice']='10526|0|..percentage'
end

return commandArray

what do i need to change to get this working?

Re: updating percentage

Posted: Saturday 20 July 2024 8:33
by psubiaco
Try this:

Code: Select all

commandArray = {}

if devicechanged['itho filter teller'] then
    percentage = math.floor(tonumber(otherdevices_svalues['itho filter teller']) / 6480)
    print("Percentage="..percentage)
    commandArray['UpdateDevice']='10526|0|..percentage'
end

return commandArray
The only differences from your code are:
1. device is read only if needed
2. percentage value is converted to integer
3. percetnage value is printed in the LOG, so you can check that it is in a valid range
If it does not work, please copy here a piece of log

Re: updating percentage

Posted: Saturday 20 July 2024 16:31
by tiga
thanks!

but this doesn't work

Code: Select all

 2024-07-20 16:21:53.512 Status: LUA: Percentage=0
i got 0 on percentage

"itho filter teller" containes a value of 484 so percentage should be 484/6480= 0.07 %

i changed 6480 to 64.80 to make it full percentage value so percentage should give a value of 7

Re: updating percentage

Posted: Saturday 20 July 2024 21:00
by tiga
dont know what went wrong the first time but now i get:

Code: Select all

2024-07-20 20:58:22.118 Status: LUA: Percentage=7
but the % device does not get updated.....it stays at 0%

Re: updating percentage

Posted: Saturday 20 July 2024 21:17
by tiga
solved by using this to update the device:

Code: Select all

commandArray[#commandArray + 1] = { ['UpdateDevice'] = 10526 ..'|0|'..percentage }

Re: updating percentage

Posted: Thursday 25 July 2024 16:51
by tiga
this is what i got now:

Code: Select all

local wtw_filter_levensduur     = otherdevices_svalues["wtw filter levensduur (9mnd)"]

commandArray = {}

if devicechanged['itho filter teller'] then
    percentage = math.floor(tonumber(otherdevices_svalues['itho filter teller']) / 64.80)
    print("Percentage="..percentage)

if wtw_filter_levensduur ~= percentage then
    commandArray[#commandArray + 1] = { ['UpdateDevice'] = 10526 ..'|0|'..percentage }
    end
end    
return commandArray
i only want "wtw filter levensduur (9mnd)" (idx 10526) to update only when it is needed.....
but with this script it gets updated every time 'itho filter teller' gets updated.

how can i fix that?