Page 1 of 1

Convert sunset as $

Posted: Wednesday 31 March 2021 10:47
by Dickey
Hi,
Need to convert sunset as a $ as 20:30 f.I.
Search the wiki, but can’t find it.

Re: Convert sunset as $

Posted: Wednesday 31 March 2021 11:41
by waaren
Dickey wrote: Wednesday 31 March 2021 10:47 Hi,
Need to convert sunset as a $ as 20:30 f.I.
Search the wiki, but can’t find it.
Can you please elaborate a bit on this? Based on this one line, I have no clear idea on what you try to achieve.

Re: Convert sunset as $

Posted: Wednesday 31 March 2021 12:23
by Dickey
Hi waaren,

Thanks for you're answer. This is a part of the code.
Want to have a action between 2 different moments.

Code: Select all

local onTime = 'sunset'
local ofTime        = '23:00'
local printerTime   = '09:00'
commandArray = {}
    if  os.date('%H:%M') >= onTime and os.date('%H:%M') <= ofTime then 
        if otherdevices['Wie is er thuis'] == 'Off' then
            print ("We zijn NIET thuis")

Re: Convert sunset as $

Posted: Wednesday 31 March 2021 12:36
by erem
maybe this will help: Use sunset and sunrise time in lua

viewtopic.php?t=8572

Re: Convert sunset as $

Posted: Wednesday 31 March 2021 12:38
by Dickey
Thanks Rob,

Wil try that, let you know the result.

Dick

Re: Convert sunset as $

Posted: Wednesday 31 March 2021 12:57
by waaren
Dickey wrote: Wednesday 31 March 2021 12:23 Hi waaren,

Thanks for you're answer. This is a part of the code.
Want to have a action between 2 different moments.

Code: Select all

local onTime = 'sunset'
local ofTime        = '23:00'
local printerTime   = '09:00'
commandArray = {}
    if  os.date('%H:%M') >= onTime and os.date('%H:%M') <= ofTime then 
        if otherdevices['Wie is er thuis'] == 'Off' then
            print ("We zijn NIET thuis")

OK. sunset moment is passed to Lua as minutes since midnight in _G.timeofday.SunsetInMinutes

This will give you two options.

Code: Select all

commandArray = {}

local onTime = _G.timeofday.SunsetInMinutes  -- sunset as minutes since midnight
local now = os.date('%H') * 60 + os.date('%M') -- now in minutes since midnight

local ofTime        = '23:00'
local printerTime   = '09:00'

    if  now >= onTime and os.date('%H:%M') <= ofTime then 
        if otherdevices['Wie is er thuis'] == 'Off' then
            print ("We zijn NIET thuis")
        end
    end

return commandArray
or

Code: Select all

local function minutesToTime(minutes)
    local h =  math.floor(minutes / 60)
    local hh = ('0' .. h):sub(-2)
    local mm = ('0' .. minutes - (h * 60)):sub(-2)
    return hh .. ':' .. mm
end


commandArray = {}

local onTime = minutesToTime(_G.timeofday.SunsetInMinutes)  -- sunset as hh:mm

print(onTime)

local ofTime        = '23:00'
local printerTime   = '09:00'

    if  os.date('%H:%M') >= onTime and os.date('%H:%M') <= ofTime then 
        if otherdevices['Wie is er thuis'] == 'Off' then
            print ("We zijn NIET thuis")
        end
    end

return commandArray


Re: Convert sunset as $

Posted: Wednesday 31 March 2021 14:21
by Dickey
You been very busy :D Tnx for that.
I used opt 2. Did not know the ... minutesToTime(_G.timeofday.SunsetInMinutes).
This is new piece:

Code: Select all

local ofTime        = '23:00'
local printerTime   = '09:00'
local function minutesToTime(minutes)
    local h =  math.floor(minutes / 60)
    local hh = ('0' .. h):sub(-2)
    local mm = ('0' .. minutes - (h * 60)):sub(-2)
    return hh .. ':' .. mm
end
commandArray = {}
local onTime = minutesToTime(_G.timeofday.SunsetInMinutes)  -- sunset as hh:mm
    if  now >= onTime and os.date('%H:%M') <= ofTime then 
        if otherdevices['Wie is er thuis'] == 'Off' then
            print ("We zijn NIET thuis")
            commandArray['Group:Hoofdverlichting']='Inactive'
Appreciate you're help.
Thanks a lot.