nighttime not working  [Solved]

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

Moderator: leecollings

Post Reply
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

nighttime not working

Post by molnaratti »

I want to turn on my outdoor lights at night. Unfortunately, for some reason, it always turns on, ignoring the 'at nighttime' option. What do I mess up?

Code: Select all

return {
    on = {
      timer = { 'at nighttime' },
      devices = { 'terasz mozgas' }
    },
    execute = function(domoticz, item)
      if (item.isTimer) then
         -- the timer was triggered
         domoticz.devices('terasz').switchOff()
         domoticz.devices('Pince elott kulteri l').switchOff()
      elseif (item.isDevice and item.active) then
         -- it must be the detector
         domoticz.devices('terasz').switchOn().forMin(6)
         domoticz.devices('Pince elott kulteri l').switchOn().forMin(6)
      end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: nighttime not working

Post by waaren »

molnaratti wrote: Monday 13 April 2020 13:51 I want to turn on my outdoor lights at night. Unfortunately, for some reason, it always turns on, ignoring the 'at nighttime' option. What do I mess up?
Thx for reporting. Seems like a bug in dzVents. Until fixed you can use

Code: Select all

'every minute at nighttime'
if you want the script to be processed every minute during nighttime or

Code: Select all

'at sunset' 
if you want the script to be processed only at the start of nighttime

BTW. you are now switching the devices Off at nighttime in your script
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: nighttime not working

Post by molnaratti »

Thanks for the help.
Unfortunately, "every minute at nighttime" and "at sunset" doesn't work either.

Domoticz2020.1 (build 11835)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: nighttime not working

Post by waaren »

molnaratti wrote: Monday 13 April 2020 14:26 Thanks for the help.
Unfortunately, "every minute at nighttime" and "at sunset" doesn't work either.

Domoticz2020.1 (build 11835)
Checked this again but it is working as expected. Are you sure Eventsystem and dzVents are enabled ? I tested with the script below so you should see lines in the log like:

Code: Select all

2020-04-13 21:21:00.074  Status: dzVents: Info: ------ Start internal script: dz timer nighttime:, trigger: "at nighttime"
2020-04-13 21:21:00.074  Status: dzVents: !Info: item.trigger is: at nighttime
2020-04-13 21:21:00.075  Status: dzVents: Info: ------ Finished dz timer nighttime

Code: Select all

return 
{
    on = 
    {
        timer = 
        { 
            'at nighttime', 
        },
        devices = 
        { 
            'terasz mozgas' 
        }
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'nighttime',
    },
    
    execute = function(dz, item)
        dz.log('item.trigger is: ' .. item.trigger,dz.LOG_FORCE)
        if item.isTimer then
            -- the timer was triggered
            dz.devices('terasz').switchOff()
            dz.devices('Pince elott kulteri l').switchOff()
        elseif item.isDevice and item.active) then
            -- it must be the detector
            dz.devices('terasz').switchOn().forMin(6)
            dz.devices('Pince elott kulteri l').switchOn().forMin(6)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: nighttime not working

Post by molnaratti »

waaren wrote: Monday 13 April 2020 21:22
molnaratti wrote: Monday 13 April 2020 14:26 Thanks for the help.
Unfortunately, "every minute at nighttime" and "at sunset" doesn't work either.

Domoticz2020.1 (build 11835)
Checked this again but it is working as expected. Are you sure Eventsystem and dzVents are enabled ? I tested with the script below so you should see lines in the log like:

Code: Select all

2020-04-13 21:21:00.074  Status: dzVents: Info: ------ Start internal script: dz timer nighttime:, trigger: "at nighttime"
2020-04-13 21:21:00.074  Status: dzVents: !Info: item.trigger is: at nighttime
2020-04-13 21:21:00.075  Status: dzVents: Info: ------ Finished dz timer nighttime

Code: Select all

return 
{
    on = 
    {
        timer = 
        { 
            'at nighttime', 
        },
        devices = 
        { 
            'terasz mozgas' 
        }
    },
    
    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'nighttime',
    },
    
    execute = function(dz, item)
        dz.log('item.trigger is: ' .. item.trigger,dz.LOG_FORCE)
        if item.isTimer then
            -- the timer was triggered
            dz.devices('terasz').switchOff()
            dz.devices('Pince elott kulteri l').switchOff()
        elseif item.isDevice and item.active) then
            -- it must be the detector
            dz.devices('terasz').switchOn().forMin(6)
            dz.devices('Pince elott kulteri l').switchOn().forMin(6)
        end
    end
}
Yes, Eventsystem and dzVents enabled. I modified the script as suggested, but the nighttime log will not be:

2020-04-22 13:04:02.553 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/Script #4.lua

"2020-04-22 12:57:00.742 Status: dzVents: Info: ------ Finished halo_ajto_warn
2020-04-22 12:57:00.742 Status: dzVents: Info: ------ Start internal script: halo_klima_futes_dz:, trigger: "at 7:30-21:46"
2020-04-22 12:57:00.753 Status: dzVents: Info: ------ Finished halo_klima_futes_dz
2020-04-22 12:57:00.753 Status: dzVents: Info: ------ Start internal script: hatso_ajto_warn:, trigger: "every minute"
2020-04-22 12:57:00.757 Status: dzVents: Info: ------ Finished hatso_ajto_warn
2020-04-22 12:57:00.758 Status: dzVents: Info: ------ Start internal script: Kandallo termosztát:, trigger: "every minute"
2020-04-22 12:57:00.766 Status: dzVents: Info: ------ Finished Kandallo termosztát
2020-04-22 12:57:00.767 Status: dzVents: Info: ------ Start internal script: radiator_dz:, trigger: "every minute"
2020-04-22 12:57:00.767 Status: dzVents: Info: ------ Finished radiator_dz"

i checked the raspberry clock with the date command, ok.
The problems came when updating to the new stable, now I switched to devel branch but it didn't solve.
I don't understand where the problem might be.
Thank you for your help, sorry for my bad English.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: nighttime not working

Post by waaren »

molnaratti wrote: Wednesday 22 April 2020 13:02 Interestingly, only new dzvents scripts do not take the nighttime switch into account.
The problems came when updating to the new stable, now I switched to devel branch but it didn't solve.
Maybe I don't understand the intention of the script correctly. Can you describe in words what you expect the script to do during daytime and what you expect it to do during nighttime ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: nighttime not working

Post by molnaratti »

waaren wrote: Wednesday 22 April 2020 13:13
molnaratti wrote: Wednesday 22 April 2020 13:02 Interestingly, only new dzvents scripts do not take the nighttime switch into account.
The problems came when updating to the new stable, now I switched to devel branch but it didn't solve.
Maybe I don't understand the intention of the script correctly. Can you describe in words what you expect the script to do during daytime and what you expect it to do during nighttime ?
Only turn on the lamp for 5 minutes at night when the motion sensor is turned on, currently it always turns on, not just at night.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: nighttime not working

Post by waaren »

molnaratti wrote: Wednesday 22 April 2020 14:02 Only turn on the lamp for 5 minutes at night when the motion sensor is turned on, currently it always turns on, not just at night.
You should use this syntax in the on = section to achieve that.

Code: Select all

return 
{
    on = 
    {
        devices = 
        { 
            ['terasz mozgas'] = { 'at nighttime' },
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all works OK
        marker = 'device at nighttime',
    },

    execute = function(dz, item)
        local terasz = dz.devices('terasz')
        if item.active then
            terasz.cancelQueuedCommands()
            terasz.switchOn().checkFirst()
            terasz.switchOff().afterSec(300)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
molnaratti
Posts: 34
Joined: Friday 02 February 2018 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: nighttime not working  [Solved]

Post by molnaratti »

Thank you waaren!

Your code is working flawlessly. With that in mind, I will review the others as well.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests