Page 1 of 1

Switch off delay not working

Posted: Tuesday 13 April 2021 9:22
by 27fb
Hello,

The switch off delay does not seem to be working. Whatever the delay value, the switch turns off immediately.
The on delay however works just as expected.

1) Could anyone confirm the bug ? Is there a fix ?
2) Does the off delay normally apply to a script attached the off event ?

Thanks for your help


I am using :
Version: 2020.2
Build Hash: b63341bc0
Compile Date: 2020-04-26 13:47:55
dzVents Version: 3.0.2
Python Version: 3.7.3 (default, Jan 22 2021, 20:04:44) [GCC 8.3.0]

Re: Switch off delay not working

Posted: Tuesday 13 April 2021 9:44
by waaren
27fb wrote: Tuesday 13 April 2021 9:22 The switch off delay does not seem to be working. Whatever the delay value, the switch turns off immediately.
The on delay however works just as expected.
Standard behavior for these delays is:

The On delay causes a device to switch On with a delay of the set amount of seconds after the switchOn command is given.
The Off delay causes a device to switch Off with a delay of the set amount of seconds after the device switched to On.

Does your device react different?

Re: Switch off delay not working

Posted: Tuesday 13 April 2021 19:40
by 27fb
Thank you for your quick reply. You are right I was confused about the meaning of "Off delay".

Is there a way to delay extinction (i.e. to postpone SwitchOff command) ? To be more precise I would like to shutdown my mediacenter « gracefully » before turning off the power switch.

Re: Switch off delay not working

Posted: Tuesday 13 April 2021 20:58
by waaren
27fb wrote: Tuesday 13 April 2021 19:40 Thank you for your quick reply. You are right I was confused about the meaning of "Off delay".

Is there a way to delay extinction (i.e. to postpone SwitchOff command) ? To be more precise I would like to shutdown my mediacenter « gracefully » before turning off the power switch.
You can do this with scripting. How do you shutdown your mediacenter ?

Re: Switch off delay not working

Posted: Tuesday 13 April 2021 21:09
by waltervl
If you have group for example media center with 2 devices (media center and power plug) when you switch off the group you can set a delay of x seconds on the off action of the plug. So the 2 devices get the switch off action on the same time but the plug will switch off x seconds later than the media center.
Forget this... I also understood this switch off delay completely different. It is switch off delay after switch on......

Edit: Switching on off delay behavior is as described.

Re: Switch off delay not working

Posted: Wednesday 14 April 2021 23:01
by 27fb
waltervl wrote: Tuesday 13 April 2021 21:09 If you have group for example media center with 2 devices (media center and power plug) when you switch off the group you can set a delay of x seconds on the off action of the plug. So the 2 devices get the switch off action on the same time but the plug will switch off x seconds later than the media center.
Forget this... I also understood this switch off delay completely different. It is switch off delay after switch on......
Yes I got confused too...

Re: Switch off delay not working

Posted: Wednesday 14 April 2021 23:06
by 27fb
waaren wrote: Tuesday 13 April 2021 20:58
27fb wrote: Tuesday 13 April 2021 19:40 Thank you for your quick reply. You are right I was confused about the meaning of "Off delay".

Is there a way to delay extinction (i.e. to postpone SwitchOff command) ? To be more precise I would like to shutdown my mediacenter « gracefully » before turning off the power switch.
You can do this with scripting. How do you shutdown your mediacenter ?
I intended to run a bash script triggered when turning off the switch (the script:/// is declared in the Action off field of the switch). The script itself triggers a JSON rpc on the mediacenter (vero4k). The switch is a fibaro wall plug. It controls other peripherals such as an audio amplifier, tv...

Re: Switch off delay not working

Posted: Wednesday 14 April 2021 23:43
by waaren
27fb wrote: Wednesday 14 April 2021 23:06 I intended to run a bash script triggered when turning off the switch (the script:/// is declared in the Action off field of the switch). The script itself triggers a JSON rpc on the mediacenter (vero4k). The switch is a fibaro wall plug. It controls other peripherals such as an audio amplifier, tv...
A dzVents approach could look like below

__________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________


Code: Select all

local scriptVar = 'mediacenter Control'

return
{
    on =
    {
        devices =
        {
            'stop mediacenter', -- define as virtual push off button
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging = {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
        marker = 'mediacenter control',
    },

    execute = function(dz, item)
        local delay = 5

        if item.isDevice and item.state == 'Off' then
            dz.openURL(
            {
                url = 'http://mediacenter_JSON_rpc', -- change to JSON call
                callback = scriptVar,
            })
        elseif item.isHTTPResponse then
            dz.devices('Fibaro plug').switchOff().silent().afterSec(delay)
        end
    end
}

Re: Switch off delay not working

Posted: Thursday 15 April 2021 1:00
by 27fb
Thank you very much ! I added a condition to switch power on whenever the virtual switch is turned on. Even though it's working, could you please have a look and tell me if the conditional construct is correct (should item.state == 'On' be a subbranch of item.IsDevice) ?

Code: Select all

local scriptVar = 'mediacenter control'

return
{
    on =
    {
        devices =
        {
            'mediacenter.switch', -- define as virtual push off button
        },

        httpResponses =
        {
		scriptVar,	
        },
    },

    logging = {
        level = domoticz.LOG_ERROR, -- change to domoticz.LOG_DEBUG when testing
        marker = 'mediacenter control',
    },

    execute = function(dz, item)
        local delay = 30

        if item.isDevice and item.state == 'On' then
            dz.devices('television.switch').switchOn().silent()
	end
        
	if item.isDevice and item.state == 'Off' then
            dz.openURL(
            {
                url = 'http://<mediacenterip:port>/jsonrpc', -- change to JSON call
		method= 'POST',
		postData= {['jsonrpc']= "2.0", ["method"]= "System.Shutdown", ["id"]= "domoticz"},
                callback = scriptVar,
            })
        elseif item.isHTTPResponse then
            dz.devices('television.switch').switchOff().silent().afterSec(delay)
        end
    end
}

Re: Switch off delay not working

Posted: Thursday 15 April 2021 8:31
by waaren
27fb wrote: Thursday 15 April 2021 1:00 Thank you very much ! I added a condition to switch power on whenever the virtual switch is turned on. Even though it's working, could you please have a look and tell me if the conditional construct is correct (should item.state == 'On' be a subbranch of item.IsDevice) ?
Good to hear it's working for you.
No sure I understand your question about subbranch.
item.isDevice and item.state are both attributes of the item object. item.isDevice is a boolean (true or false/nil) and item.state is a string (if item (= mediacenter.switch) is an On/Off switch: 'On' or 'Off').

The script could then also look like below

Code: Select all

local scriptVar = 'mediacenter control'

return
{
    on =
    {
        devices =
        {
            'mediacenter.switch', -- define as virtual switch
        },

        httpResponses =
        {
        scriptVar,
        },
    },

    logging = {
        level = domoticz.LOG_ERROR, -- change to domoticz.LOG_DEBUG when testing
        marker = 'mediacenter control',
    },

    execute = function(dz, item)
        local delay = 30
        local tv = dz.devices('television.switch')

        if item.isDevice and item.state == 'On' then
            tv.switchOn().silent()
        elseif item.isDevice and item.state == 'Off' then
            dz.openURL(
            {
                url = 'http://<mediacenterip:port>/jsonrpc', 
                method= 'POST',
                postData= {['jsonrpc']= "2.0", ["method"]= "System.Shutdown", ["id"]= "domoticz"},
                callback = scriptVar,
            })
        elseif item.isHTTPResponse then
            tv.switchOff().silent().afterSec(delay)
        end
    end
}

Re: Switch off delay not working

Posted: Thursday 15 April 2021 9:21
by 27fb
That's exactly what i expected.

Still I find it complicated. Wouldn't it be easier to have a "Switch off delay " field directly at the switch level that does that. This would also imply renaming the present feature to "Switch off delay after switch on" because current labeling is pretty confusing.

Anyway thank you again !

Re: Switch off delay not working

Posted: Thursday 15 April 2021 11:57
by waltervl
Well I Just tested it.
It is what we both thought and not according the description @waaren gave:
Switch on delay is delay after switching on device command.
Switch off delay is delay after switching off device command.

So my proposal for a Group in your case is feasible.

Re: Switch off delay not working

Posted: Thursday 15 April 2021 12:50
by waaren
waltervl wrote: Thursday 15 April 2021 11:57 It is what we both thought and not according the description @waaren gave:
My post was not about the On / Off delay feature in Scenes / Groups. It was about On/ Off delay in Switch settings.

Re: Switch off delay not working

Posted: Thursday 15 April 2021 13:05
by waltervl
waaren wrote: Thursday 15 April 2021 12:50
waltervl wrote: Thursday 15 April 2021 11:57 It is what we both thought and not according the description @waaren gave:
My post was not about the On / Off delay feature in Scenes / Groups. It was about On/ Off delay in Switch settings.
Oh man, things can be made complicated here.... Why have 2 settings that have a different meaning on different locations?
Just tested it and that is correct.

Re: Switch off delay not working

Posted: Friday 16 April 2021 11:41
by jannl
Why not check the power consumption before switching off?

I switch off my desktop 5 minutes afterr the power consumption drops below a certain value. If for some reason the shutdown takes longer than expected you could have a problem.....

Re: Switch off delay not working

Posted: Wednesday 30 June 2021 16:54
by HM31
It seems that the switch Off delay does not work for Python managed switch, specifically for TPLink hardware switchs (https://github.com/J0hnMatrix/domoticz- ... 0-hs110-v2)

My switch is configured to automatically come "Off" after 20 seconds :
Off Delay: 20 (Seconds) 0 = Disabled
But it seems that it does nothing (it works perfectly with a RF433 switch with RFXCom.

There is no action to switch it off after the 20s in log file.

Re: Switch off delay not working

Posted: Wednesday 30 June 2021 17:07
by waltervl
I am almost sure I tested it on Python Plugin controlled switches (Zigate Zigbee) and for me it worked.

Re: Switch off delay not working

Posted: Thursday 01 July 2021 20:21
by HM31
Thanks for this answer.
May be it's something with this specific plugin ?!
I used a workaround adding a "FOR 20 SECONDS" in my lua script that put my switch On and this works.
I opened an issue on github, but this plugin has some forks and seems not to be updated frequently.