Turn on a Group for a certain time  [Solved]

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:

Turn on a Group for a certain time

Post by gschmidt »

Hi,

I have a blockly script which turns on a Group of bulbs for 2 minutes, when an Security Door switch "Schuurdeur" is set to "Alarm" and the time is before sunrise or after sunset. But in blockly it is not possible to turn a group on for a certain amount of time. Therefor I have to use a second blockly script where a virtual switch triggers the group on/off. This Virtual Switch "Tuin Tijdelijk" is used in the first blockly script (see picture below) to turn on for 2 minutes.

Knipsel.JPG
Knipsel.JPG (30.15 KiB) Viewed 1854 times

Is it possible to create this flow in dzVents with a group which is turned on for 2 minutes?
Then I don't need the virtual switch plus the blockly script which triggers the group
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Thursday 26 March 2020 22:48 Hi,

Turns on a Group of bulbs for 2 minutes, when an Security Door switch "Schuurdeur" is set to "Alarm" and the time is before sunrise or after sunset.
Is it possible to create this flow in dzVents with a group which is turned on for 2 minutes?
/quote]
Could be something like

Code: Select all

return 
{
    on = 
    {
        devices = 
        {
            Schuurdeur = 
            { 
                'at nighttime',
            },
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Group switch',
    },

    execute = function(dz, item)
        local tuin = dz.groups('Tuin') -- Change to name of your group
        
        if item.state == 'Alarm' then
            tuin.cancelQueuedCommands()
            tuin.switchOn()
            tuin.switchOff().afterSec(120)
        end
    end
}
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: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Saturday 28 March 2020 23:52 Could be something like
This is working thanx!
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Saturday 28 March 2020 23:52 Could be something like
Hi,

I have changed this working script from a group 'Tuin' to a device "Tuinverlichting"
Device "Tuin Verlichting" is a virtual ON/OFF switch which controls (dzVents script) a zigbee2mqtt group of bulbs

The script turns ON the device but it doesn't turn it OFF after 120 seconds.

Why is this, I have an equal type of script for the "Doorbel" and "Hallway Light", which is working?

Code: Select all

-- Schuurdeur security dzVents script

return 
{
    on = 
    {
        devices = 
        {
            Schuurdeur = 
            { 
              'at nighttime',
            },
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Schuurdeur Security Tuin Verlichting',
    },

    execute = function(dz, item)
        local tv = dz.devices('Tuin Verlichting')
        
        if (item.state == 'Open' and tv.state == 'Off') then
            tv.cancelQueuedCommands()
            tv.switchOn()
            tv.switchOff().afterSec(120)
        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Wednesday 28 October 2020 20:36 The script turns ON the device but it doesn't turn it OFF after 120 seconds.
Why is this, I have an equal type of script for the "Doorbel" and "Hallway Light", which is working?
What do you see in the log ? If nothing useful yet than I suggest to add some log statements at useful places and include relevant device states .
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: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Wednesday 28 October 2020 22:16
gschmidt wrote: Wednesday 28 October 2020 20:36 The script turns ON the device but it doesn't turn it OFF after 120 seconds.
Why is this, I have an equal type of script for the "Doorbel" and "Hallway Light", which is working?
What do you see in the log ? If nothing useful yet than I suggest to add some log statements at useful places and include relevant device states .
Hi waaren,

Nope didn't see anything in the log.
More strange is that i went back to the previous setup & script and it is working again???

The difference between the previous and the new setup is:
I have 5 lights in the garden, which I want to turn on for 2 minutes when the schuurdeur alarm is triggered.

OLD setup:
1x "Tuinverlichting" virtual dimmer switch, which controls a zigbee2mqtt group with 4 IKEA Bulbs
1x KAKU ON/OFF Switch (Vijver Spotjes)
Added both Switches to a domoticz Group 'Schuurdeur Security'.....This way the script below has worked for months.

New setup:
I replaced the KAKU device (broken) by a IKEA Wall-Outlet to control the "Vijver Spotjes"
Therefore I added the IKEA Wall-Outlet in zigbee2mqtt to the same group as the 4 IKEA Bulbs.
"Tuinverlichting" virtual dimmer switch controls 5 lights now.

I thought that the script didn't have to use the Domoticz group anymore, but the switchOff().afterSec(120) function is not executed.
Then I added the "Tuin Verlichting" switch to a Group, and changed the script to......and it is working?

Why is the switchOff().afterSec(120) function executed with a Domoticz Group, but not directly with the "Tuinverlichting" virtual dimmer switch?

Code: Select all

-- Schuurdeur security dzVents script

return 
{
    on = 
    {
        devices = 
        {
            Schuurdeur = 
            { 
              'at nighttime',
            },
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Schuurdeur Security Tuin Licht',
    },

    execute = function(dz, item)
        local tv = dz.devices('Tuin Verlichting')
        local tuin = dz.groups('Schuurdeur Security')
        
        if (item.state == 'Open' and tv.state == 'Off') then
            tuin.cancelQueuedCommands()
            tuin.switchOn()
            tuin.switchOff().afterSec(120)
        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Wednesday 28 October 2020 23:10 Why is the switchOff().afterSec(120) function executed with a Domoticz Group, but not directly with the "Tuinverlichting" virtual dimmer switch?
Sorry but I cannot help if you don't share the loglines. At least add a log statement where you show the state of the door and of tuinverlichting.
Maybe I overlook something but In your earlier post you stated that tv was an On / Off switch and in your later post it is a dimmer

If you switch Off a dimmer, the reported state might well still be 'Set level'
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: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Thursday 29 October 2020 0:07
gschmidt wrote: Wednesday 28 October 2020 23:10 Why is the switchOff().afterSec(120) function executed with a Domoticz Group, but not directly with the "Tuinverlichting" virtual dimmer switch?
Sorry but I cannot help if you don't share the loglines. At least add a log statement where you show the state of the door and of tuinverlichting.
Maybe I overlook something but In your earlier post you stated that tv was an On / Off switch and in your later post it is a dimmer

If you switch Off a dimmer, the reported state might well still be 'Set level'
Hi waaren,

You are right. I’ve made a typing error...it is a virtual dimmer switch, which probably needs a command like dimLevel instead of Off. That is why a group is working, because it is an on/off device.

I will share the log a.s.a.p.
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Turn on a Group for a certain time

Post by gschmidt »

Hi waaren,

I have the LOG details for Script #1. But (Virtual Dummy) Light/Switch (Tuin Verlichting) is not switched of

Code: Select all

2020-10-29 20:26:50.615 (RFXtrx433XL) Security (Schuurdeur)
2020-10-29 20:26:50.801 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-10-29 20:26:50.980 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-10-29 20:26:50.771 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Open"
2020-10-29 20:26:50.771 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Script #1: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-10-29 20:26:50.773 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-10-29 20:26:50.773 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: On
2020-10-29 20:26:50.773 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off
2020-10-29 20:26:50.773 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off AFTER 120 SECONDS
2020-10-29 20:26:50.773 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Script #1
2020-10-29 20:26:50.775 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-29 20:26:50.909 Status: dzVents: Info: Handling events for: "Tuin Verlichting", value: "On"
2020-10-29 20:26:50.947 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-29 20:26:52.647 (RFXtrx433XL) Security (Schuurdeur)
2020-10-29 20:26:52.847 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Normal"
2020-10-29 20:26:52.847 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Script #1: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-10-29 20:26:52.849 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-10-29 20:26:52.849 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Script #1
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Thursday 29 October 2020 20:31 I have the LOG details for Script #1. But (Virtual Dummy) Light/Switch (Tuin Verlichting) is not switched of
I also asked to
at least add a log statement where you show the state of the door and of tuinverlichting.
Can you replace the script with this one? It will now show enough information to debug it.

Code: Select all

-- Schuurdeur security dzVents script

return
{
    on =
    {
        devices =
        {
            Schuurdeur =
            {
              'at nighttime',
            },
        },
        groups =
        {
            'Schuurdeur Security',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Schuurdeur Security Tuin Licht',
    },

    execute = function(dz, item)
        local tv = dz.devices('Tuin Verlichting')
        local tuin = dz.groups('Schuurdeur Security')

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

        if item.isDevice and item.state == 'On' and tv.state == 'Off' then
            tuin.cancelQueuedCommands()
            tuin.switchOn()
            tuin.switchOff().afterSec(11)
        end
    end
}
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: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Thursday 29 October 2020 21:24 Can you replace the script with this one? It will now show enough information to debug it.

Code: Select all

-- Schuurdeur security dzVents script

return
{
    on =
    {
        devices =
        {
            Schuurdeur =
            {
              'at nighttime',
            },
        },
        groups =
        {
            'Schuurdeur Security',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Schuurdeur Security Tuin Licht',
    },

    execute = function(dz, item)
        local tv = dz.devices('Tuin Verlichting')
        local tuin = dz.groups('Schuurdeur Security')

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

        if item.isDevice and item.state == 'On' and tv.state == 'Off' then
            tuin.cancelQueuedCommands()
            tuin.switchOn()
            tuin.switchOff().afterSec(11)
        end
    end
}
I have changed "item.state == 'On'" to "Open" to make it trigger the script. This is the command for the Kerui Door Sensor
Here is the LOG:

Code: Select all

2020-10-29 22:11:46.891 (RFXtrx433XL) Security (Schuurdeur)
2020-10-29 22:11:47.095 Activating Scene/Group: [Schuurdeur Security]
2020-10-29 22:11:47.100 Activating Scene/Group Device: Tuin Verlichting (On)
2020-10-29 22:11:47.106 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-10-29 22:11:47.075 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Open"
2020-10-29 22:11:47.075 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-10-29 22:11:47.076 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-10-29 22:11:47.077 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Schuurdeur Security: Group device adapter
2020-10-29 22:11:47.077 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur Security (group) State is Off
2020-10-29 22:11:47.077 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is Off
2020-10-29 22:11:47.077 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur (device) State is Open
2020-10-29 22:11:47.077 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: On
2020-10-29 22:11:47.077 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off
2020-10-29 22:11:47.077 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off AFTER 11 SECONDS
2020-10-29 22:11:47.077 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
2020-10-29 22:11:47.079 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-29 22:11:47.206 Status: dzVents: Info: Handling events for: "Schuurdeur Security", value: "On"
2020-10-29 22:11:47.206 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Group: "Schuurdeur Security", Index: 19
2020-10-29 22:11:47.207 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-10-29 22:11:47.207 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur Security (group) State is On
2020-10-29 22:11:47.207 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is Off
2020-10-29 22:11:47.208 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur Security (group) State is On
2020-10-29 22:11:47.208 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
2020-10-29 22:11:49.979 (RFXtrx433XL) Security (Schuurdeur)
2020-10-29 22:11:50.135 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Normal"
2020-10-29 22:11:50.136 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-10-29 22:11:50.137 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-10-29 22:11:50.137 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Schuurdeur Security: Group device adapter
2020-10-29 22:11:50.138 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur Security (group) State is On
2020-10-29 22:11:50.138 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is On
2020-10-29 22:11:50.138 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur (device) State is Normal
2020-10-29 22:11:50.138 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
2020-10-29 22:11:58.101 Activating Scene/Group: [Schuurdeur Security]
2020-10-29 22:11:58.110 Activating Scene/Group Device: Tuin Verlichting (Off)
2020-10-29 22:11:58.124 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-10-29 22:11:58.276 Status: dzVents: Info: Handling events for: "Schuurdeur Security", value: "Off"
2020-10-29 22:11:58.276 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Group: "Schuurdeur Security", Index: 19
2020-10-29 22:11:58.277 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-10-29 22:11:58.278 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur Security (group) State is Off
2020-10-29 22:11:58.278 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is On
2020-10-29 22:11:58.278 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur Security (group) State is Off
2020-10-29 22:11:58.278 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
2020-10-29 22:11:58.397 Status: dzVents: Info: Handling events for: "Tuin Verlichting", value: "Off"
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Thursday 29 October 2020 22:22 I have changed "item.state == 'On'" to "Open" to make it trigger the script. This is the command for the Kerui Door Sensor
Here is the LOG:
So what I see in the log (summarized to make it clear)

Code: Select all

2020-10-29 22:11:47.077 : Schuurdeur Security (group) State is Off         -- Group is still Off
2020-10-29 22:11:47.077 : Constructed timed-command: On                    -- Switching group to On immediate
2020-10-29 22:11:47.077 : Constructed timed-command: Off AFTER 11 SECONDS  -- Schedule Switching group to Off after 11 seconds

2020-10-29 22:11:47.207 : Schuurdeur Security (group) State is On          -- Group is switched to On in 0.13 seconds

2020-10-29 22:11:58.278 : Schuurdeur Security (group) State is Off         -- Group is switched to Off in 11.201 Seconds 
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: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Thursday 29 October 2020 23:13
gschmidt wrote: Thursday 29 October 2020 22:22 I have changed "item.state == 'On'" to "Open" to make it trigger the script. This is the command for the Kerui Door Sensor
Here is the LOG:
So what I see in the log (summarized to make it clear)

Code: Select all

2020-10-29 22:11:47.077 : Schuurdeur Security (group) State is Off         -- Group is still Off
2020-10-29 22:11:47.077 : Constructed timed-command: On                    -- Switching group to On immediate
2020-10-29 22:11:47.077 : Constructed timed-command: Off AFTER 11 SECONDS  -- Schedule Switching group to Off after 11 seconds

2020-10-29 22:11:47.207 : Schuurdeur Security (group) State is On          -- Group is switched to On in 0.13 seconds

2020-10-29 22:11:58.278 : Schuurdeur Security (group) State is Off         -- Group is switched to Off in 11.201 Seconds 
Yes this script is working. This is also how my previous script worked.
However, there used to be 2 devices in the “Schuur Security” group, one of the devices was a kaku on/off switch.
The other one is “(Virtual Dummy) Light/Switch (Tuin Verlichting)”, this is a virtual dimmer switch which is controlling a zigbee2mqtt group of 4 devices.
The kaku switch is broken, so bought an ikea wall outlet switch.
This is also a zigbee device, which I have added to the same Zigbee2mqtt group, which now exists of 5 devices.

As you can see in my log there is now only 1 device in the “Schuur Security” group: “(Virtual Dummy) Light/Switch (Tuin Verlichting)”.
So my idea was to remove the group from domoticz, and in the script only use “(Virtual Dummy) Light/Switch (Tuin Verlichting)” to switchOn() and SwitchOff().AfterSec(20)
The problem here is that it swiches On, but not Off.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Friday 30 October 2020 20:10 The problem here is that it swiches On, but not Off.
So what is the script you use for this setup and what do you see in the log when it is triggered?
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: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Saturday 31 October 2020 18:50
gschmidt wrote: Friday 30 October 2020 20:10 The problem here is that it swiches On, but not Off.
So what is the script you use for this setup and what do you see in the log when it is triggered?
Here the script:

Code: Select all

-- Schuurdeur security dzVents script

return
{
    on =
    {
        devices =
        {
            Schuurdeur =
            {
              'at daytime',
            },
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Schuurdeur Security Tuin Licht',
    },

    execute = function(dz, item)
        local tv = dz.devices('Tuin Verlichting')

        dz.log(tv.name .. ' (' .. tv.baseType ..') State is ' .. tv.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 tv.state == 'Off' then
            tv.cancelQueuedCommands()
            tv.switchOn()
            tv.switchOff().afterSec(11)
        end
    end
}
Here the LOG:

Code: Select all

2020-11-01 09:18:54.563 (RFXtrx433XL) Security (Schuurdeur)
2020-11-01 09:18:54.769 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-11-01 09:18:54.946 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-11-01 09:18:54.719 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Open"
2020-11-01 09:18:54.719 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-11-01 09:18:54.720 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-11-01 09:18:54.720 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is Off
2020-11-01 09:18:54.721 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur (device) State is Open
2020-11-01 09:18:54.721 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: On
2020-11-01 09:18:54.721 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off
2020-11-01 09:18:54.721 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off AFTER 11 SECONDS
2020-11-01 09:18:54.721 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
2020-11-01 09:18:54.723 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-01 09:18:54.883 Status: dzVents: Info: Handling events for: "Tuin Verlichting", value: "On"
2020-11-01 09:18:54.919 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-01 09:18:57.514 (RFXtrx433XL) Security (Schuurdeur)
2020-11-01 09:18:57.708 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Normal"
2020-11-01 09:18:57.708 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-11-01 09:18:57.709 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-11-01 09:18:57.709 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is On
2020-11-01 09:18:57.709 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur (device) State is Normal
2020-11-01 09:18:57.709 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
Nothing happens afer 11 seconds...Tuin Verlichting (device) is still ON
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Sunday 01 November 2020 9:21 Nothing happens afer 11 seconds...Tuin Verlichting (device) is still ON
:o
I don't understand yet what is going wrong. I cannot replicate the issue on my system. It almost looks like the Tuin verlichting hardware ignores the afterSec.

Below script should give some more information.

Code: Select all

-- Schuurdeur security dzVents script

return
{
    on =
    {
        devices =
        {
            Schuurdeur =
            {
              'at daytime',
            },
            'Tuin Verlichting',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Schuurdeur Security Tuin Licht',
    },

    execute = function(dz, item)
        local tv = dz.devices('Tuin Verlichting')
        local door = dz.devices('Schuurdeur')

        dz.log(tv.name .. ' (' .. tv.baseType ..') State is ' .. tv.state ,dz.LOG_DEBUG )
        dz.log(door.name .. ' (' .. door.baseType ..') State is ' .. door.state ,dz.LOG_DEBUG )

        dz.log(tv.deviceType,dz.LOG_DEBUG)
        dz.log(tv.deviceSubType,dz.LOG_DEBUG)
        dz.log(tv.rawData,dz.LOG_DEBUG)
        dz.log(tv.nValue,dz.LOG_DEBUG)
        dz.log(tv.hardwareName,dz.LOG_DEBUG)

        if item == door and item.state == 'Open' and tv.state == 'Off' then
            tv.cancelQueuedCommands()
            tv.switchOn()
            tv.switchOff().afterSec(11)
        end
    end
}
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: Turn on a Group for a certain time

Post by gschmidt »

waaren wrote: Sunday 01 November 2020 11:11
gschmidt wrote: Sunday 01 November 2020 9:21 Nothing happens afer 11 seconds...Tuin Verlichting (device) is still ON
:o
I don't understand yet what is going wrong. I cannot replicate the issue on my system. It almost looks like the Tuin verlichting hardware ignores the afterSec.

Below script should give some more information.

Code: Select all

-- Schuurdeur security dzVents script

return
{
    on =
    {
        devices =
        {
            Schuurdeur =
            {
              'at daytime',
            },
            'Tuin Verlichting',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'Schuurdeur Security Tuin Licht',
    },

    execute = function(dz, item)
        local tv = dz.devices('Tuin Verlichting')
        local door = dz.devices('Schuurdeur')

        dz.log(tv.name .. ' (' .. tv.baseType ..') State is ' .. tv.state ,dz.LOG_DEBUG )
        dz.log(door.name .. ' (' .. door.baseType ..') State is ' .. door.state ,dz.LOG_DEBUG )

        dz.log(tv.deviceType,dz.LOG_DEBUG)
        dz.log(tv.deviceSubType,dz.LOG_DEBUG)
        dz.log(tv.rawData,dz.LOG_DEBUG)
        dz.log(tv.nValue,dz.LOG_DEBUG)
        dz.log(tv.hardwareName,dz.LOG_DEBUG)

        if item == door and item.state == 'Open' and tv.state == 'Off' then
            tv.cancelQueuedCommands()
            tv.switchOn()
            tv.switchOff().afterSec(11)
        end
    end
}
This is the LOG:

Code: Select all

020-11-01 12:23:49.098 (RFXtrx433XL) Security (Schuurdeur)
2020-11-01 12:23:49.286 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-11-01 12:23:49.432 (Virtual Dummy) Light/Switch (Tuin Verlichting)
2020-11-01 12:23:49.244 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Open"
2020-11-01 12:23:49.244 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is Off
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur (device) State is Open
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Light/Switch
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Switch
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: {"78"}
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: 0
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Virtual Dummy
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: On
2020-11-01 12:23:49.245 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off
2020-11-01 12:23:49.246 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Constructed timed-command: Off AFTER 11 SECONDS
2020-11-01 12:23:49.246 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
2020-11-01 12:23:49.247 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-01 12:23:49.387 Status: dzVents: Info: Handling events for: "Tuin Verlichting", value: "On"
2020-11-01 12:23:49.420 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-11-01 12:23:52.476 (RFXtrx433XL) Security (Schuurdeur)
2020-11-01 12:23:52.885 (RFXtrx433XL) Security (Schuurdeur)
2020-11-01 12:23:52.655 Status: dzVents: Info: Handling events for: "Schuurdeur", value: "Normal"
2020-11-01 12:23:52.655 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Start internal script: Schuurdeur_Security_new: Device: "Schuurdeur (RFXtrx433XL)", Index: 317
2020-11-01 12:23:52.656 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Processing device-adapter for Tuin Verlichting: Switch device adapter
2020-11-01 12:23:52.656 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Tuin Verlichting (device) State is On
2020-11-01 12:23:52.656 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Schuurdeur (device) State is Normal
2020-11-01 12:23:52.656 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Light/Switch
2020-11-01 12:23:52.656 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Switch
2020-11-01 12:23:52.656 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: {"78"}
2020-11-01 12:23:52.656 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: 2
2020-11-01 12:23:52.657 Status: dzVents: Debug: Schuurdeur Security Tuin Licht: Virtual Dummy
2020-11-01 12:23:52.657 Status: dzVents: Info: Schuurdeur Security Tuin Licht: ------ Finished Schuurdeur_Security_new
Maybe this would help you....This is the Script (you have created for me a few months ago) for the "(Virtual Switch) Tuin Verlichting".
You created this for my kitchen light, but I also used it for "Tuin Verlichting".

Code: Select all

--[[ dumpMQTT     
]]--

return 
{
    on = 
    {
        devices = 
        { 
            'Tuin Verlichting' 
        },
    },

    logging = 
    { 
        level = domoticz.LOG_ERROR, --domoticz.LOG_ERROR
        marker = 'Tuin_Verlichting',
    },

    data = 
    {   
        lastState = 
        { 
            initial = 'Off',
        },
    },
    
    execute = function(dz, item)
        
       -- ************** Your settings (when not default) below this line *********************

        local MQTTBrokerHost  
        local MQTTTopic = 'zigbee2mqtt/Tuin_Licht_ct/set' 
        local mosquitto_pub = '/usr/bin/mosquitto_pub' 
        local mqttUser = 'mqtt'
        local mqttPass = 'xxx'
        local initialDimLevel = 200

      -- ************** No changes required below this line ************************
            
        local MQTTBrokerHost = MQTTBrokerHost or 'localhost'
        local MQTTTopic = MQTTTopic or 'domoticz/out'
        local mosquitto_pub = mosquitto_pub or '/usr/bin/mosquitto_pub'
       
       local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            if commandOutput:find '::ERROR::' then     -- something went wrong
               dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_ERROR)
            else -- all is fine!!
                if returnTable[3] ~= 0 then 
                    dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
                end
            end

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        local function composeMQTT(item)
            local message = {}
            
            if item.state == 'Off' then 
                message.state = 'OFF' 
                dz.data.lastState = 'Off'
                message.brightness = 0
            else
                message.state = "ON"
                if dz.data.lastState == 'Off' then 
                    message.brightness = initialDimLevel
                    dz.data.lastState = 'On'
                    item.setLevel( initialDimLevel / 2.55 ).silent()
                else
                    message.brightness = math.floor(item.level * 2.55 + 0.5)
                end
            end
            message.color_temp = 350
            
            message = dz.utils.toJSON(message)
            message = message:gsub(',',',\n  '):gsub('}','\n } \n'):gsub('{','\n { \n  '):gsub(':',' : ')
                        
            return ( mosquitto_pub .. ' -d -u ' .. mqttUser .. ' -P ' .. mqttPass .. ' -h '.. MQTTBrokerHost  .. ' -t '  .. MQTTTopic .. " -m '" .. message .. "'")
        end

        -- Main code
        osCommand(composeMQTT(item))
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Turn on a Group for a certain time

Post by waaren »

gschmidt wrote: Sunday 01 November 2020 12:31 This is the LOG:
Can you show a bit more log? Not only the first couple of seconds but at least 2 cycles of opening and closing the door ?
Maybe this would help you....This is the Script (you have created for me a few months ago) for the "(Virtual Switch) Tuin Verlichting".
You created this for my kitchen light, but I also used it for "Tuin Verlichting".
Sorry but I don't see how this could be connected. The only thing the new script should do is switching a virtual device to On immediate and Off after 11 seconds. But maybe I am overlooking something ?
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: Turn on a Group for a certain time  [Solved]

Post by gschmidt »

waaren wrote: Sunday 01 November 2020 12:46
gschmidt wrote: Sunday 01 November 2020 12:31 This is the LOG:
Can you show a bit more log? Not only the first couple of seconds but at least 2 cycles of opening and closing the door ?
Maybe this would help you....This is the Script (you have created for me a few months ago) for the "(Virtual Switch) Tuin Verlichting".
You created this for my kitchen light, but I also used it for "Tuin Verlichting".
Sorry but I don't see how this could be connected. The only thing the new script should do is switching a virtual device to On immediate and Off after 11 seconds. But maybe I am overlooking something ?
Sadly 2 cycles of opening and closing the door have exactly the same LOG messages.

Today I have re-placed in the script: device "Tuin Verlichting" with device "Tuin_Licht_ct".
This (dimmer switch) device is automatically created with the "domoticz-zigbee2mqtt-plugin".
It controls the same zigbee2mqtt group as "Tuin Verlichting" does
And this devices has no problem switching off with afterSec(11)....so strange...
I am using this device now instead of "Tuin Verlichting"
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest