Sunrise time in text dummy

Moderator: leecollings

Post Reply
maceddy
Posts: 13
Joined: Saturday 13 January 2018 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version: 12723
Location: Hoogeveen
Contact:

Sunrise time in text dummy

Post by maceddy »

Just for the fun of it:

Every morning I get a push message with tje current temperature. That works fine.
I would like, just for the fun, to include the sunrise time.

Is there a way to put the sunrise time in a text dummy? I tried with Set dummy to sunrise, but I get 'unknown comparevariable logic_sunrisesunset' as content in the text dummy.. I think there is some conversion to be done.. Is that even possible in blockly?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sunrise time in text dummy

Post by waaren »

I don't think it can be done in Blockly.
In dzVents it would look like the script below.

If you are not yet familiar with dzvents then please look at the 10 lines using dzVents with Domoticz for an intro to dzVents and howto get this script active in domoticz.

Before activating this script you need two text sensors; named Sunset and Sunrise.

Code: Select all

return {
    on          =   {   timer     =   { "at 00:03", "at 06:03" }}, -- twice a day to be sure and 3 min past the hour because at the hour already quite busy 
     
    execute = function( dz )
        local function minutes2time(minutes)   -- integer in; string out 
            local hour      = string.format("%02d",math.floor(minutes / 60))
            local minutes   = string.format("%02d",minutes - (hour * 60))
            return (hour .. ":" .. minutes) --  string out 
        end
        
        dz.devices("Sunset").updateText(minutes2time(dz.time.sunsetInMinutes))
        dz.devices("Sunrise").updateText(minutes2time(dz.time.sunriseInMinutes))
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
alanlsmith
Posts: 132
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: Latest β
Location: Near London (Saaarf!)
Contact:

Re: Sunrise time in text dummy

Post by alanlsmith »

or in Lua if you fancy it.

Just change text device idx & time to run if you want to.

script_time_displaysunset.lua

Code: Select all

commandArray = {}

local houroftheday = tonumber(os.date("%H"))
local minutesofthehour = tonumber(os.date("%M"))
local timeinminutes = (houroftheday *60) + minutesofthehour
local dawn = timeofday['SunriseInMinutes']
local dawnminute = dawn % 60
local dawnhour = (dawn - dawnminute) /60

--Change to suit--
local sunsetdeviceIDX = 508 --idx of text device

if(timeinminutes == 180) then -- 03:00 --Time to run script

	displaysunset = 'Sunrise: ' ..dawnhour.. ':' ..dawnminute
	commandArray[#commandArray+1] = {['UpdateDevice'] = sunsetdeviceIDX.. '|0|' ..displaysunset}

end
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
Jubbes
Posts: 33
Joined: Wednesday 24 October 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sunrise time in text dummy

Post by Jubbes »

is it possible to include civil twilight start and civil twilight end in the dzvents code?

Jubbes
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sunrise time in text dummy

Post by waaren »

Jubbes wrote: Wednesday 22 May 2019 13:38 is it possible to include civil twilight start and civil twilight end in the dzvents code?
Sure. (available in dzVents version >= 2.4.7)

Code: Select all

-- dzVents version >= 2.4.7
return {
    timer     =   { "at 00:03", "at 06:03" }, -- twice a day to be sure and 3 min past the hour because at the hour already quite busy 
     
    execute = function( dz )
        local function minutes2time(minutes)   -- integer in; string out 
            local hour      = string.format("%02d",math.floor(minutes / 60))
            local minutes   = string.format("%02d",minutes - (hour * 60))
            return (hour .. ":" .. minutes) --  string out 
        end
        
        dz.devices("Sunset").updateText("Sunset: " .. minutes2time(dz.time.sunsetInMinutes).. "\nCivil twilight end: " .. minutes2time(dz.time.civTwilightEndInMinutes or "-"))
        dz.devices("Sunrise").updateText("Sunrise: ".. minutes2time(dz.time.sunriseInMinutes).. "\nCivil twilight start: " .. minutes2time(dz.time.civTwilightStartInMinutes or "-"))
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jubbes
Posts: 33
Joined: Wednesday 24 October 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sunrise time in text dummy

Post by Jubbes »

Perfect waaren,
i have one button for one astro event:

dz.devices("Civil Twilight End").updateText(minutes2time(dz.time.civTwilightEndInMinutes))
dz.devices("Civil Twilight Start").updateText(minutes2time(dz.time.civTwilightStartInMinutes))
dz.devices("Sunset").updateText(minutes2time(dz.time.sunsetInMinutes))
dz.devices("Sunrise").updateText(minutes2time(dz.time.sunriseInMinutes))

is it possible to add nautical twilight start/end and astronomical twilight start/end for four buttons?

Thank you,
jubbes
Jubbes
Posts: 33
Joined: Wednesday 24 October 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sunrise time in text dummy

Post by Jubbes »

I mean what is the short Name from Nautical and Astronimical Twilight for the Script like civTwilightEnd ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sunrise time in text dummy

Post by waaren »

Jubbes wrote: Friday 24 May 2019 9:31 I mean what is the short Name from Nautical and Astronimical Twilight for the Script like civTwilightEnd ?
There is none in dzVents but I am trying to get it in another way. Script should be available today.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jubbes
Posts: 33
Joined: Wednesday 24 October 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sunrise time in text dummy

Post by Jubbes »

2.4.19
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sunrise time in text dummy

Post by waaren »

Jubbes wrote: Friday 24 May 2019 10:072.4.19
Posted the revised script in dzVents examples
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jubbes
Posts: 33
Joined: Wednesday 24 October 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sunrise time in text dummy

Post by Jubbes »

Cool, thank you.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest