One RF code to change state of other sonoff

Hi i have a new problem :wink:
i bought RF Switch connect it to openmqttgateway and here is scenario :wink:
Thng :
Type switch : kosiarkaRF [ stateTopic=“home/OpenMQTTGateway/433toMQTT”, transformationPattern=“JSONPATH:$.value” ]

received value is: 13564930

and now (i think need a rule) i need when kosiarkaRF received code (all time same one code 13564930) send command to turn on or off other sonoff lets say commandTopic=“cmnd/touch_/POWER1”
so if touch_ is on command will send off and if its off comannd will turn it on
but i dont know how to do it :confused:

i tested with :
rule “test”
Item rf_code received update
val mqttActions = getActions(“mqtt”,“mqtt:broker:MyMQTTBroker”)
var status = getThingStatusInfo(“rf_code”).getStatus.toString()
logInfo(“RF_CODE”, status)

if (status == ‘13564930’) {
{ mqttActions.publishMQTT(“cmnd/touch_/POWER1”,“ON”) }


but without success just to turn it on :frowning:

Did you understand the Idea of channels and Items?

SImply use a String Channel instead of Switch (Switch is only ON or OFF)

Type string : kosiarkaRF [ stateTopic="home/OpenMQTTGateway/433toMQTT", transformationPattern="JSONPATH:$.value" ]

and add another Channel

Type switch : touch_ch1 "Touch" [ commandTopic="cmnd/touch_/POWER1", stateTopic="stat/touch_/POWER1" ]

for the Sonoff module to switch.

Link this channel to a String Item - let’s name it rf_code -
and another link to the second channel, now to a Switch Item - named Touch_ch1Item.

Now use this rule:

rule "test"
    Item rf_code received update
    var status = rf_code.state.toString
    logInfo("test","RF_CODE: {}", status)
    if (status == "13564930") 
        Touch_ch1Item.sendCommand(if(Touch_ch1Item.state == OFF) ON else OFF)

The Channel will receive the code and will update the Item. The Item update will trigger the rule.
The rule will send ON or OFF to the other Item, depending on the current state of the Item. (This is: toggle the Item)

1 Like

thx. i was wrong with item type.