How to stop Blinds when a Door Contact is open

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

Moderator: leecollings

Post Reply
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

How to stop Blinds when a Door Contact is open

Post 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"
Last edited by gschmidt on Friday 21 May 2021 15:45, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to stop a Shutter when doorcontact is open

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: How to stop a Shutter when doorcontact is open

Post 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',
        },
    },
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to stop a Shutter when doorcontact is open

Post 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"
User avatar
madpatrick
Posts: 667
Joined: Monday 26 December 2016 12:17
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

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

Post 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
-= HP server GEN11 =- OZW -=- Toon2 (rooted) -=- Domoticz v2025.1 -=- Dashticz v3.14b on Tab8" =-
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to stop a Shutter when doorcontact is open

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to stop a Shutter when doorcontact is open

Post 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
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest