[SOLVED] Close Rollershutters when sun shines using groups

Tags: #<Tag:0x00007f616d35d6a0> #<Tag:0x00007f616d35d5d8>

Hi,

We have various Rollershutters around the house. I am in the process of making a rule that, if the “auto close when sun shines” switch is set to ON and certain criteria are met, the respective members closes. This way, I avoid writing the rule for every shutter. I tried implementing this designe pattern but get stuck on the filter bit. Here is (part of) the items file:

Group gZonAchter
Group gZonAchterSwitch

Rollershutter rolluikZolderRechts "Rolluik [%d %%]" <rollershutter> (gZonAchter)
Rollershutter rolluikZolderLinks  "Rolluik [%d %%]" <rollershutter> (gZonAchter)

Switch rzrZon "Zon stand [MAP(zonstand.map):%s]" <sun> (gZonAchterSwitch)
Switch rzlZon "Zon stand [MAP(zonstand.map):%s]" <sun> (gZonAchterSwitch)

So the Switch should define if the Shutter is in auto closing mode or not and the Rollershutter is the item that needs closing when certain conditions apply.

The rule should be something in the order of:
gZonAchter.members.forEach[ i | gZonAchterSwitch.members.filter [ j | j.state == ON ] sendCommand(DOWN)

Maybe my approach isn’t the right one so any hints/tips/trick in the right direction are appreciated.

As written what you have is syntactically incorrect (sendCommand(DOWN) to what Item?) and it doesn’t make sense what you are trying to do on this line.

As written you are:

  1. for each member of gZoneAchter
    a. get a list of all members of gZoneAchterSwitch that are ON
  2. sendCommand(DOWN) to ???

Put in English, you are getting the list of all members of gZonAchterSwitch that are ON twice but not doing anything with it. You are just getting the list over an over, once for each member of gZonAchter. Once you are done with that you sendCommand to nothing.

If I understand what you are trying to do you have a flag for each Rollershitter. When that Switch is ON you need to close the Rollershutter. If that is what you are trying to do you need Design Pattern: Associated Items so you can do something like:

// Get the flags that are ON
val auto = gZonAchterSwitch.members.filter[ a | a.state == ON]

// For each of the flags that are ON, send DOWN to the corresponding Rollershutter
auto.forEach[ a | 
    val rs = gZonAchter.members.findFirst[ r | r.name == a.name + "_Rollershutter" ]
    rs.sendCommand(DOWN)
]

In words we get a list of all the members of gZonAchterSwitch that are ON. For each member of that list we get the Rollershutter associated with that switch and sendCommand DOWN to that Item.

Hi Rich,

I know the code wasn’t complete. Should have posted all I had but I didn’t get/see how the filter was supposed to work. I needed to filter and then send it to specific members and couldn’t get my head around it.

You did help me in the right direction though so I’ll try this over the upcomming days when I have time amd report back.

I guess the part “_rollershutter” should be the rollershutter item right?

Read the Associated Items posting. The “_Rollershutter” part is taking advantage of the fact that you will be naming your Items so you can construct the name of an associated Item, in this case the Rollershutter, using the name of an Item you have, in this case the switch.

Hi all,

So far I ended up with this code:

                val autoAchter = gZonAchterAuto.members.filter[ a | a.state == 0]
                logInfo(logName, "Debug 13")

                        autoAchter.forEach[ a |
                        val rsAchter = gZonAchter.members.findFirst[ r | r.name == a.name + "_shutter" ]
                                rsAchter.sendCommand(stand_ochtend)
                                logInfo(logName, "Debug 15")

Now, can I implement another filter that checks if nightmode is enabled?
This is (part of) my items file:

Number autoRzr "Rolluik mode [%s]" <automation> (gAuto, gZonAchterAuto, gZolder, gHerstel)
Number autoRzl "Rolluik mode [%s]" <automation> (gAuto, gZonAchterAuto, gZolder, gHerstel)

Rollershutter autoRzr_shutter (gZonAchter)
Rollershutter autoRzl_shutter (gZonAchter)

Switch autoRzr_nacht "rzr [%s]" (gHerstel, gAchterNacht)
Switch autoRzl_nacht "rzl [%s]" (gHerstel, gAchterNacht)

So I am using groups gZonAchterAuto to check if the auto mode is set, gZonAchter to control the shutter (according to Design Pattern: Associated Items) and gAchterNacht to check nightmode (or so I want to…)

I am really struggling with this sort of coding but it works so awesome as I don’t have to write code for every shutter + if I get more shutters, the code doesn’t need any updating :slight_smile:

Thanks in advance!

val rsNacht=   gAchterNacht.members.findFirst[ r | r.name == a.name + "_nacht" ]

Hi Rich,

I still struggle a lot with the double filter. Would you please spend a few minutes helping me?
So far I have:

                val autoAchter = gZonAchterAuto.members.filter[ a | a.state == 0 ]
                logInfo(logName, "Debug 13")

                autoAchter.forEach[ a | 
                val rsNacht = gAchterNacht.members.filter[ n | a.name + "_nacht".state == OFF]
                logInfo(logName, "Debug 14")

                rsNacht.forEach[ n | 
                val rsAchter = gZonAchter.members.findFirst[ r | r.name == a.name + "_shutter" ]
                        //rsAchter.sendCommand(stand_ochtend)
                        logInfo(logName, "Debug 15")
               ]
               ]

It only logs “Debug 13” so far. What I am trying to achieve is:
Filter on all members of gZonAchterAuto that have state 0. Then, look at all members of gAchterNacht with the name-part of the earlier mentioned members + “_nacht”. If that state == OFF, then set the shutter.

Ie. check if autoRzr it’s state is 0. If so, then look at autoRzr_nacht to see if that state is OFF. If that is the case, then set autoRzr_shutter. So it is like a double filter.

Maybe I am thinking to difficult here but I really can’t get my head around it :disappointed_relieved:

Thanks

If you are not seeing any errors in your logs then autoAchter is empty, meaning no members of gZonAchterAuto have the state 0.

Make good use of your debug statements. Instead of “Debug 13” which doesn’t tell you much of anything use

logInfo(logName, "There are " + autoAchter.size + " rollershutters in mode 0")

After a lot of thinking, checking, more reading on this community I ended up with:

        val autoAchter = gZonAchterAuto.members.filter[ a | a.state < 4 && a.state != 1  ]
        logInfo(logName, "There are " + autoAchter.size + " shutters in auto-mode")

        autoAchter.forEach[ a |
        logInfo(logName, "It is " + a.name + " turn to check for nightmode")

                val rsNacht = gAchterNacht.members.findFirst[ n | n.name == a.name + "_nacht" ]
                if(rsNacht.state == OnOffType::OFF) {
                        (a.name + "_shutter").sendCommand(stand_ochtend)
                        logInfo(logName, "Item " + a.name + "_shutter received command")
                }
        ]

Should it help anyone…

cheers!