Page 1 of 1

sunset does not work

Posted: Saturday 18 April 2020 22:20
by robbert1977
Hi all,

Ok I tried my first easy lua script today for switching garden lights at sunset and switch them off a few hours after.
When during testing I used a time it worked perfectly. When I us trigger 'at sunset' it doesn't work. If I use ' at nighttime' is does work.
So for the ease I made a short test script and I really don't know why sunset doesn't work it should I think.

Ok so according to domoticz the sunset was today at 20:42
I checked sunsetInMinutes to check sunset was indeed calculated correctly

Code: Select all

 return {
        active = true,
        on = {
          timer = {
          -- 'on at nighttime every 2 minutes'  -- WORKED
          -- 'on at 5 minutes before sunset'   -- DIDN't WORK at 20:37
          -- 'on at sunset'  -- DIDN't WORK at 20:42
          -- 'on 18/4 at 21:19'  -- WORKED
          }
        },
        execute = function(domoticz)
        local sunset = domoticz.time.sunsetInMinutes
        domoticz.log('sunset works ' ..sunset.. ' sunset')
      end
    } 
Log with minute time sunset

Code: Select all

2020-04-18 22:00:00.095 Status: dzVents: Info: ------ Start external script: test.lua:, trigger: "on at nighttime every 2 minutes"
2020-04-18 22:00:00.095 Status: dzVents: Info: sunset works 1242 sunset
2020-04-18 22:00:00.095 Status: dzVents: Info: ------ Finished test.lua
You would expect that you would see the sunset with following as a trigger.. but it ain't
-- Code --
timer = {
'on after sunset every minute',
'on at nighttime every 5 minutes'

-- Log --
2020-04-18 22:33:25.568 (Buienradar) General/Custom Sensor (Rainfall next Hour)
2020-04-18 22:34:25.557 (Buienradar) General/Custom Sensor (Next Rainshower Leadtime)
2020-04-18 22:35:00.487 Status: dzVents: Info: ------ Start external script: test.lua:, trigger: "on at nighttime every 5 minutes"
2020-04-18 22:35:00.487 Status: dzVents: Info: sunset works 1242 sunset
2020-04-18 22:35:00.487 Status: dzVents: Info: ------ Finished test.lua



any help would be appreciated.
Kind regards robbert

Re: sunset does not work

Posted: Saturday 18 April 2020 23:00
by waaren
robbert1977 wrote: Saturday 18 April 2020 22:20 When during testing I used a time it worked perfectly. When I us trigger 'at sunset' it doesn't work. If I use ' at nighttime' is does work.
Please always include your domoticz / dzVents version.

a modified test.

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
          'on at nighttime every 2 minutes',      -- WORKED (the on is ignored here the right syntaxis is 'at nighttime every 2 minute'
          'at 124 minutes after sunset',           -- DIDN't WORK at 20:37 
          'at sunset',                          -- DIDN't WORK at 20:42
          'on 18/4 at 22:51',                      -- WORKED
         },
        },
        
    execute = function(domoticz, item)
        domoticz.log('sunset in minutes works: ' .. domoticz.time.sunsetInMinutes)
     
        domoticz.log ('domoticzVersion: '  .. domoticz.settings.domoticzVersion)
        domoticz.log ('dzVentsVersion: '  .. domoticz.settings.dzVentsVersion)
        domoticz.log ('triggered by : '  .. item.trigger)
        
    end
} 
My results from the above script (sunset time at my location 18/4/2020 20:45)
Spoiler: show

Code: Select all

2020-04-18 22:48:00.257  Status: dzVents: Info: ------ Start internal script: dz time triggers:, trigger: "on at nighttime every 2 minutes"
2020-04-18 22:48:00.257  Status: dzVents: Info: sunset in minutes works: 1245
2020-04-18 22:48:00.257  Status: dzVents: Info: domoticzVersion: 2020.1 (build 11935)
2020-04-18 22:48:00.257  Status: dzVents: Info: dzVentsVersion: 3.0.2
2020-04-18 22:48:00.257  Status: dzVents: Info: triggered by : on at nighttime every 2 minutes
2020-04-18 22:48:00.257  Status: dzVents: Info: ------ Finished dz time triggers

2020-04-18 22:49:00.282  Status: dzVents: Info: ------ Start internal script: dz time triggers:, trigger: "at 124 minutes after sunset"
2020-04-18 22:49:00.283  Status: dzVents: Info: sunset in minutes works: 1245
2020-04-18 22:49:00.283  Status: dzVents: Info: domoticzVersion: 2020.1 (build 11935)
2020-04-18 22:49:00.283  Status: dzVents: Info: dzVentsVersion: 3.0.2
2020-04-18 22:49:00.283  Status: dzVents: Info: triggered by : at 124 minutes after sunset
2020-04-18 22:49:00.283  Status: dzVents: Info: ------ Finished dz time triggers

2020-04-18 22:50:00.301  Status: dzVents: Info: ------ Start internal script: dz time triggers:, trigger: "on at nighttime every 2 minutes"
2020-04-18 22:50:00.301  Status: dzVents: Info: sunset in minutes works: 1245
2020-04-18 22:50:00.301  Status: dzVents: Info: domoticzVersion: 2020.1 (build 11935)
2020-04-18 22:50:00.302  Status: dzVents: Info: dzVentsVersion: 3.0.2
2020-04-18 22:50:00.302  Status: dzVents: Info: triggered by : on at nighttime every 2 minutes
2020-04-18 22:50:00.302  Status: dzVents: Info: ------ Finished dz time triggers

2020-04-18 22:51:00.320  Status: dzVents: Info: ------ Start internal script: dz time triggers:, trigger: "on 18/4 at 22:51"
2020-04-18 22:51:00.320  Status: dzVents: Info: sunset in minutes works: 1245
2020-04-18 22:51:00.320  Status: dzVents: Info: domoticzVersion: 2020.1 (build 11935)
2020-04-18 22:51:00.320  Status: dzVents: Info: dzVentsVersion: 3.0.2
2020-04-18 22:51:00.320  Status: dzVents: Info: triggered by : on 18/4 at 22:51
2020-04-18 22:51:00.321  Status: dzVents: Info: ------ Finished dz time triggers

Re: sunset does not work

Posted: Saturday 18 April 2020 23:17
by robbert1977
Hi,

Thanks for your fast reply and help :P

Code: Select all

return
{
    on =
    {
        timer =
        {
          'on at nighttime every 2 minutes',      -- WORKED (the on is ignored   'at nighttime every 1 minute',
          'at 124 minutes after sunset',           -- DIDN't WORK at 20:37
          'at sunset',                          -- DIDN't WORK at 20:42
          'on 18/4 at 22:51',                      -- WORKED
         },
        },

    execute = function(domoticz, item)
        domoticz.log('sunset in minutes works: ' ..domoticz.time.sunsetInMinutes)

        domoticz.log ('domoticzVersion: '  ..domoticz.settings.domoticzVersion)
        domoticz.log ('dzVentsVersion: '  .. domoticz.settings.dzVentsVersion)
        domoticz.log ('triggered by : '  .. item.trigger)

    end
}

Code: Select all

2020-04-18 23:16:00.431 Status: dzVents: Info: ------ Start external script: test2.lua:, trigger: "on at nighttime every 2 minutes"
2020-04-18 23:16:00.431 Status: dzVents: Info: sunset in minutes works: 1242
2020-04-18 23:16:00.431 Status: dzVents: Info: domoticzVersion: 2020.1
2020-04-18 23:16:00.431 Status: dzVents: Info: dzVentsVersion: 3.0.1
2020-04-18 23:16:00.431 Status: dzVents: Info: triggered by : on at nighttime every 2 minutes
2020-04-18 23:16:00.431 Status: dzVents: Info: ------ Finished test2.lua
seems the minutes with an s is not ignored?

second could this work? 'on after sunset every minute' ?

Re: sunset does not work

Posted: Saturday 18 April 2020 23:27
by robbert1977
It worked :P

Code: Select all

return
{
    on =
    {
        timer =
        {
          'on at nighttime every 2 minutes',
          'at 163 minutes after sunset',
          'at 164 minutes after sunset',
          'at 165 minutes after sunset',
          'at sunset',
          'on 18/4 at 22:51',
         },
        },

    execute = function(domoticz, item)
        domoticz.log('sunset in minutes works: ' ..domoticz.time.sunsetInMinutes)

        domoticz.log ('domoticzVersion: '  ..domoticz.settings.domoticzVersion)
        domoticz.log ('dzVentsVersion: '  .. domoticz.settings.dzVentsVersion)
        domoticz.log ('triggered by : '  .. item.trigger)

    end
}

Code: Select all

2020-04-18 23:25:41.254 Status: User: robbert initiated a scene/group command
2020-04-18 23:26:00.536 Status: dzVents: Info: ------ Start external script: test2.lua:, trigger: "on at nighttime every 2 minutes"
2020-04-18 23:26:00.536 Status: dzVents: Info: sunset in minutes works: 1242
2020-04-18 23:26:00.536 Status: dzVents: Info: domoticzVersion: 2020.1
2020-04-18 23:26:00.536 Status: dzVents: Info: dzVentsVersion: 3.0.1
2020-04-18 23:26:00.536 Status: dzVents: Info: triggered by : on at nighttime every 2 minutes
2020-04-18 23:26:00.536 Status: dzVents: Info: ------ Finished test2.lua
2020-04-18 23:27:00.540 Status: dzVents: Info: ------ Start external script: test2.lua:, trigger: "at 165 minutes after sunset"
2020-04-18 23:27:00.541 Status: dzVents: Info: sunset in minutes works: 1242
2020-04-18 23:27:00.541 Status: dzVents: Info: domoticzVersion: 2020.1
2020-04-18 23:27:00.541 Status: dzVents: Info: dzVentsVersion: 3.0.1
2020-04-18 23:27:00.541 Status: dzVents: Info: triggered by : at 165 minutes after sunset
2020-04-18 23:27:00.541 Status: dzVents: Info: ------ Finished test2.lua

Re: sunset does not work

Posted: Saturday 18 April 2020 23:31
by waaren
robbert1977 wrote: Saturday 18 April 2020 23:17 Could this work? 'on after sunset every minute' ?
what do you want? After sunset until midnight or every minute between sunset and sunrise ?

Re: sunset does not work

Posted: Saturday 18 April 2020 23:45
by robbert1977
actually on certain months for a certain amount of time:

'at 179 minutes after sunset',
'at 182 minutes after sunset on 1/1-1/5',
'on 1/1-1/5 at 178 minutes after sunset'

looking for the right syntax I guess :P

Re: sunset does not work

Posted: Saturday 18 April 2020 23:51
by robbert1977
ok so..

'on 1/1-1/5 at 23:50' works

'on 1/1-1/5 at 178 minutes after sunset' doesn't work

'at 188 minutes after sunset on 1/1-1/5' works

that's where I really went wron as time at the end works but sunset at the end doesn't

thanks for your time!

Re: sunset does not work

Posted: Saturday 18 April 2020 23:52
by waaren
robbert1977 wrote: Saturday 18 April 2020 23:45 looking for the right syntax I guess :P
Check the timer trigger rules at the wiki