DZ Vents Light timer Help Please  [Solved]

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

Moderator: leecollings

Cndiann

Re: DZ Vents Light timer Help Please

Post by Cndiann »

Could you maybe share your final script? Looks useful to me also
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: DZ Vents Light timer Help Please

Post by madpatrick »

Sure

Code: Select all

local PIR                   = 'PIR Sensor'                      -- change to name of your PIR
local light                 = 'Woonkamer'                       -- change to name of your light/group
local lux                   = 'PIR Lux'                         -- change to name of your lux device
local Sleep                 = '23:00'                           -- after sleep time switch off lamps unless PIR movement and LUX value < xx
local retrigger             = 'Retrigger using customEvent'
local minutesBeforeSunset   = 60                      -- 45 min before sunset

return
{
    on =
    {
        timer =
        {
            'at '  .. minutesBeforeSunset .. ' minutes before sunset',  -- This will be concatenated to xx minutes before sunset
            --'every minute', -- only for testing
            'at ' .. Sleep,
        },
        customEvents =
        {
            retrigger,
        }
    },


    logging =
    {
        level = domoticz.LOG_INFO, -- Logging suppressed
        marker = '-=# light control #=- ',
    },

    execute = function(dz)

        local PIR   = dz.devices(PIR)
        local light = dz.groups(light)  -- groups instead of device
        local lux   = dz.devices(lux).lux

        dz.log(' LUX = ' .. lux,dz.LOG_FORCE)
        dz.log(PIR.name .. ' was last updated ' .. PIR.lastUpdate.secondsAgo .. ' seconds ago',dz.LOG_FORCE)
        dz.log(light.name .. ' state is ' .. light.state ,dz.LOG_FORCE)

        
 -- the text between quotes and the variables minutesBeforeSunset (60) and Sleep (23:00) will be concatenated to 
        --                             between xx minutes before sunset and 23:00
        if dz.time.matchesRule('between ' .. minutesBeforeSunset .. ' minutes before sunset and ' .. Sleep) and not(dz.time.matchesRule('at ' .. Sleep)) then 
                if lux < 16 then
                light.switchOn().checkFirst()
                dz.log(light.name .. ' switched On or already On',dz.LOG_FORCE)
            else
                dz.emitEvent(retrigger).afterSec(300) -- try again in 5 min.
                dz.log('Script will start again in 5 minutes',dz.LOG_FORCE)
            end
        else
            if PIR.lastUpdate.secondsAgo > 600 then
                light.switchOff().checkFirst()
                dz.log(light.name .. ' switched Off or already Off',dz.LOG_FORCE)
            else
                dz.emitEvent(retrigger).afterSec(300)
                dz.log('Script will start again in 5 minutes',dz.LOG_FORCE)
            end
        end
    end
}
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest