Dzvents Timer combine with dummy switch?  [Solved]

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

Moderator: leecollings

Post Reply
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Dzvents Timer combine with dummy switch?

Post by Larsoss »

Hello,

I would like to know if it is possible to switch the timer script on a dummy via Dzvents.

By this I mean that I have a dummy that shows the seasons. Autumn, Winter, etc ..

Now my script switches to a time window between 6:50 AM and 8:00 PM, but it always does. But I can also choose that for example

Dummy = Autumn, then switch between 7am & 9pm
Dummy = Winter, then switch between 08:00 & 20:00

Or is this not possible?
This is the script I currently use for switching the lamps.

Code: Select all

return
{
    on =
    {
        timer =
        {
            "every 3 minutes on mon, tue, wed, thu, fri, sat, sun between 06:50 and 20:00",
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Auto verlichting ON',
    },

    execute = function(dz)
        local lowerLux          = 11                            -- Onder welke niveau moet het script starten.
        local upperLux          = 45                            -- Boven de waarde gaan de lampen automatisch uit.
        local currentLux        = dz.devices(46).lux            --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")        --Groep schakelaar Woonkamer.
        local tuin              = dz.groups("Tuin")             --Groep schakelaar Tuin.
        local phoneLarsOn       = dz.devices(150).state == 'On' --Dummy Telefoon Lars
        local phoneDesireeOn    = dz.devices(151).state == 'On' --Dummy Telefoon Dees

        if ( currentLux < lowerLux ) and ( phoneLarsOn or phoneDesireeOn ) then
            woonkamerlampen.switchOn().checkFirst()
            tuin.switchOn().checkFirst()
        elseif currentLux > upperLux then
            woonkamerlampen.switchOff().checkFirst()
            tuin.switchOff().checkFirst()
        end
    end
}

Because I had seen something where I suspect that it is possible.

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at sunset',
            'at ' .. Sleep,
        },
        customEvents =
        {
            retrigger,
        }
    },
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents Timer combine with dummy switch?

Post by waaren »

Larsoss wrote: Monday 19 October 2020 13:13 I would like to know if it is possible to switch the timer script on a dummy via Dzvents.
Although this can be done by creating a function in the active = section , it quite complicate the script and there is no real advantage compared to a simpler solution.

Have a look at below script

Code: Select all

return
{
    on =
    {
        timer =
        {
            "every 3 minutes on mon, tue, wed, thu, fri, sat, sun between 06:50 and 22:00", 
            -- "every 3 minutes between 06:50 and 22:00",  -- this is the same ( only 7 days in a week :-) )
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Auto verlichting ON',
    },

    execute = function(dz)
        local lowerLux          = 11                            -- Onder welke niveau moet het script starten.
        local upperLux          = 45                            -- Boven de waarde gaan de lampen automatisch uit.
        local currentLux        = dz.devices(46).lux            --lux sensor
        local woonkamerlampen   = dz.groups("Woonkamer")        --Groep schakelaar Woonkamer.
        local tuin              = dz.groups("Tuin")             --Groep schakelaar Tuin.
        local phoneLarsOn       = dz.devices(150).state == 'On' --Dummy Telefoon Lars
        local phoneDesireeOn    = dz.devices(151).state == 'On' --Dummy Telefoon Dees

        local season = {}
        season.name = dz.devices('Seizoen').levelName
        season.Spring = 'at 07:00-21:00'
        season.Summer = 'at 07:00-22:00'
        season.Autumn = 'at 07:00-21:00'
        season.Winter = 'at 07:00-20:00'

        if dz.time.matchesRule(season[season.name]) then
            if ( currentLux < lowerLux ) and ( phoneLarsOn or phoneDesireeOn ) then
                woonkamerlampen.switchOn().checkFirst()
                tuin.switchOn().checkFirst()
            elseif currentLux > upperLux then
                woonkamerlampen.switchOff().checkFirst()
                tuin.switchOff().checkFirst()
            end
        else
            dz.log('No action needed (outside set time window)', dz.LOG_DEBUG)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Larsoss
Posts: 65
Joined: Friday 18 March 2016 10:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Dzvents Timer combine with dummy switch?

Post by Larsoss »

So he's still watching between 6:50 AM / 10:00 PM, but won't switch between 7:00 AM / 9:00 PM because it's now fall?

That's how I read it correctly, right?
Raspberry 4 - USB boot Domoticz /|\ Raspberry 2B - Dashticz /|\ Tasmota device's /|\ Philips Hue & Yeelight
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Dzvents Timer combine with dummy switch?  [Solved]

Post by waaren »

Larsoss wrote: Monday 19 October 2020 23:26 So he's still watching between 6:50 AM / 10:00 PM, but won't switch between 7:00 AM / 9:00 PM because it's now fall?
That's how I read it correctly, right?
No. In this example the script will be triggered every 3 minutes between 06:50 and 22:00 but in the script body you set the time per season that it will actually evaluate the lux and phones and act upon it.

So now (autumn) this example script will only do something between 07:00 and 21:00. During winter it will only do something between 07:00 and 20:00 etc.
Off course you can set the this time-window to anything you want / need. The on = timer section determines when the script start. The time-windows in the body determine when it can do something.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest