How to create a delay in a contact's On/Off sequence

Moderator: leecollings

Post Reply
Michel13
Posts: 69
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

How to create a delay in a contact's On/Off sequence

Post by Michel13 »

Hello,
I wrote a Lua script that allows me to control my pool's chlorinator. Without going into details that are irrelevant here, I need to cut off its power for 10 seconds to reset it. The device that controls the power is "On" when the power is off, and "Off" to power the chlorinator. I would like to do this:

Code: Select all

commandArray[stop_electrolyseur] = "On" -- power off
10 second delay
commandArray[stop_electrolyseur] = "Off" -- power on
But I fail to translate this sequence into a Lua script.
Could a kind soul tell me how to implement this sequence?
User avatar
psubiaco
Posts: 219
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: How to create a delay in a contact's On/Off sequence

Post by psubiaco »

Try with this:
commandArray["stop_electrolyseur"] = "On FOR 10 seconds"
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
Michel13
Posts: 69
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to create a delay in a contact's On/Off sequence

Post by Michel13 »

Thank you psubiaco, so simple !
Just one question : if the contact is "On" before the sequence, is this command will do the same or is it necessary to turn it off before ?
HvdW
Posts: 600
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How to create a delay in a contact's On/Off sequence

Post by HvdW »

From the wiki. (Check that first)

Code: Select all

    -- switch on for 2 minutes after 10 seconds
    device.switchOn().afterSec(10).forMin(2)

    -- switch on at a specic time / day
    device.switchOn().at('09:00')                   -- earliest moment it will be 09:00 hr.
    device.switchOn().at('08:53:30 on fri')         -- earliest moment it will be Friday at 08:53:30
    device.switchOn().at('08:53:30 on sat, sun')    -- earliest moment it will be Saturday or Sunday at 08:53:30 (whatever comes first)

    -- switch on for 2 minutes after a randomized delay of 1-10 minutes
    device.switchOff().withinMin(10).forMin(2)
    device.close().forMin(15)
    device.open().afterSec(20)
    device.open().afterMin(2)

    -- switch on but do not trigger follow up events
    device.switchOn().silent()

    -- flash a light for 3 times
    device.switchOn().forSec(2).repeatAfterSec(1, 3)

    -- switch the device on but only if the current state isn't already on:
    device.switchOn().checkFirst()
    -- this is a short for:
    if (device.state == 'Off') then
        devices.switchOn()
    end
Bugs bug me.
User avatar
psubiaco
Posts: 219
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: How to create a delay in a contact's On/Off sequence

Post by psubiaco »

Michel13 wrote: Friday 23 May 2025 18:58 Thank you psubiaco, so simple !
Just one question : if the contact is "On" before the sequence, is this command will do the same or is it necessary to turn it off before ?
If it was on, you don't need to turn off than on for 10 seconds, but you may experience strange behaviours.
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
Michel13
Posts: 69
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to create a delay in a contact's On/Off sequence

Post by Michel13 »

psubiaco wrote: Friday 23 May 2025 20:11 you don't need to turn off than on for 10 seconds,
Ok, I understand.
At first, the power supply of the unit is Off (control device is On). I need to turn it Off to supply the chlorinator. At the next call (2 hours later), control device is Off and I need to turn it On for 10 sec to initiate and start a new cycle.
So here is my script :

Code: Select all

	if otherdevices[stop_electrolyseur] == "On" then
		commandArray[stop_electrolyseur] = "Off"
	else
		commandArray[stop_electrolyseur] = "On for 10 seconds" 
	end
Thanks for your help.
User avatar
psubiaco
Posts: 219
Joined: Monday 20 August 2018 9:38
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Italy
Contact:

Re: How to create a delay in a contact's On/Off sequence

Post by psubiaco »

Your script can be called every minute, so you can use a variable to manage time to know what you have to do.

Please note you have also the "AFTER" keyword: I never tried, but maybe it works

Code: Select all

commandArray[device]="On for 10 seconds after 7200 seconds"
Check it, it may not work as I expected.
Paolo
--
I use DomBus modules to charge EV car, get a full alarm system, control heat pump, fire alarm detection, lights and much more. Video
Facebook page - Youtube channel
Michel13
Posts: 69
Joined: Thursday 07 January 2016 19:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: How to create a delay in a contact's On/Off sequence

Post by Michel13 »

Thanks psubiaco
My script is called every 15 minutes and time of operation of the chlorinator (2 hours) is managed properly elsewhere in the script. So it was only the question of supplying the unit on and off which was my only problem. Now it is solved thanks to you.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest