Need some help with script please

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

Moderator: leecollings

Post Reply
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Need some help with script please

Post by leby »

Hi all,

I have a script that should turn on a group in the morning 05:45 on weekdays and 07:00 on weekends. If the sun is already up since more than 20 minutes the light should not turn on. The group has both light indoor and outdoor. If it's daylight the the outdoor lights should turn off.

If the time have passed sunrise with more than 2 hours and there has been no movement in the house for the past 20 minutes the all light should turn off.

When the time pass 10 o'clock in the morning the light should be turned off no matter movements or not.

I have a variable with Idx (5) that another script set to "Natt" when the light goes out in the evening.

The lights goes on as intended but it does not turn off at all. Obviously there is something wrong in my amature script :?
Anyone that can see my mistake and enlight me?

Code: Select all

return {
	active = true, 
	on = {
		timer = {'at 05:45 - 10:15 every 5 minutes on mon,tue,wed,thu,fri', 'at 07:00 - 10:15 every 5 minutes on sat, sun'}
	},
	execute = function(domoticz, device)
        local Morgon = domoticz.groups(1) ----- all lights in the group that should turn on in the morning
        local Alla = domoticz.groups(2) ----- all lights inside the house
        local Ute = domoticz.groups(5) ----- all lights outside the house
        local Kok_pir = domoticz.devices(161) ----- Pir in the kitchen
        local Hall_pir = domoticz.devices(37) ----- Pir in the hallway
        local tid = domoticz.time.secondsSinceMidnight/60 --- time since midnight in minutes
	local tidig = (domoticz.time.sunriseInMinutes + 20) --- should not turn on if this has passed
	local sen = (domoticz.time.sunriseInMinutes + 120) ---- turn of if no movement at this time
	local status = domoticz.variables(5) --- the variable that I use to control the status

		if      tid < tidig and status.value == 'Natt' then
		        Morgon.switchOn()
		        status.set('Morgon')
		
		elseif  domoticz.time.isDayTime and status.value == 'Morgon' then
		        Ute.switchOff()
		        status.set('Dagsljus')
		
		elseif  tid > sen and Hall_pir.lastUpdate.minutesAgo > 20 and Kok_pir.lastUpdate.minutesAgo > 20 and status.value ~= 'Dag' then
		        Alla.switchOff()
		        Ute.switchOff()
		        status.set('Dag')
		
	    elseif  status.value ~= 'Dag' and tid >= 600 then
		        Ute.switchOff()
		        Alla.switchOff()
		        status.set('Dag')
		end
		
	end
}
/lennart
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Need some help with script please

Post by leby »

Is the timer so sensitive that

Code: Select all

timer = {'at 05:45 - 10:15 every 5 minutes on mon,tue,wed,thu,fri', 'at 07:00 - 10:15 every 5 minutes on sat, sun'}
is different from

Code: Select all

timer = {'at 05:45-10:15 every 5 minutes on mon,tue,wed,thu,fri', 'at 07:00-10:15 every 5 minutes on sat, sun'}
?, does it matter if there is a space between the dash and the time?

Regards / lennart
/lennart
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Need some help with script please

Post by leby »

Well, I will answer my self ;-) it does matter if there is a space between the dash and the time in a time trigger. With a space in there the trigger will only trigger once on the starting time and no more.
So, I nearly expect my script that had the initial question to run tomorrow morning after that I have removed the space.

/l
/lennart
leby
Posts: 98
Joined: Monday 28 July 2014 9:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Stockholm
Contact:

Re: Need some help with script please

Post by leby »

So live in production I can report that the space should not be there... (probably in the documentation already)
with 05:45-10:15 instead of 05:45 - 10:15 it works like a charm..
/lennart
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest