Page 1 of 1

How to stop Blinds when a Door Contact is open

Posted: Thursday 20 May 2021 21:13
by gschmidt
Hi,

I have Blinds (RFXtrx433XL - Type DC106) at the second floor which doesn't have an autostop function.
So if the window is open and the Blind command is "Close" it may get broken.
Now I also have a "Door Contact" (Zigbee2mqtt) device which I have attached to the window behind the Blinds.

Is it possible with dzVents to only open or close the Blinds if the "Door Contact" is closed?
Or "Stop" the Blinds (and if possible go back to "Open") when the "Door Contact" is set to "Open"?

I tried with following script but nothing happens when I first "Open" the "Door Contact" and "Close" the "Blinds" (not attached yet to the window ofcourse):

Code: Select all

--- Rolluik security dzVents script

return
{
    on =
    {
        devices =
        {
            'Raam Sensor',
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR,
        marker = 'Rolluik Security Raam Sensor',
    },

    execute = function(dz, item)
        local luik = dz.devices('Luik 1')

        dz.log(luik.name .. ' (' .. luik.baseType ..') State is ' .. luik.state ,dz.LOG_DEBUG )
        dz.log(item.name .. ' (' .. item.baseType ..') State is ' .. item.state ,dz.LOG_DEBUG )

        if item.isDevice and item.state == 'Open' and luik.state == 'Close' then
            luik.cancelQueuedCommands()
            luik.Stop().checkFirst()
            luik.Open().checkFirst()afterSec(1)
        end
    end
}
But this is in the log:

Code: Select all

2021-05-20 21:02:04.827 RFXtrx433XL: Blinds (Luik 1)
2021-05-20 21:02:07.674 Status: dzVents: Info: Handling events for: "Raam Sensor", value: "Open"
2021-05-20 21:02:10.818 Status: dzVents: Info: Handling events for: "Raam Sensor", value: "Closed"
2021-05-20 21:02:12.939 RFXtrx433XL: Blinds (Luik 1)
2021-05-20 21:02:27.552 Status: dzVents: Info: Handling events for: "Raam Sensor", value: "Open"
2021-05-20 21:02:33.831 RFXtrx433XL: Blinds (Luik 1)
2021-05-20 21:02:35.031 RFXtrx433XL: Blinds (Luik 1)
2021-05-20 21:02:42.230 Status: dzVents: Info: Handling events for: "Raam Sensor", value: "Closed"

Re: How to stop a Shutter when doorcontact is open

Posted: Thursday 20 May 2021 21:38
by waaren
gschmidt wrote: Thursday 20 May 2021 21:13 I tried with following script but nothing happens when I first "Open" the "Door Contact" and "Close" the "Blinds" (not attached yet to the window ofcourse):
Made some small adjustments to the script. It might not directly solve the issue but it will show some more information.
(if you set the logging level to domoticz.LOG_ERROR it will only show errors)

Code: Select all

--- Rolluik security dzVents script

return
{
    on =
    {
        devices =
        {
            'Raam Sensor',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Rolluik Security Raam Sensor',
    },

    execute = function(dz, item)
        local luik = dz.devices('Luik 1')

        dz.log(luik.name .. ' (' .. luik.baseType ..') State is ' .. luik.state ,dz.LOG_DEBUG )
        dz.log(item.name .. ' (' .. item.baseType ..') State is ' .. item.state ,dz.LOG_DEBUG )

        if item.isDevice and item.state == 'Open' and luik.state == 'Closed' then
            luik.cancelQueuedCommands()
            luik.stop()
            luik.open().afterSec(1)
        end
    end
}

Re: How to stop a Shutter when doorcontact is open

Posted: Friday 21 May 2021 14:10
by madpatrick
Maybe a stupid comment, but is the script now activated bij de "Raam Sensor" and not by "Luik" ?

Code: Select all

    on =
    {
        devices =
        {
            'Raam Sensor',
        },
    },
So it must be

Code: Select all

    on =
    {
        devices =
        {
            'Luik 1',
        },
    },

Re: How to stop a Shutter when doorcontact is open

Posted: Friday 21 May 2021 16:22
by gschmidt
waaren wrote: Thursday 20 May 2021 21:38
gschmidt wrote: Thursday 20 May 2021 21:13 I tried with following script but nothing happens when I first "Open" the "Door Contact" and "Close" the "Blinds" (not attached yet to the window ofcourse):
Made some small adjustments to the script. It might not directly solve the issue but it will show some more information.
(if you set the logging level to domoticz.LOG_ERROR it will only show errors)

Code: Select all

--- Rolluik security dzVents script

return
{
    on =
    {
        devices =
        {
            'Raam Sensor',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Rolluik Security Raam Sensor',
    },

    execute = function(dz, item)
        local luik = dz.devices('Luik 1')

        dz.log(luik.name .. ' (' .. luik.baseType ..') State is ' .. luik.state ,dz.LOG_DEBUG )
        dz.log(item.name .. ' (' .. item.baseType ..') State is ' .. item.state ,dz.LOG_DEBUG )

        if item.isDevice and item.state == 'Open' and luik.state == 'Closed' then
            luik.cancelQueuedCommands()
            luik.Stop()
            luik.Open().afterSec(1)
        end
    end
}
Hi,

I have changed the code and switched the devices to

Code: Select all

return {
    on =
    {
        devices =
        {
            'Luik 1',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Rolluik Security Raam Sensor',
    },

    execute = function(dz, item)
        local sensor = dz.devices('Raam Sensor')

        dz.log(sensor.name .. ' (' .. sensor.baseType ..') State is ' .. sensor.state ,dz.LOG_DEBUG )
        dz.log(item.name .. ' (' .. item.baseType ..') State is ' .. item.state ,dz.LOG_DEBUG )

        -- if item.isDevice and item.state == 'Open' and luik.state == 'Closed' then
        if item.isDevice and item.state == 'Closed' and sensor.state == 'Open' then
            item.cancelQueuedCommands()
            item.Stop()
            item.Open().afterSec(1)
        end
    end
}
Not working....The log produces the following Error

Code: Select all

2021-05-21 16:06:17.541 Status: dzVents: Info: Rolluik Security Raam Sensor: ------ Start internal script: Rolluik_Security: Device: "Luik 1 (RFXtrx433XL)", Index: 41
2021-05-21 16:06:17.542 Status: dzVents: Debug: Rolluik Security Raam Sensor: Processing device-adapter for Raam Sensor: Switch device adapter
2021-05-21 16:06:17.542 Status: dzVents: Debug: Rolluik Security Raam Sensor: Raam Sensor (device) State is Open
2021-05-21 16:06:17.542 Status: dzVents: Debug: Rolluik Security Raam Sensor: Luik 1 (device) State is Closed
2021-05-21 16:06:17.542 Status: dzVents: Info: Rolluik Security Raam Sensor: ------ Finished Rolluik_Security
2021-05-21 16:06:17.543 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-05-21 16:06:17.542 Error: dzVents: Error: (3.1.8) Rolluik Security Raam Sensor: An error occurred when calling event handler Rolluik_Security
2021-05-21 16:06:17.542 Error: dzVents: Error: (3.1.8) Rolluik Security Raam Sensor: ...z/scripts/dzVents/generated_scripts/Rolluik_Security.lua:28: attempt to call a nil value (field 'Stop')
2021-05-21 16:06:22.380 RFXtrx433XL: Blinds (Luik 1)
2021-05-21 16:06:22.548 Status: dzVents: Info: Handling events for: "Luik 1", value: "Stopped"

Re: How to stop Blinds when a Door Contact is open

Posted: Friday 21 May 2021 16:35
by madpatrick
What type of switch do you have selected in Domoticz for Luik 1 ?

Code: Select all

2021-05-21 16:06:17.542 Error: dzVents: Error: (3.1.8) Rolluik Security Raam Sensor: ...z/scripts/dzVents/generated_scripts/Rolluik_Security.lua:28: attempt to call a nil value (field 'Stop'
For a Stop function you need to selected type : Venetians Blinds instead of Blinds (inverterted)
Venetian blinds has the stop function

Re: How to stop a Shutter when doorcontact is open

Posted: Friday 21 May 2021 19:13
by waaren
gschmidt wrote: Friday 21 May 2021 16:22 Not working....The log produces the following Error
All dzVents methods and functions use camelCase (so every single one starts with lowercase)

Edited my previous post to reflect this.

Re: How to stop a Shutter when doorcontact is open

Posted: Saturday 22 May 2021 11:57
by gschmidt
waaren wrote: Friday 21 May 2021 19:13
gschmidt wrote: Friday 21 May 2021 16:22 Not working....The log produces the following Error
All dzVents methods and functions use camelCase (so every single one starts with lowercase)

Edited my previous post to reflect this.
Working, thanx! but the devices must be switched like madpatrik said.
Here the final Code

Code: Select all

--- Rolluik security dzVents script

return {
    on =
    {
        devices =
        {
            'Luik 1',
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR,
        marker = 'Rolluik Security Raam Sensor',
    },

    execute = function(dz, item)
        local sensor = dz.devices('Raam Sensor')

        dz.log(sensor.name .. ' (' .. sensor.baseType ..') State is ' .. sensor.state ,dz.LOG_INFO )
        dz.log(item.name .. ' (' .. item.baseType ..') State is ' .. item.state ,dz.LOG_INFO )

        if item.isDevice and item.state == 'Closed' and sensor.state == 'Open' then
            item.cancelQueuedCommands()
            item.stop()
            item.open().afterSec(1)
            dz.notify('Luik 1','Het raam staat open, daarom is het rolluik weer geopend!', dz.PRIORITY_NORMAL,'','',dz.NSS_TELEGRAM)
        end
    end
}