compare system time with user variable

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

Moderator: leecollings

Post Reply
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

compare system time with user variable

Post 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?
SweetPants

Re: compare system time with user variable

Post by SweetPants »

Tried dzVentz? https://www.domoticz.com/wiki/DzVents:_ ... _scripting "on Timer" function?
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: compare system time with user variable

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: compare system time with user variable

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rkarolek
Posts: 33
Joined: Friday 31 August 2018 12:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: compare system time with user variable

Post 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/
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest