Item state changing without external interaction

  • Platform information:

    • Hardware: Raspberry Pi 4
    • OS: Linux 4.19.97-v7l+
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
    • openHAB version: openHAB 2.5.3-1 (Release Build)
  • Issue of the topic: I’ve created a virtual switch to be used into HabPanel as a manual trigger for a rule that calls Alexa. The overall solution is working fine but the virtual switch is changing the state without manual interaction. I would to know how to avoid this behaviour.
    Is there something wrong with my setup ?

    • Items configuration related to the issue
 Switch		DR2_CENA_03				"Campainha"
  • Sitemap configuration related to the issue
    HabPanel generic button.

  • Rules code related to the issue

rule "Campainha"
	when
	   	Item DR2_CENA_03 changed from OFF to ON
	then
    var maxLoops = 4

    logInfo("Campainha ", "Recebeu Comando ON")
    sendBroadcastNotification(BABA_ACTING)

    while (DR2_CENA_03.state == ON)
    { 
      Amazon_Echo_Dot_Announcement.sendCommand("Babá Chamando")
      Thread::sleep(10000)
      maxLoops = maxLoops - 1
      if(maxLoops == 0)
      {
        DR2_CENA_03.sendCommand(OFF)
        Amazon_Echo_Dot_Announcement.sendCommand("Babá Chamando")
        logInfo("Campainha ", "Recebeu Comando OFF")
        return
      }
    }
    end

I tried to fix this issue adding an startup condition to the virtual switch:

rule "Items Startup"
when
    System started
then
    DR2_CENA_03.postUpdate(OFF)
end
  • Services configuration related to the issue
    N/A
  • Log
events.log:2020-03-20 03:34:08.284 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command OFF
events.log:2020-03-20 03:34:08.312 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from ON to OFF
events.log:2020-03-20 06:07:36.214 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command ON
events.log:2020-03-20 06:07:36.220 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from OFF to ON
events.log:2020-03-20 06:08:16.320 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command OFF
events.log:2020-03-20 06:08:16.353 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from ON to OFF
events.log:2020-03-20 08:03:39.444 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command ON
events.log:2020-03-20 08:03:39.450 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from OFF to ON
events.log:2020-03-20 08:04:19.539 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command OFF
events.log:2020-03-20 08:04:19.570 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from ON to OFF
events.log:2020-03-20 09:37:55.174 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command ON
events.log:2020-03-20 09:37:55.183 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from OFF to ON
events.log:2020-03-20 09:38:35.301 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command OFF
events.log:2020-03-20 09:38:35.350 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from ON to OFF

Appreciate your help!

Could you explain your log a bit? We don’t know what you expected to happen at those times.

The log is I think incomplete; I would have expected to see some “predicted” messages at least. What else might be going on?

There are two obvious sources of commands to your Item, your habpanel UI and the rule itself.

The rule is not really the way to do things in an event-driven system, but I’m not really clear about what you trying to achieve.

Hi,
Thank you for help on this!
Let me try to clarify it, I create a virtual switch (DR2_CENA_03) and assigned this switch to a button in the Habpanel UI. When I press the button the rule “campainha” is trigged and sends a command 4 times to Alexa (amazon echo dot).

This is working fine, but for some strange reason the rule is being triggered without I touch the Habpanel button. Sometimes everyone is sleeping and Alexa starts talking the message configured in the rule, like a ghost :wink:
As an additional information, I’m not using this virtual switch in other place around my configuration.

Regarding the log, I filtered the it (using grep command) to get only the lines with the virtual switch:

DR2_CENA_03 (virtual switch)

This is the full log is:

2020-03-20 03:33:28.180 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command ON
2020-03-20 03:33:28.203 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from OFF to ON
2020-03-20 03:33:28.232 [ome.event.ItemCommandEvent] - Item 'Amazon_Echo_Dot_Announcement' received command Babá Chamando
2020-03-20 03:33:28.234 [nt.ItemStatePredictedEvent] - Amazon_Echo_Dot_Announcement predicted to become 
2020-03-20 03:33:38.272 [ome.event.ItemCommandEvent] - Item 'Amazon_Echo_Dot_Announcement' received command Babá Chamando
2020-03-20 03:33:38.275 [nt.ItemStatePredictedEvent] - Amazon_Echo_Dot_Announcement predicted to become 
2020-03-20 03:33:48.268 [ome.event.ItemCommandEvent] - Item 'Amazon_Echo_Dot_Announcement' received command Babá Chamando
2020-03-20 03:33:48.270 [nt.ItemStatePredictedEvent] - Amazon_Echo_Dot_Announcement predicted to become 
2020-03-20 03:33:58.286 [ome.event.ItemCommandEvent] - Item 'Amazon_Echo_Dot_Announcement' received command Babá Chamando
2020-03-20 03:33:58.288 [nt.ItemStatePredictedEvent] - Amazon_Echo_Dot_Announcement predicted to become 
2020-03-20 03:34:08.284 [ome.event.ItemCommandEvent] - Item 'DR2_CENA_03' received command OFF
2020-03-20 03:34:08.303 [ome.event.ItemCommandEvent] - Item 'Amazon_Echo_Dot_Announcement' received command Babá Chamando
2020-03-20 03:34:08.309 [nt.ItemStatePredictedEvent] - Amazon_Echo_Dot_Announcement predicted to become 
2020-03-20 03:34:08.312 [vent.ItemStateChangedEvent] - DR2_CENA_03 changed from ON to OFF

Is it clear now ?

Thx

Well, openHAB isn’t making stuff up. A command is appearing from somewhere.

It is unlikely, but do check that you don’t have another Item with the same name. Only one could exist at a time, but the other might have bindings etc. Remember that you may have created Items with PaperUI as well as xxx.items files.

What kind of device does your habpanel run on? What can happen if that hibernates, and wakes up later? I don’t see a reason that would send a spurious command, but something does.
Any other active UIs, perhaps on a phone?

It turns out that autoupdate does not report its “predicted” message unless the Item concerned has linked bindings. So I’ve learnt something.
Your events.log are okay in that respect.