Sonoff dual to control shutters

I have openHAB running on my Pi and I am playing with the demo set up under basicui
I have 7 electric shutters and I will be controlling them each with a sonoff dual R2 flashed with tasmota.
I have read, copied and fettled my way to a working set up complete with group close and open.
My only sticking point is getting the icons to correctly reflect the state of the shutters.
This is made awkward for the following simple reason: The up and down action of the shutters is controlled by a switched live. POWER1 and POWER2 on the sonoff are set up in interlock mode to prevent both being active and ruining the motor. The ON command issent to POWER1 for UP and POWER2 for DOWN. Both relays have PulseTime set to allow the relay to turn off after the required amount of time.
Therin lies my problem. If I set the RollerShutter icon to autoupdate=false, they show as closed when the ON command is sent to the relay POWER1 but return to open when mqtt reports that the relay has been returned to the OFF position.
When I set autoupdate=true, the shutter icons work correctly in single mode but do not update the group icons. In the group, the count updates but reverts to 0 when the relay turns back to OFF after its PulseTime and the icons do not change.
Now for some code - just 2 relays showing. Iā€™m new to this so please forgive any posting errors.
ITEMS:

/* Shutters*/
Switch mqttSonoff6_1 "SOnOff 6-1" (Shutter1) {mqtt=">[mosquitto:lounge1/cmnd/POWER1:command:*:${command}],<[mosquitto:lounge1/stat/POWER1:state:REGEX((.*))]"}
Switch mqttSonoff6_2 "SOnOff 6-2" (Shutter2) {mqtt=">[mosquitto:lounge1/cmnd/POWER2:command:*:${command}],<[mosquitto:lounge1/stat/POWER2:state:REGEX((.*))]"}
String mqttSonoff6lwt "lounge1" { mqtt="<[mosquitto:lounge1/tele/LWT:state:default]" }
String mqttSonoff6state "SOnOff 6 [JSONPATH($.Wifi.RSSI):%s %%]" { mqtt="<[mosquitto:lounge1/tele/STATE:state:default]" }
Rollershutter Sonoff6 "lounge1" (GF_Kitchen) { autoupdate="true" }

Switch mqttSonoff7_1 "SOnOff 7-1 [%s]" (Shutter1) {mqtt=">[mosquitto:lounge2/cmnd/POWER1:command:*:${command}],<[mosquitto:lounge2/stat/POWER1:state:REGEX((.*))]"}
Switch mqttSonoff7_2 "SOnOff 7-2 [%s]" (Shutter2) {mqtt=">[mosquitto:lounge2/cmnd/POWER2:command:*:${command}],<[mosquitto:lounge2/stat/POWER2:state:REGEX((.*))]"}
String mqttSonoff7lwt "SOnOff 7 [%s]" { mqtt="<[mosquitto:lounge2/tele/LWT:state:default]" }
String mqttSonoff7state "SOnOff 7 [JSONPATH($.Wifi.RSSI):%s %%]" { mqtt="<[mosquitto:lounge2/tele/STATE:state:default]" }
Rollershutter Sonoff7 "lounge2 [%d%%]" (GF_Kitchen) { autoupdate="true" }
/* active groups */
Group:Switch:OR(ON, OFF)        Shutter1      "All Shutters [(%d)]"
Group:Switch:OR(ON, OFF)        Shutter2      "All Shutters [(%d)]"

SITEMAP

	Frame label="Master Shutters Control" {
			Switch item=Shutter1 icon="blinds" mappings=[ON="All Open"]
			Switch item=Shutter2 icon="blinds" mappings=[ON="All Closed"]
    } 

RULES

rule "Sonnoff6 2"
when
    Item Sonoff6 received command
then
        switch (receivedCommand) {
            case UP: mqttSonoff6_1.sendCommand(ON)
            case DOWN:mqttSonoff6_2.sendCommand(ON)
            case STOP: {
                if(mqttSonoff6_1.state == ON) mqttSonoff6_1.sendCommand(OFF)
                if(mqttSonoff6_2.state == ON) mqttSonoff6_2.sendCommand(OFF)
            }
        }
end
rule "Sonnoff7 2"
when
    Item Sonoff7 received command
then
//    logDebug("sonoff1","7-2: received command: {}",receivedCommand)

        switch (receivedCommand) {
            case UP: mqttSonoff7_1.sendCommand(ON)
            case DOWN:mqttSonoff7_2.sendCommand(ON)
            case STOP: {
                if(mqttSonoff7_1.state == ON) mqttSonoff7_1.sendCommand(OFF)
                if(mqttSonoff7_2.state == ON) mqttSonoff7_2.sendCommand(OFF)
            }
        }
end

Thanks very much.

Rollershutter Sonoff6 "lounge1" (GF_Kitchen) { autoupdate="true" }

The autoupdate will do nothing because there is no binding on the item.

Change your items to:

Group:Rollershutter Shutters
Rollershutter Sonoff6 "lounge1" (GF_Kitchen, Shutters) { autoupdate="true" }

Your sitemap:

	Frame label="Master Shutters Control" {
			Switch item=Shutters icon="blinds" mappings=[UP="All Open"]
			Switch item=Shutters icon="blinds" mappings=[DOWN="All Closed"]
    } 

You are repeating your code a lot, have a look at:

and

Thank you so much for the links. I hope to learn as much as possible but sometimes become overwhelmed with the material available. I have implemented your changes and understand what they have achieved - thank you.
I am still hoping to display in the groups all open/closed how many shutters are open and how many are closed according to the individual switchesā€™ last position. Is this even possible in my type of set up?

Thatā€™s not quite true. Whether or not there is any binding on an Item, if autoupdate=ā€œtrueā€ (or defaulted) then any command sent to the Item will trigger autoupdate to guess what the effect will be on Item state, and issue an update to that effect.

So for example, if you command ON to a Switch with no binding it will shortly be updated to ON.

1 Like

Yes but not straightforward. You will need proxy items

Hi!
One thing, if You have standard tubular roller shutter motor. You will end up with relay contacts welded. Sonoff has poor quality relays with 10A current. In roller shutter, to start the motor are used big capacitors, spike with back voltage is around 1000V. For this kind of motors You should try to find relays with 16A on 250V AC with AgSnO2 contacts, like Finder or Relpol. Iā€™m Using RELPOL RM85-3011-35-1024.
Sorry for little Off top and my English :).

2 Likes

Thanks. I am delving into proxy items to see if I can work out how to manage it. I think if I could have the Group on and Group off switches on the same page as the actual switches it would remove the need for what I was trying to do as I would be able to see how many were open or shut.
I have managed to get the above in action but the Group open and Group close switches do not update the Blinds icons in the individual switches. I will keep trying.

OK Vincent. I have a working version of what I wanted to achieve and I would really appreciate it if you could cast your eye over it to see if there is anything you disapprove of. It now does what I wanted. My last sticking point is how to remove the 0 or 100 next to the shutter switch and the (0) or (2) next to the all open/closed switches.

ITEMS

Switch mqttSonoff6_1 "SOnOff 6-1" {mqtt=">[mosquitto:lounge1/cmnd/POWER1:command:*:${command}],<[mosquitto:lounge1/stat/POWER1:state:REGEX((.*))]"}
Switch mqttSonoff6_2 "SOnOff 6-2" {mqtt=">[mosquitto:lounge1/cmnd/POWER2:command:*:${command}],<[mosquitto:lounge1/stat/POWER2:state:REGEX((.*))]"}
Rollershutter Sonoff6 "lounge1" (GF_Kitchen, Shutters) { autoupdate="true" }

Switch mqttSonoff7_1 "SOnOff 7-1" {mqtt=">[mosquitto:lounge2/cmnd/POWER1:command:*:${command}],<[mosquitto:lounge2/stat/POWER1:state:REGEX((.*))]"}
Switch mqttSonoff7_2 "SOnOff 7-2" {mqtt=">[mosquitto:lounge2/cmnd/POWER2:command:*:${command}],<[mosquitto:lounge2/stat/POWER2:state:REGEX((.*))]"}
Rollershutter Sonoff7 "lounge2" (GF_Kitchen, Shutters) { autoupdate="true" }

Group:Switch:OR(ON, OFF) Shutters "All Shutters"

SITEMAP

	Frame label="Electric Shutters" {
      Switch item=Sonoff6
      Switch item=Sonoff7
    }
	Frame label="Master Shutters Control" {
			Switch item=Shutters icon="blinds" mappings=[ON="All Open"]
			Switch item=Shutters icon="blinds" mappings=[OFF="All Closed"]      
    }

RULES

rule "Sonnoff6 2"
when
    Item Sonoff6 received command
then
        switch (receivedCommand) {
            case UP: mqttSonoff6_1.sendCommand(ON)
            case DOWN:mqttSonoff6_2.sendCommand(ON)
            case ON:Sonoff6.sendCommand(UP)
            case OFF:Sonoff6.sendCommand(DOWN)
            case STOP: {
                if(mqttSonoff6_1.state == ON) mqttSonoff6_1.sendCommand(OFF)
                if(mqttSonoff6_2.state == ON) mqttSonoff6_2.sendCommand(OFF)
            }
        }
end
rule "Sonnoff7 2"
when
    Item Sonoff7 received command
then
        switch (receivedCommand) {
            case UP: mqttSonoff7_1.sendCommand(ON)
            case DOWN:mqttSonoff7_2.sendCommand(ON)
            case ON:Sonoff7.sendCommand(UP)
            case OFF:Sonoff7.sendCommand(DOWN)
            case STOP: {
                if(mqttSonoff7_1.state == ON) mqttSonoff7_1.sendCommand(OFF)
                if(mqttSonoff7_2.state == ON) mqttSonoff7_2.sendCommand(OFF)
            }
        }
end

Many thanks for the pointer. I did wonder about the quality of the relays. Iā€™ll add it to my ā€˜to doā€™ list

Iā€™ll review your code tonight.
For the values that you donā€™t want to see, change the label:
"lounge1 []"

Thanks for that perfect nugget. Us beginners sometimes forget that you have to specify ā€˜nothingā€™ rather than just relying on providing nothing.