updating percentage

Moderator: leecollings

Post Reply
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

updating percentage

Post 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?
User avatar
psubiaco
Posts: 205
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: updating percentage

Post 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
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: updating percentage

Post 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
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: updating percentage

Post 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%
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: updating percentage

Post by tiga »

solved by using this to update the device:

Code: Select all

commandArray[#commandArray + 1] = { ['UpdateDevice'] = 10526 ..'|0|'..percentage }
tiga
Posts: 156
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: updating percentage

Post 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?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests