Sonoff (tasmota) RF Bridge to item file

okay… the items kinda works… I have changed a few mistakes ind the code now I looks like:

String Sonoff_Button { mqtt="<[broker:tele/sonoff_rf/RESULT:state:JSONPATH($.RfReceived.Data)]" }

But… when I press the button on the RF Transmitter openhab log sees it… and write:

Sonoff_Button changed from NULL to 6A8CD2

But… it does not sees when I press again… first I have to pres another button, and the log says:

Sonoff_Button changed from 6A8CD2 to 6A8CD8

And the it sees when I press the first button again…

Also the rules, logs tells me:
Configuration model ‘sonoffrf.rules’ is either empty or cannot be parsed correctly!

rules looks like this:

Rule "Button Pressed"
when
    Sonoff_Button received update // Need received update if Data has not change but button still pressed
then
    Thread:sleep(100) // Need the sleep to allow for the state to change
    If (Sonoff_Button,state = "6A8CD2") {
       if (4CH01.state == ON || 4CH01.state == NULL) 4CH01.sendCommand(OFF)
else 4CH01.sendCommand(ON)
    }
end

4CH01 is an item

Item names cannot begin with a number in the text rules
You’ll have to rename the item
And there is a double == in the if conditional test

Rule "Button Pressed"
when
    Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
    Thread:sleep(100) // Need the sleep to allow for the state to change
    If (Sonoff_Button,state == "6A8CD2") {
       if (4CH01.state == ON || 4CH01.state == NULL) 4CH01.sendCommand(OFF)
else 4CH01.sendCommand(ON)
    }
end

I thought that the received update trigger would take care of that
What is the events.log when you press the same button several times?

Have updated the rule, with the missing = and selected another item fore test… log still says:

Configuration model ‘sonoffrf.rules’ is either empty or cannot be parsed correctly!

event log only registeres when I press the button the first time… then nothing happens until I have pressed another button…with another ID

That is because you item 4CH01 starts with a number. The text rules don’t accept item names starting with numbers.
You’ll have to rename the item.

Ok, that’s a problem. Let me think about it

the item is renamed now it is “pow1” instead of “4cd01”

Rule "Button Pressed"
when
    Sonoff_Button received update // Need received update if Data has not change but button still pressed
then
    Thread:sleep(100) // Need the sleep to allow for the state to change
    If (Sonoff_Button,state == "6A8CD2") {
       if (Pow1.state == ON || Pow1.state == NULL) Pow1.sendCommand(OFF)
else Pow1.sendCommand(ON)
    }
end

My fault if not If

hate to say it… but still not working, the same as before… :frowning:

I obviously was still asleep this morning
rule not Rule
Thread::sleep not Thread:sleep
And Sonoff_Button.state not Sonoff_Button,state

rule "Button Pressed"
when
    Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
    Thread::sleep(100) // Need the sleep to allow for the state to change
    if (Sonoff_Button.state == "6A8CD2") {
        if (Pow1.state == ON || Pow1.state == NULL) Pow1.sendCommand(OFF)
        else Pow1.sendCommand(ON)
    }
end

Still the same… but in the meantime I have played with a simple on off rule… and I have noticed that something is different… iam using

if (TH101.state == OFF) { sendCommand(TH101, ON) }

Simple… but the sendCommand is different from what you have done… does that matter…?

Yes but not the way you think:

So try:

rule "Button Pressed"
when
    Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
    Thread::sleep(100) // Need the sleep to allow for the state to change
    if (Sonoff_Button.state == "6A8CD2") {
        if (Pow1.state == ON || Pow1.state == NULL) { Pow1.sendCommand(OFF) }
        else { Pow1.sendCommand(ON) }
    }
end

Can you publish YOUR rule as it is. Because it should work now

Of course you can get a simple Button in Basic or Classic UI:
sitemap:

Switch item=myItem mappings=[ON="ON!"]

This will draw a Button with the Caption ON!, if pressed it will send the ON command to the item myItem.
You have to take care of the fact, that the button will not be released automatically. Either use a rule

rule "release button"
when
    Item myItem received command ON
then
    myItem.postUpdate(NULL)
end

or bind the item to autoupdate="false":
item:

Switch myItem "My Item" {binding="...",autoupdate="false"}

Still not working… but i have fixed it :smiley: “Item” is missing in “when”

when
    Sonoff_Button received update // Need received update if Data has not changed but button still pressed

Shoud be:

when
  Item Sonoff_Button received update // Need received update if Data has not changed but button still pressed

Now it is working… the full code is:

rule "Button Pressed"
when
    Item Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
    Thread::sleep(100) // Need the sleep to allow for the state to change
    if (Sonoff_Button.state == "6A8CD2") {
        if (S4CH04.state == ON || S4CH04.state == NULL) { S4CH04.sendCommand(OFF) }
        else { S4CH04.sendCommand(ON) }
    }
end

And Item:

//RF Bridge
String Sonoff_Button { mqtt="<[broker:tele/sonoff_rf/RESULT:state:JSONPATH($.RfReceived.Data)]" }

now the next question… I have one more switch in my rf button, that sends another code… what is best practise then?? make another file rule, similar to this one, and with other data, or can I continue in this rule, with another RF code…?

Maybe this code snipplet i use helps you.
I control with a Rf Remote (which sends a different code for every button on it) sonoff device (s):


rule "RF433 switch sonoff and Update RF Switch (Bridge 1)"
when
    Item RfBridge_RfReceive changed
then
if (RfBridge_RfReceive.state == NULL)
    {
    logInfo("RfBridge1.rules", "Item is null, cancelling...")
    return;
    } 
    var rfData = RfBridge_RfReceive.state.toString
    logInfo("rfbridge1.rules", "Received IT Codes: " + rfData)
        switch (rfData) {         
            case "A00A1F":
               {
                publish("broker", "cmnd/sonoff-13D92F/POWER", "ON")
                }
            case "A00A17":
                {
                publish("broker", "cmnd/sonoff-13D92F/POWER", "OFF")
                }
            case "A00A1B":
               {
                publish("broker", "cmnd/sonoff-065CA6/POWER", "ON")
                }
            case "A00A13":
                {
                publish("broker", "cmnd/sonoff-065CA6/POWER", "OFF")
                }
            case "A00A1D":
               {
                publish("broker", "cmnd/sonoff-101AEE/POWER", "ON")
                }
            case "A00A15":
                {
                publish("broker", "cmnd/sonoff-101AEE/POWER", "OFF")
                }                
            case "A00A1E":
               {
                publish("broker", "cmnd/sonoff-5DE6D5/POWER", "ON")
                }
            case "A00A16":
                {
                publish("broker", "cmnd/sonoff-5DE6D5/POWER", "OFF")
                }
        	case "85D5CC":
        	    {
			    Pir433.sendCommand(ON)
			    }                   
            case "150551":
               {
				postUpdate(WohnFluter, ON)
                }
            case "150554":
                {
				postUpdate(WohnFluter, OFF)
                }   
            case "151151":
               {
				postUpdate(SchrankLicht, ON)
                }
            case "151154":
                {
				postUpdate(SchrankLicht, OFF)
                }   
            case "151451":
               {
				postUpdate(SchrankTechni, ON)
                }
            case "151454":
                {
				postUpdate(SchrankTechni, OFF)
                }   
            case "151511":
               {
				postUpdate(Glaskugel, ON)
                }
            case "151514":
                {
				postUpdate(Glaskugel, OFF)
                }   
            case "151541":
               {
				postUpdate(Leselampe, ON)
                }
            case "151544":
                {
				postUpdate(Leselampe, OFF)
                }   
            case "150151":
               {
				postUpdate(SideRechts, ON)
                }
            case "150154":
                {
				postUpdate(SideRechts, OFF)
                }   
            case "151051":
               {
				postUpdate(Salzlampe, ON)
                }
            case "151054":
                {
				postUpdate(Salzlampe, OFF)
                }   
            case "3575C0":
               {
				postUpdate(Schlafzimmer, ON)
                }
            case "35750C":
                {
				postUpdate(Schlafzimmer, OFF)
                }   
    }
 rfData=""
 RfBridge_RfReceive.postUpdate(rfData)
end

Yep!
If you have just another one of two buttons then if then will be enough
More than that it will get confusing and use the case switch

rule "Button Pressed"
when
    Item Sonoff_Button received update // Need received update if Data has not changed but button still pressed
then
    if (Sonoff_Button.state == NULL) return; //Do nothing if NULL
    Thread::sleep(100) // Need the sleep to allow for the state to change
    if (Sonoff_Button.state == "6A8CD2") {
        if (S4CH04.state == ON || S4CH04.state == NULL) { S4CH04.sendCommand(OFF) }
        else { S4CH04.sendCommand(ON) }
    }
    if (Sonoff_Button.state == "6A8CD8") {
        if (otherSwitch.state == ON || otherSwitch.state == NULL) { otherSwitch.sendCommand(OFF) }
        else { otherSwitch.sendCommand(ON) }
    }
end

Hi did you manager to get this to work with MQTT 2.5

Regards

Will this string item work for the MQTT 2?

Not sure what you mean but the binding version should not make a difference

I’m asking because of this thread:

so at the “new MQTT” the items originally should be changed to something that refers to channels as you see at the Sonoff_RF examples.

Paulo