Seconds between midnight and sunset

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

Moderator: leecollings

Post Reply
tonse
Posts: 3
Joined: Friday 11 March 2016 13:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8771
Contact:

Seconds between midnight and sunset

Post by tonse »

I need to send a command to an espeasy device. It consist of the starttime and the duration. That way the espeasy can handle the "off" command by itself. This feels more secure then sending the "off" command separate. If that command is missed, the pump will keep on running in my pool

So i need the seconds between sunset and midnight

I tried the code below. I got stuck with the Time property. I do not know where to go or which function to use.
SunsetToMidnight is a uservariable

Code: Select all

return {

	active = true, 

on = {
        timer = {'60 minutes before sunset'}
    },
	execute = function(domoticz,dummy)
	    local Time = require('Time')
local tA = Time('00:00:00')
local tB = Time('sunset')

print(tB.compare(tA).secs) 
	  
	    domoticz.variables('SunsetToMidnight').set(2378)
	   
	
	end

}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Seconds between midnight and sunset

Post by dannybloe »

Time('sunset') doesn't work. You need to pass a valid time.

I guess you meant to do this:

Code: Select all

local seconds = (24 * 3600) - domoticz.time.sunsetInMinutes * 60
See domoticz.time.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest