massive logging with lua script

Moderator: leecollings

timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

massive logging with lua script

Post by timop »

I have one script which check if my Home (switch) on and sets volumio to play if anyone is home or not if nobody at home (or time is over 9pm or under 10am)
it works but when it sets off volumio, it starts logging to domoticz about 10times /sec, so everything else logging goes "lost"
what I am doing wrong ?

script

Code: Select all

if (devicechanged['Home']) then
        --if (devicechanged['Home'] == 'On') then
          commandArray['Volumio'] = 'On'
          commandArray['Variable:VolumioVar'] = '1'
        elseif (time.hour >=21 or otherdevices['Home'] == 'Off') then
          commandArray['Volumio'] = 'Off'
          commandArray['Variable:VolumioVar'] = '0'
        elseif (time.hour <10 or otherdevices['Home'] == 'Off') then
          commandArray['Volumio'] = 'Off'
          commandArray['Variable:VolumioVar'] = '0'
        end
--end
return commandArray
log

Code: Select all

2018-04-22 21:33:47.026 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.078 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.130 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.182 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.233 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.285 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.337 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.389 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.442 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.493 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.545 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.597 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.650 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.702 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.755 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.806 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.860 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.909 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-22 21:33:47.961 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

The script you posted has 2 lines commented out which means the IF now works totally different:

Code: Select all

if (devicechanged['Home']) then
	--if (devicechanged['Home'] == 'On') then
	commandArray['Volumio'] = 'On'
	commandArray['Variable:VolumioVar'] = '1'
elseif (time.hour >= 21 or otherdevices['Home'] == 'Off') then
	commandArray['Volumio'] = 'Off'
	commandArray['Variable:VolumioVar'] = '0'
elseif (time.hour < 10 or otherdevices['Home'] == 'Off') then
	commandArray['Volumio'] = 'Off'
	commandArray['Variable:VolumioVar'] = '0'
end
--end
return commandArray
This means for each device change this logic is executed and one of the Else If's is probably true!

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

So I need to enable that commented lines?
I did copy those devicechanged lines from some example without understanding why those where there. And i commented out because it works even commented out.
edit: I removed comments it stops that massive logging at least for now, thanks!
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

You could do it like this to avoid the continuous loop:

Code: Select all

if (devicechanged['Home']) then
	if (devicechanged['Home'] == 'On') then
		commandArray['Volumio'] = 'On'
		commandArray['Variable:VolumioVar'] = '1'
	elseif devicechanged['Home'] == 'Off') then
		commandArray['Volumio'] = 'Off'
		commandArray['Variable:VolumioVar'] = '0'
	end
end
-- change based on time 
if  (otherdevices['Volumio'] == 'On')
and (time.hour >= 21 or time.hour < 10) then
	commandArray['Volumio'] = 'Off'
	commandArray['Variable:VolumioVar'] = '0'
end

return commandArray
Although the second part of the script testing for the times really should be a Time script, not a Device script.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

Fixed issue in the above code posted using otherdevices['Volumio'] in stead of devicechanged['Volumio'] for the second part.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

Thanks, I will test later today.
Those were in same script because of couple examples in script_device_volumio.lua
So i need to add second script_time_volumio.lua?
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

I didnt have time to test before, but now I tested and it works almost in one script.
If clock was before 9 o'clock and home switch was switched on, it switched Volumio on, what is not good.

So I changed two separated scripts,
script_device_volumio.lua

Code: Select all

commandArray = {}
time = os.date("*t")
if  (otherdevices['Volumio'] == 'On') and (time.hour >= 21 or time.hour < 19) then
	commandArray['Volumio'] = 'Off'
	commandArray['Variable:VolumioVar'] = '0'
end

return commandArra

and script_time_volumio.lua

Code: Select all

commandArray = {}
 
if (devicechanged['Home']) then
	if (devicechanged['Home'] == 'On') then
		commandArray['Volumio'] = 'On'
		commandArray['Variable:VolumioVar'] = '1'
	elseif (devicechanged['Home'] == 'Off') then
		commandArray['Volumio'] = 'Off'
		commandArray['Variable:VolumioVar'] = '0'
	end
end
return commandArray
It does turn Volumio On for a moment when time is before 9, is there a way to remove that moment, I think its a 1 minute.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

Iam confused: You have now < 19 in your posted script? :?:
So what exactly is it you want it to do?
Is your question about adding a condition when Home is changing it also takes the time into account?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

sorry it left for testing because here in Finland it is evening so I am testing nearest hours.
it didnt even start when time was 20 (8pm)
I tought it will start working when someone leaves home and home switch goes off and back on. but not in my case.

what I need
if anyone is home (another script turning Home switch on) and time is between 9 am - 9pm volumio switch should be on.
if home switch is on but time is 12am-9am or 9pm -12pm volumio should be off.
if home switch is off and time is anything volumio should be off.
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

It seems you have switched the logic of the Device and Time script looking at what you have posted!

Ok this script will now only change the Volumio between 9:00 and 21:00 when Home changed to On or Off:

Code: Select all

--script_device_volumio.lua

commandArray = {}
time = os.date("*t")
if devicechanged['Home'] and time.hour < 21 and time.hour > 9 then
	if (devicechanged['Home'] == 'On') then
		commandArray['Volumio'] = 'On'
		commandArray['Variable:VolumioVar'] = '1'
	elseif (devicechanged['Home'] == 'Off') then
		commandArray['Volumio'] = 'Off'
		commandArray['Variable:VolumioVar'] = '0'
	end
end
return commandArray

This script will ensure that Volumio is Off after 21:00 and before 09:00
and it will switch On Volumio in case it is Off and somebody is Home at 09:00.

Code: Select all

--script_time_volumio.lua
commandArray = {}
time = os.date("*t")
-- switch Off when On after 21:00 till 09:00 
if  otherdevices['Volumio'] == 'On' and time.hour == 9) then
	commandArray['Volumio'] = 'Off'
	commandArray['Variable:VolumioVar'] = '0'
-- switch On when Off after 09:00 till 21:00 
elseif  (otherdevices['Volumio'] == 'Off' and otherdevices['Home'] == 'On' and time.hour < 21 and time.hour > 9) then
	commandArray['Volumio'] = 'On'
	commandArray['Variable:VolumioVar'] = '1'
end

return commandArray
Is this more or less what you are looking for?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

Big Thanks!
I will test right away
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

I changed shutoff time to 22 but it didnt switch off
but I changed line
-- switch Off when On after 21:00 till 09:00
if otherdevices['Volumio'] == 'On' and time.hour == 9) then

to
if (otherdevices['Volumio'] == 'On' and time.hour > 22 and time.hour < 9) then

so now it switched off, I will check tomorrow again..
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

You are right... I changed the wrong line ... the intent was to change the second condition to make it only switch On one time in the morning like this:

Code: Select all

--script_time_volumio.lua
commandArray = {}
time = os.date("*t")
-- switch Off when On after 21:00 till 09:00
if  otherdevices['Volumio'] == 'On' and (time.hour >= 21 or time.hour <= 9) then
	commandArray['Volumio'] = 'Off'
	commandArray['Variable:VolumioVar'] = '0'
-- switch On when Off after 09:00 till 21:00
elseif  (otherdevices['Volumio'] == 'Off' and otherdevices['Home'] == 'On' and time.hour == 9) then
	commandArray['Volumio'] = 'On'
	commandArray['Variable:VolumioVar'] = '1'
end

return commandArray
Sorry, but can test myself without a lot of effort first, so leave it to you to debug. :-)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

Thats ok and I will learn same time a lot !
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

first I needed to change
if otherdevices['Volumio'] == 'On' and (time.hour >= 21 or time.hour <= 9) then
to
if otherdevices['Volumio'] == 'On' and (time.hour >= 21 or time.hour =< 9) then
it did log ')' expected near '='
it works kind of:
- it doesnt set volumio switch off when home switch goes off.
-it does set volumio on when home switch is ON and time is before 9
-it does set volumio on when home switch goes ON and time is after 9
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

timop wrote: Saturday 28 April 2018 9:21 first I needed to change
if otherdevices['Volumio'] == 'On' and (time.hour >= 21 or time.hour <= 9) then
to
if otherdevices['Volumio'] == 'On' and (time.hour >= 21 or time.hour =< 9) then
it did log ')' expected near '='
I do not see that change solving a missing ) error unless I am mistaken.
timop wrote: Saturday 28 April 2018 9:21 it works kind of:
- it doesnt set volumio switch off when home switch goes off.
This should work between 09:00 and 21:00 as outside this window it is already Off with the posted script. YOu say it doesn't do that?
timop wrote: Saturday 28 April 2018 9:21 -it does set volumio on when home switch is ON and time is before 9
This should not happen with the posted script!
timop wrote: Saturday 28 April 2018 9:21 -it does set volumio on when home switch goes ON and time is after 9
So that is OK.

Could you post the current versions of both scripts and the name of the script that code is in?
It probably is best to add some debugging lines in the scripts to ensure we understand what is happening when. Will do so after you posted the current versions.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

about that ) near = error, after I changed =< to <= it stopped error logging.

here are scripts.

Code: Select all

--script_time_Volumio.lua
commandArray = {}
time = os.date("*t")
-- switch Off when On after 21:00 till 09:00 
if  (otherdevices['Volumio'] == 'On' and time.hour >= 21 and time.hour <= 9) then
        commandArray['Volumio'] = 'Off'
        commandArray['Variable:VolumioVar'] = '0'
-- switch On when Off after 09:00 till 21:00 
elseif  (otherdevices['Volumio'] == 'Off' and otherdevices['Home'] == 'On' and time.hour == 9) then
        commandArray['Volumio'] = 'On'
        commandArray['Variable:VolumioVar'] = '1'
end

return commandArray

Code: Select all

--script_device_Volumio.lua

commandArray = {}
time = os.date("*t")
if devicechanged['Home'] and time.hour < 21 and time.hour > 9 then
        if (devicechanged['Home'] == 'On') then
                commandArray['Volumio'] = 'On'
                commandArray['Variable:VolumioVar'] = '1'
        elseif (devicechanged['Home'] == 'Off') then
                commandArray['Volumio'] = 'Off'
                commandArray['Variable:VolumioVar'] = '0'
        end
end
return commandArray

should this "time = os.date("*t")" be before or after command array?

I made one dummy switch for replacing Home, with that I can test coming home and leaving there easier.
but I have wait hourly like changing next to 12, so maybe adding minutes to time could be faster to test..
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

What time did you have this issue? :
- it doesnt set volumio switch off when home switch goes off.
Looking at our logic this will obviously only work between 10:00 and 20:00 as that is what we test for.

EDIT: Guess this should fix that?:

Code: Select all

--script_time_Volumio.lua
commandArray = {}
time = os.date("*t")
-- switch Off when On after 21:00 till 09:00 
if  (otherdevices['Volumio'] == 'On' and time.hour > 21 and time.hour <= 9) then
        commandArray['Volumio'] = 'Off'
        commandArray['Variable:VolumioVar'] = '0'
-- switch On when Off at 09:00 
elseif  (otherdevices['Volumio'] == 'Off' and otherdevices['Home'] == 'On' and time.hour == 9 and time.min == 0) then
        commandArray['Volumio'] = 'On'
        commandArray['Variable:VolumioVar'] = '1'
end

return commandArray


--script_device_Volumio.lua
commandArray = {}
time = os.date("*t")
if devicechanged['Home'] and time.hour < 21 and time.hour > 8 then
        if (devicechanged['Home'] == 'On') then
                commandArray['Volumio'] = 'On'
                commandArray['Variable:VolumioVar'] = '1'
        elseif (devicechanged['Home'] == 'Off') then
                commandArray['Volumio'] = 'Off'
                commandArray['Variable:VolumioVar'] = '0'
        end
end
return commandArray
Jos
Last edited by jvdz on Saturday 28 April 2018 10:31, edited 1 time in total.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
timop
Posts: 57
Joined: Sunday 03 January 2016 17:10
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop »

well it is all after 9, like now if I manually set home switch off volumio still stays On.
those variables, I may be never need those, but nice to have if I some day needed :)
I have also variable for Home switch..
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz »

Understand that 9:10 is after 9 but the hour will still be set to 9 so the previous test (time.hour > 9 ) will still be not true that is why I changed it to "> 8"!
This version has some debugging print statements which helps to identify which part of the logic runs when:

Code: Select all

--script_time_Volumio.lua
commandArray = {}
time = os.date("*t")
-- switch Off when On after 21:00 till 09:00
if  (otherdevices['Volumio'] == 'On' and time.hour > 21 and time.hour <= 9) then
	print("Set Volumio to Off because between 21:00 - 9:00    script_time_Volumio.lua")
	commandArray['Volumio'] = 'Off'
	commandArray['Variable:VolumioVar'] = '0'
-- switch On when Off at 09:00
elseif  (otherdevices['Volumio'] == 'Off' and otherdevices['Home'] == 'On' and time.hour == 9 and time.min == 0) then
	print("Set Volumio to On because its 9:00 and Home=On        script_time_Volumio.lua")
	commandArray['Volumio'] = 'On'
	commandArray['Variable:VolumioVar'] = '1'
end

return commandArray


--script_device_Volumio.lua
commandArray = {}
time = os.date("*t")
if devicechanged['Home'] and time.hour < 21 and time.hour > 8 then
	if (devicechanged['Home'] == 'On') then
		commandArray['Volumio'] = 'On'
		commandArray['Variable:VolumioVar'] = '1'
	elseif (devicechanged['Home'] == 'Off') then
		commandArray['Volumio'] = 'Off'
		commandArray['Variable:VolumioVar'] = '0'
	end
	print("Device Home changed to : " .. devicechanged['Home'] .. " and it's between 9:00 and 21:00. Volumio will be set to:" .. commandArray['Volumio'] .. "        script_device_Volumio.lua")
end
return commandArray
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest