Page 1 of 1

using percentage in lua

Posted: Saturday 19 October 2024 21:13
by tiga
hello all!

i have a "type: general, percentage" device called "wtw filter levensduur (9mnd)" that is logging a filter life usage

i want to send an email when filter is 50% used and 75% used

this is what i got:

Code: Select all

commandArray = {}

if devicechanged['wtw filter levensduur (9mnd)'] then

    waarde     = (tonumber(otherdevices_svalues["wtw filter levensduur (9mnd)"]))
    
    
    if waarde == 50 then
        commandArray[1]={['SendEmail'] = 'wtw filter#wtw filter is 50% vervuild, uitzuigen!#[email protected]' }
    end
    
    if waarde == 75 then
        commandArray[1]={['SendEmail'] = 'wtw filter#wtw filter is 75% vervuild, bestel een nieuwe!#[email protected]' }
    end
    

end

return commandArray
the lua script is running device triggered

but nothing happens if i have 50% or 75%

i think the error must be in this part: waarde = (tonumber(otherdevices_svalues["wtw filter levensduur (9mnd)"])) but i dont know how to fix it

or is this some kind of loop prevention couse the ['wtw filter levensduur (9mnd)'] is updated by another script?????!!!!

Re: using percentage in lua

Posted: Sunday 20 October 2024 9:48
by HvdW
Maybe use the dump() statement for your device to see what values should be used.

Re: using percentage in lua

Posted: Sunday 20 October 2024 14:18
by waltervl
Perhaps you can learn from your own previous topic here https://domoticz.com/forum/viewtopic.ph ... ge#p318704