Convert sunset as $

Moderator: leecollings

Post Reply
Dickey
Posts: 25
Joined: Friday 19 April 2019 22:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Netherlands
Contact:

Convert sunset as $

Post by Dickey »

Hi,
Need to convert sunset as a $ as 20:30 f.I.
Search the wiki, but can’t find it.
Dz-beta | Dashticz 3.8.10 BETA | Tradfri | RF-Link | Z-Wave | Harmony | Unify | P1 |
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Convert sunset as $

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Dickey
Posts: 25
Joined: Friday 19 April 2019 22:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: Convert sunset as $

Post 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")
Dz-beta | Dashticz 3.8.10 BETA | Tradfri | RF-Link | Z-Wave | Harmony | Unify | P1 |
User avatar
erem
Posts: 230
Joined: Tuesday 27 March 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Amsterdam/netherlands
Contact:

Re: Convert sunset as $

Post by erem »

maybe this will help: Use sunset and sunrise time in lua

viewtopic.php?t=8572
Regards,

Rob
Dickey
Posts: 25
Joined: Friday 19 April 2019 22:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: Convert sunset as $

Post by Dickey »

Thanks Rob,

Wil try that, let you know the result.

Dick
Dz-beta | Dashticz 3.8.10 BETA | Tradfri | RF-Link | Z-Wave | Harmony | Unify | P1 |
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Convert sunset as $

Post 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

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Dickey
Posts: 25
Joined: Friday 19 April 2019 22:29
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Netherlands
Contact:

Re: Convert sunset as $

Post 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.
Dz-beta | Dashticz 3.8.10 BETA | Tradfri | RF-Link | Z-Wave | Harmony | Unify | P1 |
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest