Migration OH2.4 to 3.4 - received command / Changed to

Hello,
I have problems migrating OH2.4 to OH3.4. It would be nice if somebody can support.

During migration to OH 3.4 (from 2.4) I had to update all my Items, to use channels (instead of mqtt). So I added a thing and some channels (working with mqtt), used by Items.
Via MQTT the item changes to ON in OH3.4 ( OH2.4 it was received command ON) .
Triggering via MQTT the updated rules work. There are other sources to trigger the Item , e.g. HABpanel. Triggering via HABpanel generates the following Events :

2023-01-04 22:10:37.249 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘EG_GZ_T0’ received command ON – ok
2023-01-04 22:10:37.259 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘EG_GZ_T0’ changed from OFF to ON – ok
2023-01-04 22:10:37.274 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘EG_GZ_T0’ changed from ON to OFF – ok
2023-01-04 22:10:37.285 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘EG_GZ_T0’ changed from OFF to ON — !!! why ?

I don’t get it why there is a changed from OFF to ON ?

With OH 2.4 I used a Rule :

rule "LightToggleRxOn"
when
  **Item EG_GZ_T0 received command ON**
then
  if (EG_GZ_R6.state == ON) {     
  	sendCommand(EG_GZ_R6, OFF)   // Relais aus   
  	sendCommand(EG_GZ_T0, OFF)   // Taster wieder auf off stellen 
  }
  else 
  {
  	if (EG_GZ_R6.state == OFF) {   // Relais off
  	sendCommand(EG_GZ_R6, ON)      // switch relais on 
  	}
  	else {
  		sendCommand(EG_GZ_R6, ON)  // switch relais on 
  	} 
  }
end

Wit OH3.4 the Item do not receive Command on, so I had to change the Rule to :

rule "LightToggleRxOn"
when
  **Item EG_GZ_T0 changed to ON**
then
  postUpdate(EG_GZ_T0, OFF)  // Reset the Status to Off , but do not trigger the received command Off rule 
      if (EG_GZ_R6.state == ON) {     
  	sendCommand(EG_GZ_R6, OFF)   // Relais aus   
  	sendCommand(EG_GZ_T0, OFF)   // Taster wieder auf off stellen 
  }
  else 
  {
  	if (EG_GZ_R6.state == OFF) {   // Relais off
  	sendCommand(EG_GZ_R6, ON)      // switch relais on 
  	}
  	else {
  		sendCommand(EG_GZ_R6, ON)  // switch relais on 
  	} 
  }
end

Thanks in advance !
Christian

Hey @chri5

It may be that your rule is running before the state of you Item has been updated. Use implicit variables in your rule.

if (receivedCommand == ON) {

thank you , but this is the state of the Relais not of the item that triggers the rule ( When Relais active light is on, switch Relais to Off )

Something not in your rule is commanding it to turn on.

add logging in your rule to debug

Hi, some tests later it seems that it is a problem of my thing:

**-- ok:** 
Type switch : sEG_GZ_T0 "EG_GZ_T0" [ stateTopic="/Haus/EG/GZ/T0", on="1",	off="0"]  
 **-- not ok:** 
Type switch : sEG_GZ_T0 "EG_GZ_T0" [ **commandTopic="/Haus/EG/GZ/T0"**,	stateTopic="/Haus/EG/GZ/T0",on="1", off="0"]   

Thank you !

Usually stateTopic and commandTopic are different. If they are the same, what you publish out will be received back by itself.

Also usually mqtt topics don’t start with a forward slash. It usually starts with a word.

Example:

Type switch : power1 [ 
  stateTopic="laundryroom-switch/switch/switch1/state", 
  commandTopic="laundryroom-switch/switch/switch1/command" 
]

Thank you for the explanation!