[SOLVED] Sonoff T1 2 gang tasmota integration

Hi all!

I want to integrate Sonoff T1 2 gang in one switch.
Trying the code, but it is not working, can anyone tell me why?

sitemap:

Switch item=ebedlo_12 mappings=[on1="1", on2="4"] icon="light"

items:

String ebedlo_12 "Ebédlő" (mL,LR,gLight)

rules:

rule "EBEDLO"
when Item ebedlo_12 received command
then switch (receivedCommand)
{
	case "on1": { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER1:command:*:default],
                            <[raspberrypi:stat/ebedlo_k/POWER1:state:default]" }
    case "on2": { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER2:command:*:default],
                            <[raspberrypi:stat/ebedlo_k/POWER2:state:default]" }
}
end

Thanks for help!

You have to define items to switch the switch.

Switch sonoffT1_1 "Channel 1 [%s]" { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER1:command:*:default], <[raspberrypi:stat/ebedlo_k/POWER1:state:default]" }
Switch sonoffT1_2 "Channel 2 [%s]" { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER2:command:*:default], <[raspberrypi:stat/ebedlo_k/POWER2:state:default]" }

Now use another rule:

rule "EBEDLO"
when
    Item ebedlo_12 received command
then
    switch (receivedCommand) {
	case "on1": sonoffT1_1.sendCommand(ON)
        case "on2": sonoffT1_2.sendCommand(ON)
    }
end

Hi!

Thanks!
I tried it, but I can’t power off the lamps, just power on working.

Sure, as there is no off command defined yet :slight_smile:

In fact, you won’t need other items or the rule at all, just the two items sonoffT1_1 and sonoffT1_2, just link them to Switch widgets in your sitemap.

I realize that :slight_smile:

Can you give me some code? Sorry I am a little bit newbie…

In the sitemap, just use:

Switch item=sonoffT1_1
Switch item=sonoffT1_2

It’s OK, but I want only one line in my sitemap with two button switch (picture in my first post), if it is possible.

My plan: First button turn on and off 1 spot, and second button turn on and off 4 spot.

Ah, I see. Then use the rule:

Number ebedlo_12 "Ebédlő" <light> (mL,LR,gLight)
Switch sonoffT1_1 "Channel 1 [%s]" { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER1:command:*:default], <[raspberrypi:stat/ebedlo_k/POWER1:state:default]" }
Switch sonoffT1_2 "Channel 2 [%s]" { mqtt=">[raspberrypi:cmnd/ebedlo_k/POWER2:command:*:default], <[raspberrypi:stat/ebedlo_k/POWER2:state:default]" }
Switch item=ebedlo_12 mappings=[1="ON1", 2="OFF1", 3="ON2", 4="OFF2"] 
rule "EBEDLO"
when
    Item ebedlo_12 received command
then
    switch (receivedCommand) {
	case 1 : sonoffT1_1.sendCommand(ON)
	case 2 : sonoffT1_1.sendCommand(OFF)
        case 3 : sonoffT1_2.sendCommand(ON)
        case 4 : sonoffT1_2.sendCommand(OFF)
    }
end

In this code I have four button, is this possible, to only two buttons shows? One press turn on second press turn off, and the second swich is the same?

Sure. There is possibly some trouble.
Let’s try this:
Change the number item:

Number ebedlo_12 "Ebédlő" <light> (mL,LR,gLight) { autoupdate="false" }

The sitemap:

Switch item=ebedlo_12 mappings=[1="1", 2="2"] 

the rule:

rule "EBEDLO"
when
    Item ebedlo_12 received command
then
    switch (receivedCommand) {
	case 1 : sonoffT1_1.sendCommand(if(sonoffT1_1.state != ON) ON else OFF)
	case 2 : sonoffT1_2.sendCommand(if(sonoffT1_2.state != ON) ON else OFF)
    }
end

Of course you don’t have any information about the actual status. An option for this:
change the rule to

rule "EBEDLO"
when
    Item ebedlo_12 received command
then
    var Number status = 0
    switch (receivedCommand) {
	case 4 : sonoffT1_1.sendCommand(if(sonoffT1_1.state != ON) ON else OFF)
	case 5 : sonoffT1_2.sendCommand(if(sonoffT1_2.state != ON) ON else OFF)
    }
    Thread::sleep(300)                       // give openHAB some time...
    if(sonoffT1_1.state == ON) status += 1
    if(sonoffT1_2.state == ON) status += 2
    ebedlo_12.postUpdate(status)
end

and finally, in the sitemap:

Switch item=ebedlo_12 label="SW1:OFF SW2:OFF" mappings=[4="1", 5="2"] visibility=[ebedlo_12==0]
Switch item=ebedlo_12 label="SW1:ON  SW2:OFF" mappings=[4="1", 5="2"] visibility=[ebedlo_12==1]
Switch item=ebedlo_12 label="SW1:OFF SW2:ON"  mappings=[4="1", 5="2"] visibility=[ebedlo_12==2]
Switch item=ebedlo_12 label="SW1:ON  SW2:ON"  mappings=[4="1", 5="2"] visibility=[ebedlo_12==3]

So, the status is in the label itself, therefor we have to use visibility to switch between different labels. :slight_smile: As we need numbers 0 to 3 for status, we now need other numbers (4 and 5) to send the command.

Hi! Thanks, it’s working!

I never figure out without your help :slight_smile: