massive logging with lua script

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Saturday 28 April 2018 10:54

11:48 Home switch switched ON logs:
2018-04-28 11:48:36.818 LUA: Device Home changed to : On and it's between 9:00 and 21:00. Volumio will be set to:On script_device_Volumio.lua
2018-04-28 11:48:36.818 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-28 11:48:36.843 (etaohjauksia) Light/Switch (Volumio)

and Volumio switch switched ON

11:49 Home switch switched OFF logs:
2018-04-28 11:49:52.703 User: Admin initiated a switch command (2/Home/Off)
2018-04-28 11:49:52.704 (dummy) Lighting 1 (Home)
2018-04-28 11:49:52.706 LUA: Device Home changed to : Off and it's between 9:00 and 21:00. Volumio will be set to:Off script_device_Volumio.lua
2018-04-28 11:49:52.706 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua
2018-04-28 11:49:52.740 (etaohjauksia) Light/Switch (Volumio)

Volumio switch switched OFF.

I changed all 9 hours to 12 so it shouldnt work when home is ON before 12:00
and it works if Home goes ON so Volumio stays OFF


not sure why but seems to work now. I removed all old Volumio scripts and made new one.
I will wait till 12:00 with Home switch ON, so it should put Volumio ON also..?

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Saturday 28 April 2018 11:16

Home ON whole time, clock came to 12:00 and switched volumio ON, yes
2018-04-28 12:00:00.424 LUA: Set Volumio to On because its 12:00 and Home=On script_time_Volumio.lua

but now when I switched Home OFF volumio stayed ON, no logging except this
2018-04-28 12:12:22.979 User: Admin initiated a switch command (2/Home/Off)

edit:
I set home and volumio OFF and changed time to 12:20
elseif (otherdevices['Volumio'] == 'Off' and otherdevices['Home'] == 'On' and time.hour == 12 and time.min == 20) then
and volumio stayed OFF like it should be

User avatar
jvdz
Posts: 1446
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz » Saturday 28 April 2018 11:40

What did you exactly change to make it work for 12:00? it should be:

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 > 11 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 < 12 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


And for the 09:00 - 21:00 it should be: ( which is a little different than before!)

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 > 20 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

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Saturday 28 April 2018 11:48

What did you exactly change to make it work for 12:00? it should be:
I changed all times where was 9 to 12.
so it should work between 12-22
I will test more at evening..

User avatar
jvdz
Posts: 1446
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz » Saturday 28 April 2018 11:51

Think there is still a small logic issue. Think it needs to be this for your original 9-21 logic:

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 > 20 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
Cheers,
Jos

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Saturday 28 April 2018 11:58

Yes thats the plan when it works.
For testing purposes I try change times between ON and OFF shorter, so I dont have to wait till evening and mornings..

User avatar
jvdz
Posts: 1446
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz » Saturday 28 April 2018 12:13

This is a version where you easily can change the times as they are defined with variables in both scripts:

Code: Select all

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

return commandArray


--script_device_Volumio.lua
commandArray = {}
starttime = 9
endtime = 21
time = os.date("*t")
if devicechanged['Home'] and time.hour < endtime and time.hour > starttime-1 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 "..starttime..":00 and "..endtime..":00. Volumio will be set to:" .. commandArray['Volumio'].. "        script_device_Volumio.lua")
end
return commandArray
EDIT: Fixed logic for time script.
Jos :-)
Last edited by jvdz on Sunday 29 April 2018 21:24, edited 2 times in total.

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Saturday 28 April 2018 20:27

I understand at all, I changed endtime to 22 and switched Home to On, nothing happened.
not even logging..
I am using beta 3.9269 if it does matter..
edit: reason was that script name was script_*_volumio.lua not scipt_*_Volumio.lua
in wiki there was in some page that scripts should be lowercase.. but not in my case :)

so it works at least now 21:33 when endtime is 22 and switched Home to ON.
2018-04-28 21:33:54.369 User: Admin initiated a switch command (2/Home/On)
2018-04-28 21:33:54.371 LUA: Device Home changed to : On and it's between 9:00 and 22:00. Volumio will be set to:On script_device_Volumio.lua
2018-04-28 21:33:54.371 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_device_Volumio.lua

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Saturday 28 April 2018 21:10

and when time was 22:00 nothing happened.
Volumio is still ON when Home switch is ON.
I manually switched Home OFF, and even then nothing happened.
I thing I will schedule from switch settings OFF time and not sure how to start, maybe manually.

There is update for beta, I will test to upgrade..
maybe one or two beer and think again :)
and start learning dzevents..

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Sunday 29 April 2018 13:17

This morning after I woke up about 9:30, Home switch was off and volumio off. like it should be.
after switching Home On volumio also switched ON
so now it works, very very strange :)
I set now times 9:00 and 21:00 and wont touch anything whole day, so lets see what happens at 21:00.

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Sunday 29 April 2018 21:03

Ok, time was 21:00 home switch ON and Volumio stays ON.
Nothing in domoticz logs.
I could schedule it Off from Volumio switch itself.

User avatar
jvdz
Posts: 1446
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz » Sunday 29 April 2018 21:22

I see somewhere along the versions I/we goofed up and changed the or to an and:

Code: Select all

-- switch Off when On after 21:00 till 09:00
if  (otherdevices['Volumio'] == 'On' and time.hour > 20 and time.hour < 9) then
Should ofcourse be:

Code: Select all

-- switch Off when On after 21:00 till 09:00
if  (otherdevices['Volumio'] == 'On' and (time.hour > 20 or time.hour < 9)) then
Jos

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Sunday 29 April 2018 21:33

That was it ! at least it now switched OFF :)
some many version that I come too blind for and or's.
I earlier set to go off at 22:00
2018-04-29 22:30:00.442 LUA: Set Volumio to Off because between 22:00 - 9:00 script_time_Volumio.lua
2018-04-29 22:30:00.459 (etaohjauksia) Light/Switch (Volumio)

User avatar
jvdz
Posts: 1446
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: massive logging with lua script

Post by jvdz » Sunday 29 April 2018 21:41

Sweet,
I had a look through the thread and indeed saw where that happened. ;-)
.... only caught it just now but it slipped in there a number of versions ago, before it was correct.

Jos

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Sunday 29 April 2018 22:09

I will report tomorrow about 9:00 status.
But for big thanks for your advices and efforts!
Ive been testing this before this thread (which isnt topics desciption for a long time) many hours..

timop
Posts: 68
Joined: Sunday 03 January 2016 18:10
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: massive logging with lua script

Post by timop » Monday 30 April 2018 8:01

and it works !
2018-04-30 09:00:00.271 LUA: Set Volumio to On because its 9:00 and Home=On script_time_Volumio.lua
2018-04-30 09:00:00.271 EventSystem: Script event triggered: /home/timo/domoticz/scripts/lua/script_time_Volumio.lua
2018-04-30 09:00:00.299 (etaohjauksia) Light/Switch (Volumio)

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests