Sonoff RF Bridge and MQTT rule

Hello, I’ve been working to make a SONOFF RF Bridge turn on or off when a 433Mhz RC button is pressed.

I’m using the MQTT v2 from David Graeff and I tried to adapt all the rules to the new standard. I’m running the following rule:


rule "Button pressed"

when Item Sonoff_RF_Received_Data  received update

then
   Thread::sleep(100)
   if (Sonoff_RF_Received_Data  == NULL) {
      logInfo("RfBridge.rules", "Item is null, cancelling...")
      return; // do nothing if NULL
      }
   var rfData = Sonoff_RF_Received_RfKey.state.toString
   logInfo("RfBridge.rules", "Received IT codes: " + rfData)

   switch (rfData) {
      case "1" :
        {


            logInfo("regra SONOFF BRIDGE", "-> Sala_estar_light liga")
             val Actions = getActions ("mqtt", "mqtt:broker:Mosquitto")
             Actions.publishMQTT("cmnd/sonoff-sala/power1", "ON")




        }
      case "5" :
       {
             logInfo("regra SONOFF BRIDGE", "-> Sala_estar_light desliga")
             val Actions = getActions ("mqtt", "mqtt:broker:Mosquitto")
              Actions.publishMQTT("cmnd/sonoff-sala/power1", "OFF")

       }
   }




when I press the button RFKey 1, looking at the logs, I can see that the MQTT message is sent and the light turns ON. However, when I press 5, I see at the log that the light will switch off but nothing happens.

Logs file:

==> /var/log/openhab2/openhab.log <==
2020-04-14 15:13:36.919 [INFO ] [marthome.model.script.RfBridge.rules] - Received IT codes: 1
2020-04-14 15:13:36.922 [INFO ] [ome.model.script.regra SONOFF BRIDGE] - -> Sala_estar_light liga

==> /var/log/openhab2/events.log <==
2020-04-14 15:13:40.744 [vent.ItemStateChangedEvent] - Sonoff_RF_Received_Sync changed from 7340 to 7330
2020-04-14 15:13:40.761 [vent.ItemStateChangedEvent] - Sonoff_RF_Received_RfKey changed from 1 to 5
2020-04-14 15:13:40.766 [vent.ItemStateChangedEvent] - Sonoff_RF_Received_Data changed from B46388 to B4638C

==> /var/log/openhab2/openhab.log <==
2020-04-14 15:13:40.879 [INFO ] [marthome.model.script.RfBridge.rules] - Received IT codes: 5
2020-04-14 15:13:40.887 [INFO ] [ome.model.script.regra SONOFF BRIDGE] - -> Sala_estar_light desliga

Any help will be appreciated!

Paulo

Use an MQTT Client like MQTT Explorer or MQTTfx and see if the message is actually published. If so the problem lies with the Sonoff, not OH.

3 Likes