Timestamp comparison in a rule

210 views
Skip to first unread message

Alex

unread,
Nov 30, 2022, 12:43:49 AM11/30/22
to TasmotaUsers
Hi I am trying to make a rule that will turn off the power at a certain time. The time is set by an outside source(Home Assistant). The time needs to survive power loss. With my knowledge of tasmota rules this is what I was able to think of:
on Time#minute do event current_time=%timestamp% endon on event#current_time>%mem1% do Power1 off endon
Where mem1 is the time set by Home Assistant
However event#current_time>%mem1%is not triggered (except when I set mem1 to 0 - so I know the rule can be triggered if I know how to do the comparison correctly). I have tried setting mem1 to a unix timestamp like 1669786474 and to 2022-12-01T07:34:34 but the rule does not trigger in both cases.
Can anyone help me with doing the comparison correctly. Or if there is a better way to do this.
Thank you

Philip Knowles

unread,
Nov 30, 2022, 6:42:08 AM11/30/22
to Alex, TasmotaUsers

Not entirely sure what you are trying to achieve (because, if you are using HA, why isn’t a timer in HA doing the command?) but, if you get HA to send the JSON to create a Timer, it will survive a power cycle.

 

Timer1 {"Enable":1,"Time":"07:34","Window":0,"Days":"----T--","Repeat":0,"Output":1,"Action":3}

 

On clock#timer1= do power1 0 endon

 

That will turn the power off at 734 on Thursday as a one off Timer

 

 

Sent from Mail for Windows

--
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 on the web, visit https://groups.google.com/d/msgid/sonoffusers/3206c801-78a5-4fc8-9380-64bc849da892n%40googlegroups.com.

 

Alex

unread,
Dec 1, 2022, 12:32:40 AM12/1/22
to TasmotaUsers
About the HA do the command instead of this rule - I prefer to keep as much of the logic on the device as possible - that way I can use it from another source or directly without losing functionality.
I have considered timers but they seemed to be a pain to generate in HA (compared to a timestamp or ISO date) so I was hoping to make the comparison rule work. So is there no way to do this comparison?
Thank you

Philip Knowles

unread,
Dec 1, 2022, 2:32:12 AM12/1/22
to Alex, TasmotaUsers
Are these 'one-off' times that you want to set? And how do you 'generate' the times to create the timestamp?
I've now removed all 'local' control from my system (other than 'off timers'). I use Google, local switches and the openHAB app and webUI (and sometimes Tasmota webUI) for control. For instance, 'OK Google, turn on the living room light at 7am tomorrow' works easily. 


From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of Alex <yordanov....@gmail.com>
Sent: Thursday, December 1, 2022 5:32:39 AM
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Re: Timestamp comparison in a rule
 

Александър Йорданов

unread,
Dec 1, 2022, 2:53:51 AM12/1/22
to Philip Knowles, TasmotaUsers
Yes they are one off times. I generate them as a template in HA: {{ now().timestamp()|int + 72*60*60 }} and {{ now().timestamp()|int + 24*60*60 }} are the two cases that I have for now for 72 and 24 hours in the future.
The template is in an automation triggered by a mqtt message coming from RFBridge that receives a signal from a rf remote

cybe...@gmail.com

unread,
Dec 1, 2022, 3:04:00 AM12/1/22
to TasmotaUsers
Maybe use 0~1440 minute based time of day instead of timestamp:

So:
on Time#minute do event current_time=%time% endon on event#current_time>%mem1% do Power1 off endon
and fill %mem1 with a minute value.

It is how I do my daylight timers, not entirely the same, but sort of the same bases

Rule1
ON Time#Initialized DO event checktime=%time% ENDON
ON Clock#Timer DO event checktime=%time% ENDON
ON event#checktime DO %var10% 0 ENDON
ON event#checktime>=%timer1% DO var10 1 ENDON
ON event#checktime>=%timer2% DO var10 0 ENDON
ON event#checktime>=%timer3% DO var10 1 ENDON
ON event#checktime>=%timer4% DO var10 0 ENDON
ON event#checktime DO Power1 %var10% ENDON

Александър Йорданов

unread,
Dec 1, 2022, 5:00:31 AM12/1/22
to cybe...@gmail.com, TasmotaUsers
I don't see how Time#minute will help me - I need to be able to set the end time for a few days ahead - if I use Time#minute the end time is limited for a maximum of one day. Or am I not understanding something?

You received this message because you are subscribed to a topic in the Google Groups "TasmotaUsers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonoffusers/kpXA3ze4O9c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/14c4d15f-e71f-411f-b711-3115986d0e1en%40googlegroups.com.

Philip Knowles

unread,
Dec 1, 2022, 7:28:12 AM12/1/22
to cybe...@gmail.com, TasmotaUsers

The one 24 hours later is relatively simple

Rule1 On power1#state=1 do backlog mem1 %time%; delay 700; rule2 1 endon //sets mem1 to minutes past midnight, waits 70 seconds then turns on rule2

Rule2 On time#minute=%mem1% do backlog power1 0; rule2 0 endon // turns power off at number of minutes past midnight and then turns itself off

 

You could also create separate Timers at 00:01 for each day of the week which you enable for the day you want to switch off and it enables rule2 for that day (rather than at the end of rule1).

 

If you compile with scripts and/or expressions you can do more arithmetic functions.

 

Sent from Mail for Windows

 

From: cybe...@gmail.com
Sent: 01 December 2022 08:04
To: TasmotaUsers
Subject: Re: Timestamp comparison in a rule

 

Maybe use 0~1440 minute based time of day instead of timestamp:

 

So:

on Time#minute do event current_time=%time% endon on event#current_time>%mem1% do Power1 off endon

and fill %mem1 with a minute value.

 

It is how I do my daylight timers, not entirely the same, but sort of the same bases

 

Rule1
ON Time#Initialized DO event checktime=%time% ENDON
ON Clock#Timer DO event checktime=%time% ENDON
ON event#checktime DO %var10% 0 ENDON
ON event#checktime>=%timer1% DO var10 1 ENDON
ON event#checktime>=%timer2% DO var10 0 ENDON
ON event#checktime>=%timer3% DO var10 1 ENDON
ON event#checktime>=%timer4% DO var10 0 ENDON
ON event#checktime DO Power1 %var10% ENDON

On Thursday, December 1, 2022 at 8:53:51 AM UTC+1 Alex wrote:

Yes they are one off times. I generate them as a template in HA: {{ now().timestamp()|int + 72*60*60 }} and {{ now().timestamp()|int + 24*60*60 }} are the two cases that I have for now for 72 and 24 hours in the future.

The template is in an automation triggered by a mqtt message coming from RFBridge that receives a signal from a rf remote

 

On Thu, Dec 1, 2022 at 9:32 AM Philip Knowles <knowles...@gmail.com> wrote:

Are these 'one-off' times that you want to set? And how do you 'generate' the times to create the timestamp?

I've now removed all 'local' control from my system (other than 'off timers'). I use Google, local switches and the openHAB app and webUI (and sometimes Tasmota webUI) for control. For instance, 'OK Google, turn on the living room light at 7am tomorrow' works easily. 

 

F5...@wanadoo.fr

unread,
Dec 2, 2022, 3:36:04 AM12/2/22
to sonof...@googlegroups.com
Hi all

I have tasmotize a Sonoff Zigbee Bridge Pro. I currently use the release
12.2.0 of tasmota.
Everything seems fine but after few days I have lost the Zigbee map. It
is now a blank page. I have tried to restart, toggling power supply
without success.
Somebody knows this problem ?
It might be a file corrupted in the file system but which one ?

Thanks in advance



--
Cet e-mail a été vérifié par le logiciel antivirus d'Avast.
www.avast.com

Philip Knowles

unread,
Dec 2, 2022, 3:48:19 AM12/2/22
to F5...@wanadoo.fr, sonof...@googlegroups.com
Are the devices still paired?
From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of F5...@wanadoo.fr <F5...@wanadoo.fr>
Sent: Friday, December 2, 2022 8:35:54 AM
To: sonof...@googlegroups.com <sonof...@googlegroups.com>
Subject: Zigbee bridge map blank
 
--
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.

F5...@wanadoo.fr

unread,
Dec 2, 2022, 9:16:20 AM12/2/22
to Philip Knowles, sonof...@googlegroups.com

Yes all devices are paired and communication seems OK.


Sans virus.www.avast.com

Stephan Hadinger

unread,
Dec 2, 2022, 10:49:33 AM12/2/22
to TasmotaUsers
Please try `zbmap` command and check the console. If you do see map information in the console, it can mean that it's only a browser issue. Please also keep in mind that the JS framework used to display the map requires that your browser has internet access.

Stephan

F5...@wanadoo.fr

unread,
Dec 2, 2022, 11:40:46 AM12/2/22
to sonof...@googlegroups.com

Thanks for reply

ZBMAP seems to give to reply. So it might mean that it could be browser issue !!??

I currently use Firefox, tried also with Edge,....same problem, both have internet access.

F5...@wanadoo.fr

unread,
Dec 2, 2022, 11:53:19 AM12/2/22
to sonof...@googlegroups.com

I have found my problem. I have deleted one device which had addtess  0x0000 ??!!

I don't know where device came from but for sure was not in use and block the map.

Thanks to all for support

Philippe

Александър Йорданов

unread,
Dec 8, 2022, 12:31:52 AM12/8/22
to Philip Knowles, cybe...@gmail.com, TasmotaUsers
Hi
Sorry for the delay.
That is a great idea and I almost used it :). But I wanted it to sit some days in my head with the hope that I'll get a better idea, and I did(at least in my opinion :) )
I was doing some experimentation on why my comparison is not working and I figured it out - the timestamp is a string (which I should have known from the start but I have a mental connection between timestamp and unix timestamp and that's why I was treating it as seconds and not string...). So when the rule tries to compare the two timestamps as numbers it takes only the first parts which are numbers(in this case 2022) and compares them.
So knowing that and with the ideas from this thread I ended up with these rules which I like best:

Rule1 on Time#minute do event current_time=%timestamp% endon on event#current_time$<%mem2% do backlog rule2 1;rule1 0; endon
Rule2 on Time#minute do var1 %time% endon on var1#state>=%mem3% do backlog  Mem1 0;rule2 0; endon

Where mem2 is in the format 20022-12-08 and mem3 is minutes since midnight. Mem1 is a part of Rule3 - another part of the device functionality that has nothing to do with this problem, and setting it to 0 effectively does power off.

Thank you all for the help

You received this message because you are subscribed to a topic in the Google Groups "TasmotaUsers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sonoffusers/kpXA3ze4O9c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sonoffusers...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/sonoffusers/6935C3E8-44A7-4C5A-B791-5B02553C0096%40hxcore.ol.
Reply all
Reply to author
Forward
0 new messages