Page 1 of 1

Logging for a single script that runs every minute

Posted: Saturday 08 July 2017 16:33
by snuiter
Hi,
I have a script that is running every minute but is only really being executed once a day, this scripts needs to put something in the log but since it runs every minute it fills my log every minute with basic dzVents text. Here is what I tried / tested.

Domoticz settings : dzVents logging on 'Silent'

script settings option 1 : no logging enabled in script > result nothing in logging although in execution there is a domoticz.log line being executed

script settings option 2 : enable logging in scripts > result every minute log is written that script was started and finished, but there was no execution

2017-07-08 16:14:00.191 dzVents: Info: Sunset :: ------ Start internal script: dz-sunset:, trigger: every minute
2017-07-08 16:14:00.191 dzVents: Info: Sunset :: ------ Finished dz-sunset

Any suggestions how I can get the logging only being written when the execute part of the script is run and not logging every minute.

Thanks,
Ivo

Re: Logging for a single script that runs every minute

Posted: Saturday 08 July 2017 16:52
by K3rryBlue
Add something like this to your LUA. Change the hour value to the hour you want to execute.
Please use search as this is available in many topics.

Code: Select all

time = os.date("*t")
if time.hour==13 and time.min<=01 then
//place your code
end

Re: Logging for a single script that runs every minute

Posted: Sunday 09 July 2017 11:51
by snuiter
Sorry I am using dzVents and not lua, for example I want some lights to turn on 40 minutes before sunset. This forces me to use the timer to be set to every minute as the sunset changes every day and thus the moment this script needs to be executed.

This is basic of the script, no problem having it run every minute but only want my log to be written when it is really being executed and that is when the if statement is true
Spoiler: show
return {
active = true,
on = {
timer = {
'every minute'
},
},
logging = {
level = domoticz.LOG_INFO,
marker = "Sunset :"
},
execute = function(domoticz)
local myMin = domoticz.time.min + domoticz.time.hour *60
local myRest = domoticz.time.sunsetInMinutes - myMin

if (myRest == 40) then
......
end
end
}
Any suggestions are appreciated

Re: Logging for a single script that runs every minute

Posted: Sunday 09 July 2017 14:51
by dannybloe
Do I understand correctly that when log level is set to silent you indeed don't see anything in the logs (as intended)? Just wanna be sure there's not a bug there.
So, there are a couple of things you can do. You can create an active function or a timer function. I'd say a timer is more appropriate:

Code: Select all

return {
	active = true,
	on = {
		timer = {
			function(d)
				local myMin = d.time.min + d.time.hour *60
				local myRest = d.time.sunsetInMinutes - myMin
				return (myRest == 40) 
			end
		},
	},
	execute = function(domoticz)
		...
	end
}
That should work (famous last words).
Lemme know if it does (or doesn't). It should now only do logging if the execute function is executed. Otherwise it should be silent.
Danny

Re: Logging for a single script that runs every minute

Posted: Sunday 09 July 2017 21:50
by snuiter
Thanks Danny this is a great solution and an extra feature of the already nice dzVents solutions.Didn't look at it from that perspective. My scripts size decreased significantly when moving from lua to dzvents. So far I am happy user as almost all my scripts have moved over.

btw. when log level is set to silent I don't get anything in the logs, that is working fine.

Cheers,
Ivo

Oh yes, I tested it just now and it worked

Re: Logging for a single script that runs every minute

Posted: Thursday 27 July 2017 20:43
by dannybloe
Hey Snuiter (always want to say that sometime).
dzVents 2.2.0 now has a xxx minutes before sunset time rule (and after, and the same for sunrise). See the docs.
It's in Domoticz beta v3.8143 or higher.
Less code to maintain. Maybe you can try it.

Re: Logging for a single script that runs every minute

Posted: Thursday 27 July 2017 21:53
by snuiter
Hi Danny,
thanks I already read it in your comments searching for 2.2.0 testers. Will test is once available.

Thanks for mentioning!

Re: Logging for a single script that runs every minute

Posted: Wednesday 28 October 2020 20:05
by madpatrick
Hi,

The question about reducing the logging reflects my question only my script (thanks to Waaren) is triggered by a PIR sensor
So every time you walk in the room, this gives a few lines in the log.
At the end of the day the log file growes and growes.....

Code: Select all

2020-10-28 19:50:12.741 Status: OpenZWave: Alarm received (Home Security: Motion Detected at Unknown Location), NodeID: 31 (0x1f)
2020-10-28 19:50:12.771 Status: dzVents: Info: Handling events for: "PIR Sensor", value: "Off"
2020-10-28 19:50:12.834 Status: dzVents: Info: Handling events for: "PIR Sensor", value: "On"
This is a part of the script.

Code: Select all

return
{
    active = true,
    on =
    {
        devices =
        {
            'Sensor - Achterdeur',                     -- deurcontact in de woonkamer
            'Sensor - Garagedeur',                     -- deurcontact in de garage
            'PIR Sensor',                              -- PIR Sensor
            'Alarm mode',
        },
    },

logging =
    {
        level = domoticz.LOG_ERROR,
        marker = scriptVar,
    },
Is it possible to enable the script on a device and the switch "Alarm mode" ?
or disable the loglines (and not block all logging....)

This is what i;ve tried, but does not work

Code: Select all

        devices =
        {
            Achterdeur,                     -- deurcontact in de woonkamer
            Garagedeur,                     -- deurcontact in de garage
            PIR,                              -- PIR Sensor
            
        }
        and
        {
            alarmMode == 'on',
            }
        ,
    },

Re: Logging for a single script that runs every minute

Posted: Sunday 01 November 2020 18:10
by waaren
madpatrick wrote: Wednesday 28 October 2020 20:05 So every time you walk in the room, this gives a few lines in the log.
At the end of the day the log file growes and growes.....
If you want to minimize your dzVents logging then set the dzVents logging in setup settings other to 'Errors only"
and use below type of logging in your scripts
The domoticz loglevel can be set in /etc/init.d/domoticz.sh
You will find quite some examples on how to do that in this forum.

Code: Select all

local scriptVar =  'log issue'
return
{
    active = true,
    on =
    {
        devices =
        {
            'Sensor - Achterdeur',                     -- deurcontact in de woonkamer
            'Sensor - Garagedeur',                     -- deurcontact in de garage
            'PIR Sensor',                              -- PIR Sensor
            'Alarm mode',
        },
    },

    logging =
        {
            level = domoticz.LOG_ERROR,
            marker = scriptVar,
        },


    execute = function(dz, item)
        dz.log('You should now only see this line',dz.LOG_FORCE)
    end
}