10 second timer tag

I have a boolean tag that when false, I want to run another script that executes periodically that verifies that the first tag should actually be false and if not sets it true.

I was originally using dateExtract(now(),'second')%10=0 && {[.]bool1/Value}=False, which mostly works, except that until the first 10 second multiple is reached, the trigger could occur anywhere from 0 to 10 seconds, and afterwards would indeed be every 10 seconds.

My second attempt was
toInt(dateDiff({[.]enableCancel/Value.Timestamp}, now(),'second'))%10=0 && {[.]bool1/Value}=False

I like this idea better since it executes every 10 seconds since the event started, except this triggers immediately as the initial dateDiff is 0.

Any suggestions? I would like to keep to tag(s) and not use a gateway timer script.

Ok I just added a check for dateDiff to not be 0, so lol yeah.

I'm not sure why you wouldn't want to use a gateway timer script, but you can make a 10 second flasher like this

toMillis(now(10000)) % 20000 > 10000

I have a similar question to OP... I have a tag right now (Memory tag of type String) that holds a message to display to the user. The reason why it's in a tag is because I read/write to it from the UI and from tag change scripts, so I needed something globally scoped. It probably isn't the best way to accomplish this, but it works.

I would like to reset the tag after 10 seconds or so, so that users don't get confused whether a message they're seeing is current or stale.

I would also really try to avoid using a time.sleep or some similar mechanism, but I can't come up with a way to accomplish this.

I was thinking to use a tag group that reads every 10 seconds indefinitely, but it doesn't give me what I want (namely, the 10 second timer to start when the message tag gets populated, not just a cyclic 10 seconds).

Do you have an idea of how to accomplish this?

Use a second tag that looks at the timestamp of the message tag and compare that to now() if the len of the message is greater than zero.

2 Likes

Getting back into this project and wanted to make sure I understand you... You're saying that two tags is all I'll need (say, statusMsg and statusMsgTs)?

I have a setup like this right now, with statusMsg being a String memory tag and statusMsgTs being a Boolean Expression tag. On the expression, I have something like this:

if(
    secondsBetween(now(0), {[.]statusMsg.Timestamp}) > 10 
        && len({[.]statusMsg}) > 0, 
    true, 
    false
)

What isn't super clear is the third step that would clear the tag. The most obvious method would be to have a gateway tag change script that would reset the statusMsgTs back to false and clear the statusMsg tag. Is there something else you had in mind?

Make your expression tag hold either the status string or the empty string, then point your display to the expression tag.

if(
    secondsBetween(now(), {[.]statusMsg.Timestamp}) > 10,
    '', 
    {[.]statusMsg}
)
1 Like

Perfect, that is what I was looking for. The only thing I added was to wrap the secondsBetween call in abs, as I was initially confused why the tag wasn't clearing. This can also be done by swapping the order of the parameters in that expression function, but I might reuse this setup elsewhere, so it will be good to have generalizable (future and past times).

Thank you again.