Switch dzvents script to off  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
DRB2019
Posts: 24
Joined: Saturday 06 July 2019 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Switch dzvents script to off

Post by DRB2019 »

Hello,

I'am running the script below to switch 2 lights on in my living room, but
sometimes i do not want the script to run.

1. Is it possible with a dummy switch in domoticz to switch the script to off (i mean the switch on/off in the events editor),
2. or is it better to implement a dummy switch state in the script to exit the script when this switch is on.

If the answer is option 2, can you please tell me how to implement this in the script below.

Thnx in advance,
René

Code: Select all

return
{
    on = {
        timer   = {'every 10 minutes between 15:30 and 22:00'},  
    },

    logging =
    {
        level = domoticz.LOG_ERROR,  -- change to LOG_ERROR when ok (was LOG_DEBUG)
        marker = 'dusk sensor',
    },

    execute = function(domoticz)
        local dusk = domoticz.devices('Schemerschakelaar1')

        if  dusk.state == 'On' and domoticz.devices('Staande_lamp').state == 'Off' then
            domoticz.devices('Staande_lamp').switchOn()
            domoticz.devices('Dressoir').switchOn()
            domoticz.log('Device ' .. item.name .. ' was updated', domoticz.LOG_INFO)
        elseif 
            dusk.state == 'Off' and domoticz.devices('Staande_lamp').state == 'On' then
            domoticz.devices('Staande_lamp').switchOff()
            domoticz.devices('Dressoir').switchOff()
        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Switch dzvents script to off  [Solved]

Post by waaren »

DRB2019 wrote: Tuesday 18 August 2020 20:52 I'am running the script below to switch 2 lights on in my living room, but
sometimes i do not want the script to run.
Two options; both based on a virtual switch. (when switch is active, script continues)

option 1 => Advantage: script is not executed at all. Disadvantage: check is done on every device update and every minute

Code: Select all

return
{
    active = function(domoticz) 
                return domoticz.devices('scriptController').active
             end,
             
    on = 
    {
        timer   = 
        {
            'every 10 minutes between 15:30 and 22:00',
        },  
    },

    logging =
    {
        level = domoticz.LOG_ERROR,  -- change to LOG_ERROR when ok (was LOG_DEBUG)
        marker = 'dusk sensor',
    },

    execute = function(domoticz)
        local dusk = domoticz.devices('Schemerschakelaar1')

        if  dusk.state == 'On' and domoticz.devices('Staande_lamp').state == 'Off' then
            domoticz.devices('Staande_lamp').switchOn()
            domoticz.devices('Dressoir').switchOn()
            domoticz.log('Device ' .. item.name .. ' was updated', domoticz.LOG_INFO)
        elseif 
            dusk.state == 'Off' and domoticz.devices('Staande_lamp').state == 'On' then
            domoticz.devices('Staande_lamp').switchOff()
            domoticz.devices('Dressoir').switchOff()
        end
    end
}


option 2 => Advantage: Less checks. Disadvantage: Script need to execute before check is done.

Code: Select all

return
{
    on = 
    {
        timer   = 
        {
            'every 10 minutes between 15:30 and 22:00',
        },  
    },

    logging =
    {
        level = domoticz.LOG_ERROR,  -- change to LOG_ERROR when ok (was LOG_DEBUG)
        marker = 'dusk sensor',
    },

    execute = function(domoticz)
        if not( domoticz.devices('scriptController').active ) then
              return
       	end
        
        local dusk = domoticz.devices('Schemerschakelaar1')

        if  dusk.state == 'On' and domoticz.devices('Staande_lamp').state == 'Off' then
            domoticz.devices('Staande_lamp').switchOn()
            domoticz.devices('Dressoir').switchOn()
            domoticz.log('Device ' .. item.name .. ' was updated', domoticz.LOG_INFO)
        elseif 
            dusk.state == 'Off' and domoticz.devices('Staande_lamp').state == 'On' then
            domoticz.devices('Staande_lamp').switchOff()
            domoticz.devices('Dressoir').switchOff()
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
DRB2019
Posts: 24
Joined: Saturday 06 July 2019 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Switch dzvents script to off

Post by DRB2019 »

Hello waaren,
Thnx for the quick reply!, at this moment i go for option 1.

I 'am able to check the script tonight. I will let you know.

waaren wrote: Tuesday 18 August 2020 22:31 Two options; both based on a virtual switch. (when switch is active, script continues)
User avatar
DRB2019
Posts: 24
Joined: Saturday 06 July 2019 13:59
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Netherlands
Contact:

Re: Switch dzvents script to off

Post by DRB2019 »

waaren wrote: Tuesday 18 August 2020 22:31 Two options; both based on a virtual switch. (when switch is active, script continues)
The script works perfect !!
I also made a new script for when then dummy switch is switched to off.

Code: Select all

return
{
    on = {
         devices = {'SchemerControl'}
    },

    logging =
    {
        level = domoticz.LOG_ERROR, 
    },
    execute = function(domoticz, item)
        if  item.state == 'Off' 
        then
            domoticz.devices('Staande_lamp').switchOff()
            domoticz.devices('Dressoir').switchOff()
        end
    end
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest