Sonoff (tasmota) RF Bridge to item file

There is no such thing as a button item but there is a Switch item
What do you want that “button” to do?

Controle a other sonoff relay device

Ok so you need a String item:

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

And then a rule:

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") {
        // Do what you want
    }
end

I think I can make that… but iam only using rules in paperUI… have never tried the rules in this way…

is it something like that:

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") {
       sendCommand(MyItem, ON)
    }
end

(found in an example, can I then use “toggle” instead of ON og OFF …? (as I remember tasmota understand “toggle”

       MyItem.sendCommand(ON)
if (MyItem.state == ON || MyItem.state == NULL) MyItem.sendCommand(OFF)
else MyItem.sendCommand(ON)

The NULL check is in case your MyItem is not initialized and then we send on OFF command otherwise it would be turned ON by the else clause which may be unsafe.

The || mean or

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…?