Rule - automatic should be stopped when roller shutters are moved manually

Hello everyone,

I need help in implementing a rule.

I have a KNX system, which is integrated in openHAB and controls my shutters.

I have written a rule that controls the shutters according to the position of the sun. For this there is an item that checks the conditions and an item that turns the automatic on and off.

If both items are ON, the shutters are driven automatically.

Now my wish is that the “Automatic ON/OFF Item” switches to OFF when a roller shutter is controlled manually.

I could also realize this by setting the item to OFF as soon as a shutter item changes.

Unfortunately, it happens now that the KNX actuator sends the status only after the roller shutters have been moved automatically and thus the automatic system switches itself off.

Does anyone have any other solution how I can control the automatic shutdown of the automatic?

Greeting, jopenhuber

when 
        Item Azimut changed
then
        if      (Azimut.state > 70 && 
                Azimut.state < 165 && 
                Clouds.state < 90 && 
                Temp_Max_Today.state > 23 && 
                Temp_Min_Tomorrow.state < 18 && 
                now.getHourOfDay() >7 && now.getHourOfDay() <18) {
                        sendCommand(Sommer_Bedingungen_Schlaf_Bad, ON)
                }
        else if (Azimut.state > 165 &&     
                 Temp_Max_Today.state < 30 && 
                 Temp_Min_Tomorrow.state < 18 && 
                 now.getHourOfDay() >7 && now.getHourOfDay() <18) {
                        sendCommand(Sommer_Bedingungen_Schlaf_Bad, OFF) 
                 }
        else 
                postUpdate(Sommer_Bedingungen_Schlaf_Bad, NULL)
end
rule "Automatik-Unterbrechung Schlaf und Bad"
when
        Item FF_Bedroom_Shutter changed or
        Item FF_Bathroom_Shutter changed or
        Item Sommer_Schlaf_Bad changed
then
        if (Sommer_Bedingungen_Schlaf_Bad.state != NULL &&
            Sommer_Schlaf_Bad_Auto.state == ON) {
                sendCommand(Sommer_Schlaf_Bad_Auto, OFF)
                }
end

You appear to saying that openHAB cannot see buttons being pressed, and neither is openHAB informed when the shutters move in response to manual buttons.
openHAB cannot know about manual actions then?

You’ll need to change these external conditions in some way.
Why doesn’t the shutter report new position over KNX?
Can you monitor motor current perhaps?

The KNX wall switches do not send any status. So I can’t see if a key has been pressed.

The shutters send their status, but only after they have reached the end position. So I have a time delay and I would like to avoid creating a timer that turns the automatic back on after the shutter has run.

Perhaps I’m confused about what you are trying to achieve.

You want to set some Item when somebody manually operates the shutters. You’ll use that Item to inhibit auto operations, but that doesn’t matter yet.

The only way you have to detect a manual operation, is a new position report afterwards, yes?
So when openHAB gets a report, it will need to remember if that was expected from an auto command, or it is unexpected.
You could use a binary flag variable - set it when you issue every OH command. When an update arrives, test if expected or not to control your “manual” Item before unsetting the flag.

Personally I think I’d do something similar but with a timer, might be more reliable. Start a timer at every OH command so as to create a 'window’s of time for the expected response. Any responses outside of that window indicate a manual operation.

So let me get this right you want to run it in automatic mode unless it is in manual mode and you want it to automaticly change when you don’t recive an input into openhab?

Yes, that is correct.

What do you mean with “don’t recive an input into openhab”?

You could create another switch item to track what mode each of you shutters are in?

I have added another switch that is ON for 30 seconds when driving automatically. After that it goes back to OFF.

The automatic switch may only switch off when this item is set to OFF. But for this I had to add a thread::sleep(1000) so that the second rule checks the correct status of the item.

That works for me. Quite a lot of code lines, but it works.

///Schlaf und Bad

//In this section I define whether the position of the sun, weather conditions and the times are correct.

rule "Automatik-Bedingungen Schlaf und Bad"
when 
 Item Azimut changed
then
 if (Azimut.state > 70 && 
 Azimut.state < 165 && 
 Clouds.state < 90 && 
 Temp_Max_Today.state > 23 && 
 Temp_Min_Tomorrow.state < 18 && 
 now.getHourOfDay() >7 && now.getHourOfDay() <18) {
 sendCommand(Sommer_Bedingungen_Schlaf_Bad, ON)
 }
 else if (Azimut.state > 165 && 
 Temp_Max_Today.state < 30 && 
 Temp_Min_Tomorrow.state < 18 && 
 now.getHourOfDay() >7 && now.getHourOfDay() <18) {
 sendCommand(Sommer_Bedingungen_Schlaf_Bad, OFF) 
 }
 else 
 postUpdate(Sommer_Bedingungen_Schlaf_Bad, NULL)
end

// Here the actual automatic driving of the shutters takes place.

rule "Sommer Schlaf und Bad Automatik"
when
Item Azimut changed 
then
 if (Sommer_Bedingungen_Schlaf_Bad.state == ON && 
 Sommer_Schlaf_Bad_Auto.state == ON){
 if (FF_Bedroom_Shutter.state != 100 || FF_Bathroom_Shutter.state != 100) {
 sendCommand(FF_Bedroom_Shutter, DOWN)
 sendCommand(FF_Bathroom_Shutter, DOWN)
 sendCommand(Sommer_Schlaf_Bad_automove, ON)
 createTimer(now.plusSeconds(30)) [|
 sendCommand(Sommer_Schlaf_Bad_automove, OFF)]
 logInfo("Rollo", "Schlaf/Bad auf Position")
 } 
 }
 else if (Sommer_Bedingungen_Schlaf_Bad.state == OFF && 
 Sommer_Schlaf_Bad_Auto.state == ON) {
 if (FF_Bedroom_Shutter.state != 0 || FF_Bathroom_Shutter.state != 0) {
 sendCommand(FF_Bedroom_Shutter, UP)
 sendCommand(FF_Bathroom_Shutter, UP)
 sendCommand(Sommer_Schlaf_Bad_automove, ON)
 createTimer(now.plusSeconds(30)) [|
 sendCommand(Sommer_Schlaf_Bad_automove, OFF)]
 logInfo("Rollo", "Schlaf/Bad RAUF")
 } 
 }
end

// Here you define when the automatic is switched off when the shutters are operated manually.

rule "Automatik-Unterbrechung Schlaf und Bad"
when
 Item FF_Bedroom_Shutter changed or
 Item FF_Bathroom_Shutter changed or
 Item Sommer_Schlaf_Bad changed
then
 Thread::sleep(1000)
 if (Sommer_Bedingungen_Schlaf_Bad.state != NULL &&
 Sommer_Schlaf_Bad_Auto.state == ON &&
 Sommer_Schlaf_Bad_automove == OFF) {
 sendCommand(Sommer_Schlaf_Bad_Auto, OFF)
 }
end

Note that if auto events happen again within the 30 secs period, things might get weird with multiple off-timers.

You could use the expire binding to automatically set this Item OFF again, so long as you always want a fixed time.

Or you can keep a reference to your timer, and use the timer’s existence as the actual flag instead of an Item

// global variable
var Timer autoMotion = null

// rule issuing auto commands
   ...
   autoMotion?.cancel   // kill existing timer, if any
      // create 30 sec timer
   autoMotion = createTimer (now.plusSeconds(30)) [ |
      logInfo("Rollo", "auto move allowance expired")
      autoMotion = null   // clear the flag
   ]
   ...

// rule to detect roller movements
   ...
   if ( autoMotion === null ) {
      // unexpected manual event
   } else {
      // expected auto move result
   }

I don’t see why? Are your Items in fact updating immediately in response to auto commands? You might want to disable autoupdate for them if that is the case. That would ensure that only “real” updates take place.

Thanks for the hint. I will solve it with the expire-binding.

Thread:sleep(1000) I need, because

sendCommand(Sommer_Schlaf_Bad_automove, ON)

is checked at the same time as the verification rule for the automatic shutdown. Apparently the second rule still registers the old status. This is actually only a fraction of a second.

What do you mean by autoupdate? Do you mean for KNX? Where can I configure that?

Explanation for autoupdate (it does sound like this is what you need)

Thanks for the link. I just read through everything and it was very interesting. I was able to apply it directly to a few items (garage door etc.).

In my previously described case it doesn’t help, because the autoupdate would be more helpful here. My rule, which is supposed to detect if the parameters for switching off the automatic are present, reads the status “too fast”. And this is still the old status. If I would deactivate autoupdate, the new “correct” status would take even longer and the rule would even more so, assume the wrong status.