Hello, 'simple' timer rearm question.

54 views
Skip to first unread message

Ag Paya

unread,
Mar 2, 2025, 3:54:03 AMMar 2
to TasmotaUsers
with rules, how to make a rearm timer ?
send ' power on' to tasmota > on is maintened for x secondes then goes to off (simple)
but rearm ???
power on > on is maintened for x secondes, if power on again, the timer is reset to x secondes again, and each time power on is send to tasmota
i found no way to do this !

Justin Adie

unread,
Mar 2, 2025, 4:07:51 AMMar 2
to Ag Paya, TasmotaUsers
Depends on the method of turning the power on.  Assuming it's a rocker or momentary switch decouple the switch from the relay. Then use the switch as the trigger for a rule.  

In the terminal

Rule1 on switch1#state =1 do backlog ruletimer1 30; power 1 1 endon on rules#timer=1 do power 1 0 Endon

Switchmode1 15

Rule1 1


You will need the switch and relay configured as switch1 and relay1 respectively 

If you are using a rocker/toggle switch change the trigger to switch1#state do 



--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/sonoffusers/07b29e8c-6466-4d0b-a0d8-7d9f5dde22b8n%40googlegroups.com.

Ag Paya

unread,
Mar 2, 2025, 5:32:25 AMMar 2
to TasmotaUsers
hello, thanks for your answer, but the ordre 'power on'  is sent by http, so 'switch' is not usable here i believe.

Ag Paya

unread,
Mar 2, 2025, 5:35:47 AMMar 2
to TasmotaUsers
what i have tried without succes:
rule1 ON Power#ON  DO RuleTimer1 20 ENDON ON Rules#Timer=1 DO Power1 0 ENDON; Rule1 1
or
rule1 ON Power#command  DO RuleTimer1 20 ENDON ON Rules#Timer=1 DO Power1 0 ENDON; Rule1 1
or

Justin Adie

unread,
Mar 2, 2025, 6:06:44 AMMar 2
to Ag Paya, SonoffUsers
What is producing the http power1 on command?  

Try creating a virtual relay and attaching that to your automations/http commands.  So power1 = virtual relay; power2 = real relay.

Then use the rule

Rule1 on Power1#On do event startTimer endon
Rule1+ on event=startTimer do backlog ruletimer1 20; power2 1; power1 0 endon 
rule1+ on rules#timer=1 do power2 0 endon

Ag Paya

unread,
Mar 2, 2025, 6:35:07 AMMar 2
to TasmotaUsers
ahk script:
SendCommand("Power1 ON")

SendCommand(command)
{
    global deviceIP
    if (!deviceIP) {
        TrayTip, Erreur, Adresse IP du périphérique non définie !, 5, 1
        return
    }

    url := "http://" . deviceIP . "/cm?cmnd=" . command
    maxAttempts := 3  ; Nombre maximum de tentatives
    attempt := 0
   
    while (attempt < maxAttempts)
    {
        attempt++
        result := SendHttpRequest(url)

        if (result != "ERROR") {
            ;~ static TimerCount := 0
            TimerCount++

            if (TimerCount >= 8) {
                TrayTip, Sonoff, Rearmement du timer `n(toutes les: %IntervalleOrdreSec% secondes) , 1, 1
                ;~ TimerCount := 0
            } else {
                TrayTip, Tasmota Response, % "Commande: " . command . "`nRéponse: " . result, 1, 1
            }
            return  ; Sortir de la fonction si la commande a réussi
        }

        ; Si l'erreur persiste, attendre 2 secondes avant de réessayer
        Sleep, 2000
        TrayTip, Tasmota, Échec de la commande après %attempt% tentatives: %command%, 1, 1
    }

    ; Si toutes les tentatives échouent, afficher une erreur
    TrayTip, Tasmota, Échec DEFINITIF de la commande après %maxAttempts% tentatives: %command%, 1, 1
}

SendHttpRequest(url)
{
    try {
        WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
        WebRequest.Open("GET", url, false)
        WebRequest.SetTimeouts(5000, 5000, 5000, 5000)  ; Timeout

        WebRequest.Send()
        result := WebRequest.ResponseText  ; Stocke la réponse

        if (result = "") {
            return "NO RESPONSE"  ; Empêche d’avoir une valeur vide
        }

        return result  ; Retourne la réponse réelle
    }
    catch e {
        return "ERROR"
    }
}



dont understand "Try creating a virtual relay"

Ag Paya

unread,
Mar 2, 2025, 6:37:32 AMMar 2
to TasmotaUsers
what i understand (and what is stopping simple logic) is that " Power1#On" is not recognised if power1 is already ON. So no action is triggered

Justin Adie

unread,
Mar 2, 2025, 7:17:25 AMMar 2
to Ag Paya, SonoffUsers
Yes - the triggers are for when a state changes

Donc pour ceci, dans le code dessous, mieux de formuler la commande http comme:

event%20startTimer


Et pour les règles dans tasmota

rule1 on event#startTimer do backlog ruletimer1 20; power1 1 endon
rule1+ on rules#timer=1 do power1 0 endon

Et initialises le règle

Rule1 1



Philip Knowles

unread,
Mar 2, 2025, 8:44:47 AMMar 2
to Ag Paya, TasmotaUsers
You haven't really explained what you are trying to achieve. There are multiple ways to achieve a 'rearm' but it depends what you wanting to do.
For instance you could use PulseTime and then use the output going off to start a RuleTimer or Delay to turn it back on.
There's also BlinkTime.

So, please explain what you are actually trying to achieve so we can stop guessing.


From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Ag Paya <pay...@gmail.com>
Sent: 02 March 2025 10:35
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Hello, 'simple' timer rearm question.
 

Ag Paya

unread,
Mar 2, 2025, 8:49:20 AMMar 2
to Justin Adie, SonoffUsers

Oui j'ai contourné le problème comme ça:
Pseudo code:
La commande 'power on'  est remplacée par timer1 à 20 sec
Avec :
rulet1 imer1 20; power1 1 endon


rule1+ on rules#timer=1 do power1 0

Mais c'est frustrant de ne pas arriver à coder un logique aussi simple !

Philip Knowles

unread,
Mar 2, 2025, 9:02:17 AMMar 2
to Ag Paya, Justin Adie, SonoffUsers
It looks like you just want to turn the relay off after 20 seconds
Pulsetime 120

Power1 1

And the relay will switch off after 20 seconds - no rule needed

If you want to sometimes have the relay on all the time and at other times want it to switch off after seconds you can use BlinkTime.


Sent: 02 March 2025 13:49
To: Justin Adie <justi...@adieandco.com>
Cc: SonoffUsers <sonof...@googlegroups.com>

Subject: Re: Hello, 'simple' timer rearm question.
 

Oui j'ai contourné le problème comme ça:

Justin Adie

unread,
Mar 2, 2025, 9:18:54 AMMar 2
to Philip Knowles, Ag Paya, SonoffUsers
The OP was wanting a solution where every on command would reset the off event to 20 seconds after the on command.  So 

On. 0 secs
On 18 secs
On 30 secs
Off 50 secs


Ag Paya

unread,
Mar 6, 2025, 4:16:24 AMMar 6
to Justin Adie, Philip Knowles, SonoffUsers

Hello
Thank for trying help me.
A schéma.

Ordre............x..................x..........................

Power...........xxxxxxxxx....xxxxxxxxx.............

Ordre...........x...........x.....................x.......................

Power.......... xxxxxxxxxxxxxxxx.......xxxxxxxxx..........

So 'simple ' rearm timer.

I will look for ' Pulsetime' thanks



Sans virus.www.avast.com

Ag Paya

unread,
Mar 6, 2025, 5:00:19 AMMar 6
to Justin Adie, Philip Knowles, SonoffUsers
hello
'Pulsetime' seems to do the trick without rule
great
thanks to all

ps : dont know how to make 'resolved'

Sans virus.www.avast.com

Philip Knowles

unread,
Mar 6, 2025, 2:01:59 PMMar 6
to Ag Paya, Justin Adie, SonoffUsers
Glad it worked


From: Ag Paya <pay...@gmail.com>
Sent: 06 March 2025 10:01
To: Justin Adie <justi...@adieandco.com>
Cc: Philip Knowles <knowles...@gmail.com>; SonoffUsers <sonof...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages