Page 1 of 1

Best way to run an action for 20 seconds

Posted: Thursday 01 June 2017 11:57
by Ewaldharmsen
Hi all,

I currently have electrical sunscreens, but not they are not smart.
I am thinking about controlling them via Domoticz by just turning on a specific relay for 20 seconds, te time it takes to close the sunscreen.
An of course another relay for 20 seconds to open it again.

Does anybody know the best way to do that?

If I put a pause command in lua of 20 second I will end up with the warning that my script runs for longer than 10 seconds.
Working with timers is also not possible I believe.

So what I basically want is a switch which will stay on for 20 seconds, than turns off

Re: Best way to run an action for 20 seconds

Posted: Thursday 01 June 2017 11:59
by Egregius
Why not use a zwave blind switch? Then you just have to send the open/close command and the switch does the rest.

Re: Best way to run an action for 20 seconds

Posted: Thursday 01 June 2017 21:57
by Thomasdc
just add the switch in domoticz and in the 'off delay' field enter 20 'you can find this in the "edit" tab of the switch int the switch overview

then when its turned on after 20 seconds it will turn off

Re: Best way to run an action for 20 seconds

Posted: Thursday 01 June 2017 22:45
by EdddieN
Sorry, highjacking this a bit.

I'm trying to do something similar, but with a % slider. I have a RF motor with RFXComm but I'm only able to do natively Open, Close and Stop.
What I would like to do is to be able to have a % slider, or at least an approximation of it. Usually to fully open or close the roller blind takes about 12 seconds, so I created a virtual percentage blind control and the following LUA code:

Code: Select all

------------------------------------------------------------------------------
-- Status virtual slider
status_blinds = 'Virtual Blind'
 
-- Electric meter virtual sensor ID (from Setup —> Devices —> Idx number of the dumme device)
-- meter_id = 356 

------------------------------------------------------------------------------
commandArray = {}

if (devicechanged[status_blinds]) then
    
-- Retrieve the previous status
    prev_status = uservariables['varBlind']
-- Retrieve the current value
    read_status = otherdevices_svalues[status_blinds]
-- Difference to move between previous and new target value
    if (read_status > prev_status) then
        target_status = read_status - prev_status
        -- convert to seconds
        target_status = target_status * 0.12
        --- REALLY NEED HELP HERE
        commandArray[] = {[UpdateDevice'] = realWindow OPEN for target_status seconds
        commandArray[] = {[UpdateDevice'] = realWindow stop
        prev_status = target_status
    elseif
        target_status = prev_status - target_status
        -- convert to seconds
        target_status = target_status * 0.12
        commandArray[] = {[UpdateDevice'] = realWindow CLOSE for target_status seconds
        commandArray[] = {[UpdateDevice'] = realWindow stop
        prev_status = target_status
    end
end

return commandArray
------------------------------------------------------------------------------
It is not finished and it is only my 2nd program in LUA but hopefully it makes sense where I want to go.
How do I tell the realWindow to open (or ON/OFF) for X seconds, and then stop.

Re: Best way to run an action for 20 seconds

Posted: Saturday 10 June 2017 19:22
by zicht
EdddieN wrote:Sorry, highjacking this a bit.

I'm trying to do something similar, but with a % slider. I have a RF motor with RFXComm but I'm only able to do natively Open, Close and Stop.
What I would like to do is to be able to have a % slider, or at least an approximation of it. Usually to fully open or close the roller blind takes about 12 seconds, so I created a virtual percentage blind control and the following LUA code:

It is not finished and it is only my 2nd program in LUA but hopefully it makes sense where I want to go.
How do I tell the realWindow to open (or ON/OFF) for X seconds, and then stop.

this is how i did the same trick http://www.domoticz.com/forum/viewtopic ... 65#p137111
You need just a stopwatch to record the timings, i just needed almost closed (look through), half closed and open or closed,
but you can add as many as you want.

As there is no way of knowing the physical status you need to start from a open or closed point.
note 1: it is possible somebody just has send another command from a remote, so you may want to wait to make sure this is not the case.
note 2: due to weight or other physical tolerance creaters there can be a slight difference to the same point depending if you come from open or closed.

It is pretty straight forward, so i assume it will work for you also :)

Re: Best way to run an action for 20 seconds

Posted: Sunday 11 June 2017 22:42
by EdddieN
zicht wrote: this is how i did the same trick http://www.domoticz.com/forum/viewtopic ... 65#p137111
You need just a stopwatch to record the timings, i just needed almost closed (look through), half closed and open or closed,
but you can add as many as you want.
Thanks a lot, exactly what I needed.