Print counter to log  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
zavjah
Posts: 36
Joined: Tuesday 13 August 2019 10:20
Target OS: Raspberry Pi / ODroid
Domoticz version:

Print counter to log

Post by zavjah »

Hi,

I am trying to do something like this

loop something
If applicable then
x=x+1
end
end
log(i)

What seems to be an easy and straight forward task is making me nuts. Can someone please give me a hint? Thx

Cheers,
zavjah
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Print counter to log

Post by waaren »

zavjah wrote: Thursday 12 September 2019 14:18 I am trying to do something like this

Code: Select all

loop something
     If applicable then 
          x=x+1
     end
end
log(i)
What seems to be an easy and straight forward task is making me nuts. Can someone please give me a hint? Thx
Don't know what you tried already and with what the specific part you are having difficulties. But this dzVents example uses a loop, counters and log statements .

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
            'every minute',              -- causes the script to be called every minute
        },
    },
    execute = function(dz)
       local otherCounter = 0
       local onCounter = 0
       
        dz.devices().forEach(function(dv)
             if dv.state =='On' then
                 onCounter = onCounter + 1
            else
                otherCounter = otherCounter + 1
            end
        end) 
        
        dz.log('Number of active devices in domoticz : ' ..  onCounter + otherCounter,dz.LOG_FORCE)
        dz.log('Number of active devices in domoticz with state = "On" : ' ..  onCounter,dz.LOG_FORCE)
        dz.log('Number of active devices in domoticz with other state : ' ..  otherCounter,dz.LOG_FORCE)
    
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
zavjah
Posts: 36
Joined: Tuesday 13 August 2019 10:20
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: Print counter to log  [Solved]

Post by zavjah »

Hi waaren,

Thank you very much, it work's like a charm :-)

Cheers,
zavjah
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest