Lua script Switch On between 2 hours

Moderator: leecollings

Post Reply
moral3jo
Posts: 1
Joined: Tuesday 08 March 2016 23:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua script Switch On between 2 hours

Post by moral3jo »

hello, i want to share my script. It works and I used it some months.
Now I change for another version so before delete and never see again I think is a good idea share.
I try to explain.
I have 2 temperature selectors ( not sure the english name) and I use to init and finish times (Habitación-Encender and Habitacion-Apagar)
I use it bc i cant found another switch I can change easy. (If there is another easy version welcome please)
So I use this 2 temperature selector to put hours. I put a lua script in folder with name "script_time_habitacion.lua" and executes every minutes.
And another switch "Hab-Activa" to disabled all this hours.

Now I use google calendar to control the switches with python so I dont need more this
hope your replys and sorry for my english

Code: Select all

function dentroHorario(ahora, ini, fin)
	ahora = tonumber(ahora)
	ini = tonumber(ini)
	fin = tonumber(fin)
	if fin<ini then
		if ahora>=ini then
			return true;
		elseif ahora<=fin then
			return true
		else
			return false
		end
	else
		hi = ini - ahora;
		hf = fin - ahora;
		if hi<=0 and hf>=0 then
			return true
		else
			return false
		end
	end
end

commandArray = {}
now = os.date("*t")
habitacion = otherdevices['Habitación']
horaActual = now.hour
horaInicio = otherdevices_svalues['Habitación-Encender']
horaFin = otherdevices_svalues['Habitacion-Apagar']

print('Mirando habitacion')
print(horaActual)
print(horaInicio)
print(horaFin)
print(habitacion)

if otherdevices['Hab-Activa']=="On" then
	if dentroHorario(horaActual, horaInicio, horaFin) then
		if habitacion=="Off" then
			commandArray['Habitación']='On'
			print('**HABITACION-ON')
		else
			print('**HABITACION-DEJO ON')
		end
	else
		if habitacion=="On" then
			commandArray['Habitación']='Off'
			print('**HABITACION-OFF')
		else
			print('**HABITACION-DEJO OFF')--*
		end
	end
end

return commandArray

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest