After Power Loss

35 views
Skip to first unread message

praba karan

unread,
Jun 4, 2024, 1:38:45 AMJun 4
to TasmotaUsers
Is it possible, in wemos d1 mini device can we note the loss of power time and again retrieving time .
Is it store the reading in log and If yes, then how to take the values from log

Justin Adie

unread,
Jun 4, 2024, 1:53:13 AMJun 4
to praba karan, TasmotaUsers
You could derive it approximately from your MQTT broker logs. 



On Tue, 4 Jun 2024, 07:38 praba karan, <prabaka...@gmail.com> wrote:
Is it possible, in wemos d1 mini device can we note the loss of power time and again retrieving time .
Is it store the reading in log and If yes, then how to take the values from log

--
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/63c44f5e-25d3-4774-b449-1e537ba5b599n%40googlegroups.com.

praba karan

unread,
Jun 12, 2024, 1:06:24 PMJun 12
to TasmotaUsers
1.   Once the main power given to Sonoff device gets off and after sometime power will come.
    Is it possible to read that main power failure time  and power came time.


 2. I have set as, the count value stored in  ware are set to clear in every midnight and make it as zero.
 If there is no power in the midnight, then the event counts  are not cleared and the count will add up with the next day count.
 Is it possible to compare based on previous and present date for reset the count.

Justin Adie

unread,
Jun 13, 2024, 2:55:21 AMJun 13
to praba karan, SonoffUsers
You asked this first question on 4th June.  You received responses.  Were those responses not adequate?

On the second question, this type of thing is easier to evaluate server-side.  Which was essentially the recommendation on the first question.  

If you really need a client side tool for monitoring and reporting on system uptime of an IoT device then use a second device that is battery backed.  



praba karan

unread,
Jun 13, 2024, 10:05:34 AMJun 13
to Justin Adie, SonoffUsers
we are using the below rules
rule1 ON Time#Minute=1436 DO backlog mem1 0; mem2 0 ENDON
rule2 ON Time#Minute|2 do  Ping3 192.168.1.197 endon ON Ping#192.168.1.197#Success==0 DO backlog mem1=mem1+1 endon  ON mem1#State==2 do backlog Power1 1;mem2=mem2+1;var3 %timestamp% ENDON 

mem1------> Counts for Ping Failed
mem2 ------> Total restart count of Power1 status per day
var3 ------> Power1 restart with TIMESTAMP
note :
If there is no power at the time of rule1, then  the event counts  are not cleared and the count will add up with the next day count.
How to rectify this issue and make it as zero. if once power came, then it want to start new count.
--
With Regards,
Prabakaran S

praba karan

unread,
Jun 15, 2024, 12:10:29 AMJun 15
to Justin Adie, SonoffUsers
pls any suggestion for above rules.

Justin Adie

unread,
Jun 15, 2024, 4:13:08 AMJun 15
to praba karan, SonoffUsers
I'm not understanding what you are trying to achieve with the counters.  How do they help you at all?  You asked to capture the time that power is lost but none of your rules address that.

This type of thing is best done server side.  Since tasmota primarily relies on MQTT comms (the clue is in the name ...) the monitoring can be done via an mqtt listener.

On your remote side a simple script should do the trick.  Something like this:
#!/usr/bin/php
<?php
$host = "my.mqtt.host";
$port = 1883;
$user = "my user name";
$password = "my mqtt password";
$topic = "tele/my_full_topic/#";
$logFile = "myLogFile.txt";
$logMessage = {};
date_default_timezone_set("UTC");

$cmd = "mosquitto_sub -u \"%s\" -P \"%s\" -p %d -h %s -t %s";
$command = sprintf($cmd,$user,$password,$port,$host,$topic);

$a = popen($command, "r");

file_put_contents(
$logFile,
date(DATE_ATOM) . "\t started listening\n",
FILE_APPEND | LOCK_EX
);

while($line = fgets($a, 2048)){
if(strtolower($line) == "offline"){
file_put_contents(
$logFile,
date(DATE_ATOM) . "\t device offline\n",
FILE_APPEND | LOCK_EX
);
} else {
file_put_contents(
$logFile,
date(DATE_ATOM) . "\t device online\n",
FILE_APPEND | LOCK_EX
);
}
}
file_put_contents(
$logFile,
date(DATE_ATOM) . "\t stopped listening\n",
FILE_APPEND | LOCK_EX
);
?>

Set the script to executable and run it.  Or load it as a service.


There is no cogent method of doing much with a tasmotised device when it has no power.   To reset a counter on boot,  use a rule that triggers at system boot 

>>> on system#boot do mem1 0 endon

There are things you can do if there are hangs every now and then on the tasmota.  The most reliable is to use a second device to switch off the power to the first device for a short period of time.  For these type of scenarios I use a tasmotised plug.  Using rules like your ping would work as a monitor.  You would need to use static IP addresses or hostnames.

On your rule specifically, I am not convinced that trying to do maths on mem1 will work unless you have USE_EXPRESSIONS set at compile time.  Do you?

The point of using memX is so that the variable persists through power loss.  Is this something that you want?  If not then use var.  with varX the value is reset on reboot so you do not need to be concerned about resetting the value. 

To increment a variable use addX.  Eg. 

On system#boot do var1 0 endon on time#minute|5 do add1 endon 
Reply all
Reply to author
Forward
0 new messages