Rolllershutter-Status (UP, DOWN, STOP) store in items

Hello,

I want the status of an rollershutter UP/DOWN/STOP store in items or variables.
The reason for saving to items is so that I can then save and restore them to mapDB. This should not be the case with variables created in the rule or processed there.

However, I also want to work with these items (UP / DOWN / STOP) in the form of integers.
For example, I want only one shutter to move at a time and the others to wait or be in a queue.

Example:
Shutter living room gets command “UP” (variable A = 1)
Shutter kitchen also gets the command “UP” (Variable B =1)

In the rule I would like to query the direction of the shutters in an if, elseif query, for example, and then move them one after the other.

I’ve been searching the internet for a few hours now, trying to pick out the individual pieces, but not yet with full success.

Below I have inserted an excerpt:

items:
Rollershutter Rollershutter_living_room
Number Rollershutter_living_room1

rules:
var Rollershutter_living_room1 = (Rollershutter_living_room.state as Number)

rule “Rollershutter living room”
when
Item Rollershutter_living_room received command
then
switch(receivedCommand.toString.toUpperCase){
case “UP”: {
Rollershutter_living_room.postUpdate(1)
}
}

I would be very grateful if someone could help me. Thank you in advance for this.

Greeting
Tobi

Is this what you are looking for?

UP,DOWN,STOP aren’t states but commands.
Rollershutter items are of PercentType so why don’t you just use them like that ?
If your actuators allow for this you can also send them to XX % via rules.

1 Like

Hello Bruce
Hello Markus

Thank you very much for your answers. :slight_smile:

I had already dealt with “Transformation Services”, but I don’t want to “transfer” commands but store the commands in variables.

It should be from the shutter 1:
UP command in variable A (1 pressed / 0 after reset when processing is done)
DOWN command in variable B (1 pressed / 0 after reset when processing is done)
STOP command in variable C (1 pressed / 0 after reset when processing is done)

Markus you are right that I would like to drive the roller shutter later with percent defaults, however the variables are to serve first that I avoid a simultaneous operation of roller shutters. It should be an interlock among each other.

In the next step I would like to query in a variable the percentage or the number, which is given to the shutter. With this the runtime for the UP or DOWN command is then calculated after the “interlocking check”.

Can you maybe give me a hint how I could save and process the states of the commands (UP / DOWN / STOP) via items?

Thanks again for your answers and thank you very much for your support and efforts!

Greetings
Tobi

Again: Commands are events - they don’t have a state. There is no such thing as a state “moving up”.
So I believe your concept is broken. At least I don’t understand it. You’re making us victim to the XY problem.

1 Like

Hi Tobi

What would be the reason to do so? I have several rollershutters in use and I never came to a conclusion that such “state” keep would be needed.

Regards
Stefan

To suggest the beginnings of a different approach -

If you want to have only one of many shutters moving at a time, you will need to know if and when a shutter is moving.

You cannot tell that from the last command - maybe that was UP, but you don’t know when that movement completed. You cannot tell that from the position - so it’s 67% right now, that doesn’t tell you if its moving or not.
So abandon “remembering” last command, it’s useless.

You have to take time into consideration.
Say you create a virtual Item, Shutter21_Moving
By rules, you might set that “true” when Shutter21 gets an UP or DOWN command.
You might set it “false” if Shutter21 gets a STOP command.
But that’s not enough to tell you when an UP has finished and movement has stopped.

There are several methods you could use to work that out.
The simplest is just to use a fixed time - if any shutter movement always completes after 40 seconds, you can have a rule that starts a 40s timer whenever an UP/DOWN command is issued, and then sets Shutter21_Moving to “false”.
If your shutters have working position indicator %, there are more sophisticated ways to do it.

Hello Markus,

I would like to set a variable or an item in the cases “UP”, “DOWN”, “STOP”. I understood that I can not use the commands, but I thought I can “sneak in” a variable in the Rule and the Case of the shutter and have it set.

rossko57 got it almost exactly right and already preempted my “timing”.

“There are several methods you could use to work that out.
The simplest is just to use a fixed time - if any shutter movement always completes after 40 seconds, you can have a rule that starts a 40s timer whenever an UP/DOWN command is issued, and then sets Shutter21_Moving to “false”.”

The only thing left to think about is how I save, for example, an UP or DOWN command of a 2nd shutter until the 1st shutter has finished moving.

I would like to explain to Stefan briefly why this is important to me:
Until now, I did not care whether shutters run simultaneously, but there are manufacturer specifications, which prohibit e.g. simultaneous driving. This has to do with the capacitor in the shutter motor, whose capacity is reduced by parallel connection of shutters and the motor is more heavily loaded or can damage.

Thank you very much for your messages and rossko57 for the right approach which I would like to pursue further.
Can you briefly show me how I can include Shutter21_Moving?

Once again my biggest thanks for your support!

Greetings
Tobi

I’m not writing it for you. Everything you need to know is in the docs and these forums somewhere.
So,my suggestion was to use a dummy or virtual Item as the indicator of shutter-moving, that makes it easy to share among different rules.
You have many shutters which each need an indicator, so you’d probably want to use associated Items naming conventions and Groups to manage many similar Items.
Using the naming and Groups you can write one rule to handle many shutters and the associated indcator.
Your first step might be to write a rule that listens out for the start of a movement, so that’s probably going to need to be triggered from a command to the shutter, work out what the associated virtual Item is, and set that to ON or whatever.
Master that first step, and the second step will be how to turn off your virtual Item. Your choice there, but will almost certainly involve timers.

This is much more difficult. Don’t underestimate the complexity of your overall task. You will learn lots if you follow this through!

You could maintain a queue of tasks to-do, each timer a shutter movement ends you look to see if any tasks are left. You can implement fairly random sequences with that method.

Or you might use a state machine that steps through a pre-designed sequence, do-this, do-that, waiting at each step for the condition to move on to the next step.

Choices here will be about your preferences.

Hello rossko57,

Thank you very much for your more than quick reply!

I would never expect or demand that someone writes my programme for me. I just sometimes need some food for thought in the right direction.

My question was only about how the virtual element can be set using the shutter commands, as this was the original question.

I am now trying to implement your suggestion.

Thank you very much again and I’ll let you know when I’ve finished the first part.

Greetings
Tobi

Hello rossko57,

now I have a working program that stores the commands “UP”/“DOWN”/“STOP” in “number items” and passes them to the shutter control “rule”, which implements the interlock query and control.

In the next step, I will try to save the percentage setting as well and pass it to the control rule.
Do you have a suggestion or tip for me?

Perhaps someone would like to make an effort and check my code for possible areas of improvement. It could be that I could better implement the proper use of the timers.

Many thanks in advance for this and below is the code:

ITEMS:
Rollershutter Rollladen_Gaestezimmer  "Gaestezimmer"  (gGaestezimmer, Rolllaeden, gSpeichern)     

Rollershutter Rollladen_Schlafzimmer  "Schlafzimmer"  (gSchlafzimmer, Rolllaeden, gSpeichern)     

Rollershutter Rollladen_Buero  "Buero"  (gBuero, Rolllaeden, gSpeichern)   

Number GZ_Rollladen_UP
Number GZ_Rollladen_DOWN
Number GZ_Rollladen_STOP

Number SZ_Rollladen_UP
Number SZ_Rollladen_DOWN
Number SZ_Rollladen_STOP

Number Buero_Rollladen_UP
Number Buero_Rollladen_DOWN
Number Buero_Rollladen_STOP
______________________________________________
RULE:
rule "Rollladen Gästezimmer HOCH/RUNTER/STOP"
when
    Item Rollladen_Gaestezimmer received command
then
        switch(receivedCommand.toString.toUpperCase){
            case "UP": {
             GZ_Rollladen_UP.postUpdate(1)
           }
            case "STOP": {
             GZ_Rollladen_UP.postUpdate(0)
             GZ_Rollladen_DOWN.postUpdate(0)
             sendCommand (Arduino , "<Rollladen_GZ_STOP,>".toString)
             GZ_Rollladen_STOP.postUpdate(1)
            }
            case "DOWN": {
             GZ_Rollladen_DOWN.postUpdate(1)          
           }      
        } 
end

rule "Rollladen Schlafzimmer HOCH/RUNTER/STOP"
when
    Item Rollladen_Schlafzimmer received command
then
    switch(receivedCommand.toString.toUpperCase){
        case "UP": {
           SZ_Rollladen_UP.postUpdate(1) 
        }
        case "STOP": {
           SZ_Rollladen_UP.postUpdate(0)
           SZ_Rollladen_DOWN.postUpdate(0)
           sendCommand (Arduino , "<Rollladen_SZ_STOP,>".toString)
           SZ_Rollladen_STOP.postUpdate(1) 
           }
        case "DOWN": {
           SZ_Rollladen_DOWN.postUpdate(1)  
        }      
    }
end


rule "Rollladen Buero HOCH/RUNTER/STOP"
when
    Item Rollladen_Buero received command
then
    switch(receivedCommand.toString.toUpperCase){
        case "UP": {
           Buero_Rollladen_UP.postUpdate(1) 
        }
        case "STOP": {
           Buero_Rollladen_UP.postUpdate(0)
           Buero_Rollladen_DOWN.postUpdate(0) 
           sendCommand (Arduino , "<Rollladen_Buero_STOP,>".toString)
           Buero_Rollladen_STOP.postUpdate(1)
           }
       case "DOWN": {
           Buero_Rollladen_DOWN.postUpdate(1) 
        }      
    }
end

_______________________________________________

rule "Steuerung Rolllaeden HOCH"
when
    Item GZ_Rollladen_UP received update or
    Item GZ_Rollladen_UP changed or

    Item SZ_Rollladen_UP received update or
    Item SZ_Rollladen_UP changed or

    Item Buero_Rollladen_UP received update or
    Item Buero_Rollladen_UP changed or

    Time cron "0 0/1 * 1/1 * ? *"  //every Minute 
then
    if (GZ_Rollladen_UP.state == 1 && GZ_Rollladen_STOP.state == 1 && SZ_Rollladen_STOP.state == 1 && Buero_Rollladen_STOP.state == 1){
            GZ_Rollladen_STOP.postUpdate(0)
             sendCommand (Arduino , "<Rollladen_GZ_UP,>".toString)
             createTimer(now.plusSeconds(40)) [| 
                GZ_Rollladen_UP.postUpdate(0) 
                sendCommand(Rollladen_Gaestezimmer, STOP) 
             ]
    }

createTimer(now.plusSeconds(2)) [|
    if (SZ_Rollladen_UP.state == 1 && GZ_Rollladen_STOP.state == 1 && SZ_Rollladen_STOP.state == 1 && Buero_Rollladen_STOP.state == 1){
            SZ_Rollladen_STOP.postUpdate(0)
             sendCommand (Arduino , "<Rollladen_SZ_UP,>".toString)
             createTimer(now.plusSeconds(40)) [| 
                SZ_Rollladen_UP.postUpdate(0) 
                sendCommand(Rollladen_Schlafzimmer, STOP) 
             ]
    }]

createTimer(now.plusSeconds(4)) [|
    if (Buero_Rollladen_UP.state == 1 && GZ_Rollladen_STOP.state == 1 && SZ_Rollladen_STOP.state == 1 && Buero_Rollladen_STOP.state == 1){
            Buero_Rollladen_STOP.postUpdate(0)
             sendCommand (Arduino , "<Rollladen_Buero_UP,>".toString)
             createTimer(now.plusSeconds(40)) [| 
                Buero_Rollladen_UP.postUpdate(0) 
                sendCommand(Rollladen_Buero, STOP) 
             ]
    }]
end 


rule "Steuerung Rolllaeden RUNTER"
when
    Item GZ_Rollladen_DOWN received update or
    Item GZ_Rollladen_DOWN changed or

    Item SZ_Rollladen_DOWN received update or
    Item SZ_Rollladen_DOWN changed or

    Item Buero_Rollladen_DOWN received update or
    Item Buero_Rollladen_DOWN changed or

    Time cron "0 0/2 * 1/1 * ? *"  //every 2 Minute 
then
    if (GZ_Rollladen_DOWN.state == 1 && GZ_Rollladen_STOP.state == 1 && SZ_Rollladen_STOP.state == 1 && Buero_Rollladen_STOP.state == 1){
            GZ_Rollladen_STOP.postUpdate(0)
             sendCommand (Arduino , "<Rollladen_GZ_DOWN,>".toString)
            createTimer(now.plusSeconds(40)) [| 
            GZ_Rollladen_DOWN.postUpdate(0)
            sendCommand(Rollladen_Gaestezimmer, STOP)
             ]
    }

createTimer(now.plusSeconds(2)) [|
    if (SZ_Rollladen_DOWN.state == 1 && GZ_Rollladen_STOP.state == 1 && SZ_Rollladen_STOP.state == 1 && Buero_Rollladen_STOP.state == 1){
           SZ_Rollladen_STOP.postUpdate(0)
             sendCommand (Arduino , "<Rollladen_SZ_DOWN,>".toString)
            createTimer(now.plusSeconds(40)) [| 
            SZ_Rollladen_DOWN.postUpdate(0)
            sendCommand(Rollladen_Schlafzimmer, STOP)
             ]
    } ]

createTimer(now.plusSeconds(4)) [|
    if (Buero_Rollladen_DOWN.state == 1 && GZ_Rollladen_STOP.state == 1 &&     SZ_Rollladen_STOP.state == 1 && Buero_Rollladen_STOP.state == 1){
            Buero_Rollladen_STOP.postUpdate(0)
             sendCommand (Arduino , "<Rollladen_Buero_DOWN,>".toString)
             createTimer(now.plusSeconds(40)) [| 
                Buero_Rollladen_DOWN.postUpdate(0) 
                sendCommand(Rollladen_Buero, STOP) 
             ]
    }]
end

Greetings
Tobi