Page 1 of 1

compare system time with user variable

Posted: Friday 31 August 2018 12:53
by rkarolek
hi,
i try write script which are turn on/off light in specific time range, but i need to declare start and stop time.
I try use "user variable" but i have no idea how to compare time from user variable with current system time.
I wasted all yd's evening w/o any success :(

Is it possible to do?

Re: compare system time with user variable

Posted: Friday 31 August 2018 13:17
by SweetPants
Tried dzVentz? https://www.domoticz.com/wiki/DzVents:_ ... _scripting "on Timer" function?

Re: compare system time with user variable

Posted: Friday 31 August 2018 13:34
by rkarolek
sure
but it doesnt fit to me, because i cant (or i dont know how) put "time" from user variable, i prefer change start/stop time by changing variable not by change in script.

Re: compare system time with user variable

Posted: Friday 31 August 2018 17:21
by waaren
rkarolek wrote: Friday 31 August 2018 13:34 sure
but it doesnt fit to me, because i cant (or i dont know how) put "time" from user variable, i prefer change start/stop time by changing variable not by change in script.
Check this post on how to read uservariable time values with dzVents.

Re: compare system time with user variable

Posted: Friday 31 August 2018 20:38
by rkarolek
i think i found solution, its so simple that i can believe it took me so long time ;)

Code: Select all

return {
   on = {
  	timer = {'between 12:00 and 22:00'}    
   },

   execute = function(domoticz)
       
        LED_Sunny_On = domoticz.variables('Sunny_ON').value    
	LED_Sunny_Off = domoticz.variables('Sunny_OFF').value 
	Time = domoticz.time.rawTime
	
	if Time > LED_Sunny_On and Time < LED_Sunny_Off then
	    domoticz.log('SUNNY_ON')
	    domoticz.devices('Akwarium ogólne - LED Sunny').switchOn().checkFirst()
        else
           domoticz.log('SUNNY_OFF')
           domoticz.devices('Akwarium ogólne - LED Sunny').switchOff().checkFirst()
        end

Its works fine,
read time ON/OFF from user variable Sunny_ON and Sunny_OFF, and set switch on between this times, in the rest time switch is off.
now i can setting this time w/o editing script \o/