[SOLVED] changedSince stopped working after changing wifi in my house (SOLUTION: pulsetime 20)

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B+
    • OS: 9 (Stretch)
    • Java Runtime Environment: 8
    • openHAB version: 2.5.9-1
  • Issue of the topic: please be detailed explaining your issue

Ok so here we go. For (apparently) no reason, it stopped working.

So everything seems to work just fine, I have other rules using timers, I’m using historicState, and so on… everything works, except for changedSince…

This was very useful for my garage doors because I had something like this on my setup:

rule "Actions with garage gate"

when
   Item Garage_Gate received command ON
then
   if (Outside_Gate.changedSince(now.minusSeconds(60)) == false) {
      sendCommand(Outside_Gate, ON)
   }
end

And that’s it. Everytime I openned by Garage Gate, my Outside Gate would open it it hasn’t been open for the last 60 seconds.

So now it always opens, which is misleading my system whenever I arrive home.

Although it’s a very basic rule, I have then other (more complex) rules working for when I open my Outside Gate. But this is enough to explain my problem. :slight_smile:

(Yet another) isn’t very helpful without reference to other incidents you have presumably looked at and dismissed.

Okay, so you were expecting this signal true at some time.
if (Outside_Gate.changedSince(now.minusSeconds(60)) == false) {

May we see your events.log snippet showing the change that you would expect to block the rule, and the command that you expected to trigger the rule, and the unwanted command that you got.

May we also see your xxx.persist file entry for whichever persistence service you are relying on, when does this Item get persisted.

As you are relying on the system default persistence service being the one you thought of, have you checked the setting for that?

If everything seems in order so far, use REST API to inspect persisted records for this Item.

1 Like

You are absolutely right, but believe me I saw the other ones and none had the solution to my problem. I can however post links to all other posts I’ve read, if that helps. :slight_smile:

Yes, and as I said this was working. It just stopped working for no apparent reason.

Well, I was expecting this question and, my bad, I should have already mentioned that. There is nothing regarding this on events.log nor openhab.log. So it’s like it simply ignores that line and immediately executes the next one. (weird, I know)

Absolutely, there you go, this is what I have in /etc/openhab2/persistence/mysql.persist

Strategies {
	everyMinute	: "0 * * * * ?"
	every5Minutes : "0 */5 * * * ?"
	everyHour   : "0 0 * * * ?"
	everyDay    : "0 0 0 * * ?"
	default = everyChange
}

Items {
    * : strategy = everyChange, everyDay, restoreOnStartup
}

I am using mysql for almost a year now and it has been working flawlessly. Yes, it’s properly setup.

Ok so for this I need your help please. I’ve read this but I am not getting there. How can I test if the “changedSince” is or not working?

Not really, but we have no idea what you’ve already tried or looked at, so you will get advice for stuff that you’ve perhaps already seen and done.

I can’t think that is so.
If you were expecting this rule to run at all, then as it is triggered by command to Garage_Gate that command should be in your events.log

If you were expecting this rule to block the action because there was a recent change in Outside_Gate - then there will be an events.log for that recent event too.

Remember we can’t see what you are doing, when you are doing it, or what happens about it.

Don’t care really, something has gone wrong.
What I was looking for a specific answer for was, what is your system’s default persistence service set to today? Because your changedSince() relies totally on that setting to select where to get the data from. You want it pointing at mysql.

You can’t do that using REST API. This was simply to verify that you had recorded the event you expected to have recorded. You’d just see records with timestamps, but crucially this is openHABs view of the data.
The easiest way is to install misleadingly named “REST API DOCS” which is actually an interactive tool, and use its persistence options.

But at the moment, you don’t even seem to have the event.

Alright, so we learned nothing so far - let’s try a different approach.

rule "Actions with garage gate"
when
   Item Garage_Gate received command ON
then
   logInfo("test", "Gate rule triggered")
   logInfo("test", "Gate state now " + Outside_Gate.state.toString)
   var precord = Outside_Gate.previousState(true)
   logInfo("test", "Gate change default service " + precord.state.toString)
   logInfo("test", "Gate change stamped " + precord.getTimestamp.toString)
   var mrecord = Outside_Gate.previousState(true. "mysql")
   logInfo("test", "Gate change mysql service " + mrecord.state.toString)
   logInfo("test", "Gate change stamped " + mrecord.getTimestamp.toString)
   var trecord = Outside_Gate.historicState(now.minusSeconds(60))
   logInfo("test", "Gate -1min default service " + trecord.state.toString)
   logInfo("test", "Gate -1min stamped " + trecord.getTimestamp.toString)

   if (Outside_Gate.changedSince(now.minusSeconds(60)) == false) {
      sendCommand(Outside_Gate, ON)
   }
end

Unconnected with all this, you might want to review persisting every Item, it’s making stress you may not want in many cases.

First thank you very much for your kind help.

So, regarding settings, here are some images to illustrate what I have:

MySQL Persistence installed:

Screenshot_2020-11-07_12-20-07

mysql persistence selectd on settings:

Screenshot_2020-11-07_12-20-30

mysql.cfg file properly setup:

Now I’ve tested this with lights I have in my office, so I wouldn’t need to open and close gates constantly. Here is events.log file results:

2020-11-07 12:24:24.153 [ome.event.ItemCommandEvent] - Item 'Luz_Escritorio' received command ON
2020-11-07 12:24:24.179 [nt.ItemStatePredictedEvent] - Luz_Escritorio predicted to become ON
2020-11-07 12:24:24.200 [vent.ItemStateChangedEvent] - Luz_Escritorio changed from OFF to ON
2020-11-07 12:24:30.196 [ome.event.ItemCommandEvent] - Item 'Luz_Escritorio_Sanca' received command ON
2020-11-07 12:24:30.221 [nt.ItemStatePredictedEvent] - Luz_Escritorio_Sanca predicted to become ON
2020-11-07 12:24:30.241 [vent.ItemStateChangedEvent] - Luz_Escritorio_Sanca changed from OFF to ON
2020-11-07 12:24:30.368 [ome.event.ItemCommandEvent] - Item 'Luz_Escritorio_Sanca' received command ON
2020-11-07 12:24:30.376 [nt.ItemStatePredictedEvent] - Luz_Escritorio_Sanca predicted to become ON
2020-11-07 12:24:56.960 [ome.event.ItemCommandEvent] - Item 'Luz_Escritorio' received command OFF
2020-11-07 12:24:56.999 [nt.ItemStatePredictedEvent] - Luz_Escritorio predicted to become OFF
2020-11-07 12:24:57.032 [vent.ItemStateChangedEvent] - Luz_Escritorio changed from ON to OFF
2020-11-07 12:24:59.344 [ome.event.ItemCommandEvent] - Item 'Luz_Escritorio_Sanca' received command OFF
2020-11-07 12:24:59.381 [nt.ItemStatePredictedEvent] - Luz_Escritorio_Sanca predicted to become OFF
2020-11-07 12:24:59.410 [vent.ItemStateChangedEvent] - Luz_Escritorio_Sanca changed from ON to OFF
2020-11-07 12:24:59.466 [ome.event.ItemCommandEvent] - Item 'Luz_Escritorio_Sanca' received command OFF
2020-11-07 12:24:59.480 [nt.ItemStatePredictedEvent] - Luz_Escritorio_Sanca predicted to become OFF
2020-11-07 12:25:00.354 [ome.event.ItemCommandEvent] - Item 'Luz_Escritorio' received command ON
2020-11-07 12:25:00.392 [nt.ItemStatePredictedEvent] - Luz_Escritorio predicted to become ON
2020-11-07 12:25:00.414 [vent.ItemStateChangedEvent] - Luz_Escritorio changed from OFF to ON

And here openhab.log:

2020-11-07 12:24:29.929 [INFO ] [.eclipse.smarthome.model.script.test] - Testing Gate rule triggered
2020-11-07 12:24:29.942 [INFO ] [.eclipse.smarthome.model.script.test] - Gate state now OFF
2020-11-07 12:24:30.046 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change default service ON
2020-11-07 12:24:30.054 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-07 12:12:30.0
2020-11-07 12:24:30.125 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change mysql service ON
2020-11-07 12:24:30.133 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-07 12:12:30.0
2020-11-07 12:24:30.159 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs default service OFF
2020-11-07 12:24:30.169 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs stamped 2020-11-07 12:12:31.0
2020-11-07 12:25:00.368 [INFO ] [.eclipse.smarthome.model.script.test] - Testing Gate rule triggered
2020-11-07 12:25:00.382 [INFO ] [.eclipse.smarthome.model.script.test] - Gate state now OFF
2020-11-07 12:25:00.475 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change default service ON
2020-11-07 12:25:00.481 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-07 12:24:30.0
2020-11-07 12:25:00.535 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change mysql service ON
2020-11-07 12:25:00.543 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-07 12:24:30.0
2020-11-07 12:25:00.561 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs default service ON
2020-11-07 12:25:00.571 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs stamped 2020-11-07 12:24:30.0

Now, in this trial after adding your “testing code”, it worked! It did not turned on the second time…

So does this means that I will have to, each time I activate one gate, directly save previousState in mysql? I mean, it makes no sense to do it because it should simply read the latest states…

And yes, states are always being properly saved in DB.

PS: You had a typo on previousState. Instead of a point in (true. “mysql”) it should be a comma.

I’m not sure what you mean. None of the code discussed so far saves anything. It only reads what was put in your database by your mysql.persist instructions.

You are probably going to have to apply the diagnostics to your real rule to find out what goes wrong with your real devices. We already know the code does what it is supposed to, it is probably a matter of timing.

Ok, so I only had time to test this now but here we go.

This is my garage.rules file:

var Timer offTimer = null
val Number hours = now.getHourOfDay
val PorSol = new DateTime(Por_Sol.historicState(now).state.toString)



rule "Ações com o portão exterior"

when
   Item Portao_Exterior received command ON
then

   logInfo("test", "Testing EXTERIOR Gate rule triggered")
   logInfo("test", "Gate state now " + Portao_Exterior.state.toString)
   var precord = Portao_Exterior.previousState(true)
   logInfo("test", "Gate change default service " + precord.state.toString)
   logInfo("test", "Gate change stamped " + precord.getTimestamp.toString)
   var mrecord = Portao_Exterior.previousState(true, "mysql")
   logInfo("test", "Gate change mysql service " + mrecord.state.toString)
   logInfo("test", "Gate change stamped " + mrecord.getTimestamp.toString)
   var trecord = Portao_Exterior.historicState(now.minusSeconds(10))
   logInfo("test", "Gate -10secs default service " + trecord.state.toString)
   logInfo("test", "Gate -10secs stamped " + trecord.getTimestamp.toString)

   if (Alarme_Casa.historicState(now).state.toString == "ON") {
      sendCommand(Alarme_Casa, OFF)
   }

   offTimer = createTimer(now.plusSeconds(15), [|
      if (Portao_Garagem.changedSince(now.minusSeconds(60)) == false) {
         sendCommand(Portao_Garagem, ON)
      }
   ])

   if ((now.isAfter(PorSol).toString == "true" || hours < 7)
      && Luz_Exterior_Frente.historicState(now).state.toString == "OFF"
      && Luz_Exterior_Garagem.historicState(now).state.toString == "OFF") {
      sendCommand(Luz_Exterior_Frente, ON)
      sendCommand(Luz_Exterior_Garagem, ON)
      offTimer = createTimer(now.plusMinutes(1), [|
         sendCommand(Luz_Exterior_Frente, OFF)
         sendCommand(Luz_Exterior_Garagem, OFF)
      ])
   }
end



rule "Ações com o portão da garagem"

when
   Item Portao_Garagem received command ON
then

   logInfo("test", "Testing GARAGE Gate rule triggered")
   logInfo("test", "Gate state now " + Portao_Garagem.state.toString)
   var precord = Portao_Garagem.previousState(true)
   logInfo("test", "Gate change default service " + precord.state.toString)
   logInfo("test", "Gate change stamped " + precord.getTimestamp.toString)
   var mrecord = Portao_Garagem.previousState(true, "mysql")
   logInfo("test", "Gate change mysql service " + mrecord.state.toString)
   logInfo("test", "Gate change stamped " + mrecord.getTimestamp.toString)
   var trecord = Portao_Garagem.historicState(now.minusSeconds(10))
   logInfo("test", "Gate -10secs default service " + trecord.state.toString)
   logInfo("test", "Gate -10secs stamped " + trecord.getTimestamp.toString)

   if (Portao_Exterior.changedSince(now.minusSeconds(60)) == false) {
      sendCommand(Portao_Exterior, ON)
   }
end

After this, I clicked to open my garage gate and this is the events.log output:

2020-11-09 17:40:04.521 [ome.event.ItemCommandEvent] - Item 'Portao_Garagem' received command ON
2020-11-09 17:40:04.530 [nt.ItemStatePredictedEvent] - Portao_Garagem predicted to become ON
2020-11-09 17:40:04.585 [vent.ItemStateChangedEvent] - Portao_Garagem changed from OFF to ON
2020-11-09 17:40:04.713 [ome.event.ItemCommandEvent] - Item 'Portao_Exterior' received command ON
2020-11-09 17:40:04.717 [nt.ItemStatePredictedEvent] - Portao_Exterior predicted to become ON
2020-11-09 17:40:04.733 [vent.ItemStateChangedEvent] - Portao_Exterior changed from OFF to ON
2020-11-09 17:40:04.875 [vent.ItemStateChangedEvent] - Portao_Garagem changed from ON to OFF
2020-11-09 17:40:05.429 [vent.ItemStateChangedEvent] - Portao_Exterior changed from ON to OFF
2020-11-09 17:40:19.995 [ome.event.ItemCommandEvent] - Item 'Portao_Garagem' received command ON
2020-11-09 17:40:20.001 [nt.ItemStatePredictedEvent] - Portao_Garagem predicted to become ON
2020-11-09 17:40:20.031 [vent.ItemStateChangedEvent] - Portao_Garagem changed from OFF to ON
2020-11-09 17:40:20.303 [vent.ItemStateChangedEvent] - Portao_Garagem changed from ON to OFF

And this is my openhab.log output:

2020-11-09 17:40:04.494 [INFO ] [.eclipse.smarthome.model.script.test] - Testing GARAGE Gate rule triggered
2020-11-09 17:40:04.519 [INFO ] [.eclipse.smarthome.model.script.test] - Gate state now OFF
2020-11-09 17:40:04.609 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change default service OFF
2020-11-09 17:40:04.622 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-09 17:35:52.0
2020-11-09 17:40:04.646 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change mysql service OFF
2020-11-09 17:40:04.651 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-09 17:35:52.0
2020-11-09 17:40:04.670 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs default service OFF
2020-11-09 17:40:04.678 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs stamped 2020-11-09 17:35:52.0
2020-11-09 17:40:04.703 [INFO ] [.eclipse.smarthome.model.script.test] - Testing EXTERIOR Gate rule triggered
2020-11-09 17:40:04.711 [INFO ] [.eclipse.smarthome.model.script.test] - Gate state now OFF
2020-11-09 17:40:04.834 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change default service OFF
2020-11-09 17:40:04.842 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-09 17:35:52.0
2020-11-09 17:40:04.869 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change mysql service OFF
2020-11-09 17:40:04.883 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-09 17:35:52.0
2020-11-09 17:40:04.898 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs default service OFF
2020-11-09 17:40:04.905 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs stamped 2020-11-09 17:35:52.0
2020-11-09 17:40:19.984 [INFO ] [.eclipse.smarthome.model.script.test] - Testing GARAGE Gate rule triggered
2020-11-09 17:40:20.005 [INFO ] [.eclipse.smarthome.model.script.test] - Gate state now OFF
2020-11-09 17:40:20.069 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change default service OFF
2020-11-09 17:40:20.080 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-09 17:40:04.0
2020-11-09 17:40:20.102 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change mysql service OFF
2020-11-09 17:40:20.110 [INFO ] [.eclipse.smarthome.model.script.test] - Gate change stamped 2020-11-09 17:40:04.0
2020-11-09 17:40:20.123 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs default service OFF
2020-11-09 17:40:20.129 [INFO ] [.eclipse.smarthome.model.script.test] - Gate -10secs stamped 2020-11-09 17:40:04.0

This is no use. You’re not interested in the state or previous state of Portao_Garagem. You know it’s probably going to change anyway, because you just sent it a command.

Your if() test later in the rule is all about Portao_Exterior -that’s the one you’re interested in knowing the state and previous states of, because you say the if() doesn’t do what you expect.

Let’s try another way

   if (Portao_Exterior.changedSince(now.minusSeconds(60)) == false) {
      sendCommand(Portao_Exterior, ON)
   }

You say you get results there sometimes that you do not expect.
So you would want to find out what result you expected from changedSince.

We’ve now established that your persistence is basically functional, so we can skip some of the tests.
There’s two parts to a changedSince test - what you got now, and what you had then. Let’s look at those.

      // a minute ago
   var precord = Portao_Exterior.historicState(now.minusSeconds(60))
   logInfo("test", "Item -1 min " + precord.state.toString)
   logInfo("test", "Actual timestamp " + precord.getTimestamp.toString)
      // now
   logInfo("test", "Item state now " + Portao_Exterior.state.toString)

      // now lets do the real thing
   if (Portao_Exterior.changedSince(now.minusSeconds(60)) == false) {
      sendCommand(Portao_Exterior, ON)
   }

Ok so let’s see, I’ve made the change you suggested and here are the outputs:

events.log

2020-11-10 12:56:19.316 [ome.event.ItemCommandEvent] - Item 'Portao_Garagem' received command ON
2020-11-10 12:56:19.358 [nt.ItemStatePredictedEvent] - Portao_Garagem predicted to become ON
2020-11-10 12:56:19.397 [vent.ItemStateChangedEvent] - Portao_Garagem changed from OFF to ON
2020-11-10 12:56:19.577 [vent.ItemStateChangedEvent] - Portao_Garagem changed from ON to OFF
2020-11-10 12:56:23.651 [ome.event.ItemCommandEvent] - Item 'Portao_Exterior' received command ON
2020-11-10 12:56:23.690 [nt.ItemStatePredictedEvent] - Portao_Exterior predicted to become ON
2020-11-10 12:56:23.713 [vent.ItemStateChangedEvent] - Portao_Exterior changed from OFF to ON
2020-11-10 12:56:24.345 [vent.ItemStateChangedEvent] - Portao_Exterior changed from ON to OFF
2020-11-10 12:56:38.712 [ome.event.ItemCommandEvent] - Item 'Portao_Garagem' received command ON
2020-11-10 12:56:38.755 [nt.ItemStatePredictedEvent] - Portao_Garagem predicted to become ON
2020-11-10 12:56:38.780 [vent.ItemStateChangedEvent] - Portao_Garagem changed from OFF to ON
2020-11-10 12:56:39.058 [vent.ItemStateChangedEvent] - Portao_Garagem changed from ON to OFF

openhab.log

2020-11-10 12:56:23.616 [INFO ] [.eclipse.smarthome.model.script.test] - Item -1 min OFF
2020-11-10 12:56:23.624 [INFO ] [.eclipse.smarthome.model.script.test] - Actual timestamp 2020-11-10 00:00:01.0
2020-11-10 12:56:23.630 [INFO ] [.eclipse.smarthome.model.script.test] - Item state now OFF
2020-11-10 12:56:38.740 [INFO ] [.eclipse.smarthome.model.script.test] - Item -1 min OFF
2020-11-10 12:56:38.750 [INFO ] [.eclipse.smarthome.model.script.test] - Actual timestamp 2020-11-10 00:00:01.0
2020-11-10 12:56:38.764 [INFO ] [.eclipse.smarthome.model.script.test] - Item state now OFF

Okay, everything seems to be doing what it was told to do.

 ... Item -1 min OFF
 ... Actual timestamp 2020-11-10 00:00:01.0
 ... Item state now OFF

So, in your rule when you test changedSince() for 1 minute ago against “now”, the answer will be false, not changed. The state for a minute ago was OFF, the state now is OFF.

Observations of interest -

 Actual timestamp 2020-11-10 00:00:01.0

General info - when you ask persistence for a record from “1 minute ago”, there probably isn’t one for that exact instant.
So the persistence service gets the most recent record from before the target time e.g. if we have a record OFF at 08:00 and we search for a record at 08:05, it will return the 08:00/OFF record because that was the last known state and is presumed to be still valid at 08:05.

You can see when that happens (which is more or less every time) because you get the real timestamp of the record. That’s why I had you log that out.

The thing you might not be expecting here is that the most recent record for your Item appears to be from midnight.
When do you think you are saving data? That 00:00:01.0 record looks like everyDay to me.
You showed us your mysql.persist file that does have everyDay, so that looks to be working. Plus it has everyChange.

Does everyChange work then? Only if there are changes, of course.

2020-11-10 12:56:23.713 [vent.ItemStateChangedEvent] - Portao_Exterior changed from OFF to ON
2020-11-10 12:56:24.345 [vent.ItemStateChangedEvent] - Portao_Exterior changed from ON to OFF

It seems like does change, hurrah!
Albeit only for half a second. That’s a bit of a small window, and may come back on us yet.

After this, your rule does run again at 2020-11-10 12:56:38.740 … and the “1 minute ago” still returns us the ‘midnight’ record. But that’s as it should be, “one minute ago” from 12:56:38 is still before that recent change at 12:56:24.

The open question is whether your everyChange records are effective for this Item, we just cannot tell from info so far. Have another try?

Yes, it seems to be effective, look at my database for this item:

Does your list look complete to you? Doesn’t seem like many ON/OFF transitions to me, you seem to get sequences of OFF with no corresponding ON.

I’ll bet your mysql granularity is set up to record only value per second, and an ON then OFF update in the same second results in a single OFF record.

How come your gate only shows open for half a second?

1 Like

I did changed my wifi so is it that for some reason it’s not communicating as fast as it should? :open_mouth:

Let me try to change on Tasmota firmware the timing to turn the item OFF since this was set to zero only because it only needed to give the signal to open and that’s it.

Use the records already available to you, understand the problem.
Your events.log will show you when that Item state changed.
You’ve got a viewing tool that shows you what’s in your mysql.
Compare and contrast; does my guess about granularity look right?

1 Like

Ufff… finally we made it! :smiley:

Thank you SO much for your help on debugging this. Without it I would be stuck.

So, resuming:

In my case what was causing the problem was the pulse time on Tasmota firmware settings for my Sonoff SV devices that I am using for my gates.

All I had to do was going to the IP address of each Sonoff SV, go to Console menu and type this:

pulsetime1 2

By doing this, it simply waits 2 seconds before turning off and now it can always properly register in mysql the correct value and therefore, it works again. :smiley:

EDIT1: I even edited the title so that it can now clearly express the problem and try to help future visitors with same problem. :slight_smile:

EDIT2: IMPORTANT NOTICE - I simply cannot understand why, but although it worked a couple of times, it started again to loop weirdly opening and closing the gates, simply ignoring the existence of changeState checking… I then tried to change the minusSeconds to 15 instead of 60, no luck! But then I changed to 30 seconds, and voila! Don’t ask me why, but it’s now working properly…

@rossko57 Well… today I had to use the gates multiple times and there is definitely something wrong here! I cannot understand what it is but this is definitely not stable at all. Sometimes it works, sometimes it doesn’t! :frowning:

What can we do next?

Show us your events.log of a problem situation. We can’t see what’s happening.

Here it is, the last time I used and it went wrong (remember, this is after I changed yesterday the minusSeconds to 30 seconds):

2020-11-12 15:10:44.062 [ome.event.ItemCommandEvent] - Item 'Portao_Exterior' received command ON
2020-11-12 15:10:44.065 [nt.ItemStatePredictedEvent] - Portao_Exterior predicted to become ON
2020-11-12 15:10:44.087 [vent.ItemStateChangedEvent] - Portao_Exterior changed from OFF to ON
2020-11-12 15:10:44.475 [vent.ItemStateChangedEvent] - Portao_Exterior changed from ON to OFF
2020-11-12 15:10:59.128 [ome.event.ItemCommandEvent] - Item 'Portao_Garagem' received command ON
2020-11-12 15:10:59.133 [nt.ItemStatePredictedEvent] - Portao_Garagem predicted to become ON
2020-11-12 15:10:59.164 [vent.ItemStateChangedEvent] - Portao_Garagem changed from OFF to ON
2020-11-12 15:10:59.197 [ome.event.ItemCommandEvent] - Item 'Portao_Exterior' received command ON
2020-11-12 15:10:59.200 [nt.ItemStatePredictedEvent] - Portao_Exterior predicted to become ON
2020-11-12 15:10:59.223 [vent.ItemStateChangedEvent] - Portao_Exterior changed from OFF to ON
2020-11-12 15:10:59.597 [vent.ItemStateChangedEvent] - Portao_Exterior changed from ON to OFF

As we can see, the external gate oppened, then as it is supose to it openned the garage gate but then it immediately ran the other rule although it was NOT supose to.

For the garage gate, it only registered the ON state in mysql, not the OFF state:

Screenshot_2020-11-12_19-29-09

For the external gate, it registered only the OFF state the two times:

Screenshot_2020-11-12_19-30-30

Why do think it’s not supposed to? Have you thought about the triggers for your rules?

when
   Item Portao_Garagem received command ON

I’m not surprised. You don’t seem to have addressed the underlying issue that your mysql setup has a granularity of one second, and your “gate open” event duration is less than a second.

2020-11-12 15:10:44.087 [vent.ItemStateChangedEvent] - Portao_Exterior changed from OFF to ON
2020-11-12 15:10:44.475 [vent.ItemStateChangedEvent] - Portao_Exterior changed from ON to OFF

your mysql db preserves only the last event during second 44

What I suggest you do here is - forget rules for minute.
Concentrate on getting your “gate open” signalling reliable.

Let’s look at these events closely -

2020-11-12 15:10:59.197 [ome.event.ItemCommandEvent] - Item 'Portao_Exterior' received command ON
2020-11-12 15:10:59.200 [nt.ItemStatePredictedEvent] - Portao_Exterior predicted to become ON
2020-11-12 15:10:59.223 [vent.ItemStateChangedEvent] - Portao_Exterior changed from OFF to ON
2020-11-12 15:10:59.597 [vent.ItemStateChangedEvent] - Portao_Exterior changed from ON to OFF

See the ‘predicted’?
This is openHABs autoupdate feature at work.
This is enabled on your Item by default, and in response to command ON guesses the likely outcome will be state ON.
The update at 59.223 is that prediction being applied to your Item.

Next, we get another update at 59.597, some 400mS later. That’s almost certainly a real response from your Tasmota device - but it’s OFF. Why still off? Well it only got sent an ON command a couple of hundred milliseconds ago, the damned gate hasn’t moved yet.

What’s missing is an eventual ON update after the gate has had time to open.

I would think that you might want to disable autoupdate, stop it interfering.

Then you’d want to look at how your Tasmota is configured, why is it not reporting movement.

Wow, I didn’t even noticed that. But I changed pulsetime on Tasmota?!?! Should I change it on pulsetime2 or something like that instead of 1? I will try it out and let you know.