[SOLVED] First Advanced Rule - EnOcean rocker switch / roller shutter / hue

I guess so. Why not exploit the features that do what you want, instead of reinventing.

You do have to careful with getting the syntax right though, case sensitive etc.

Every rule MUST have a unique name. (system uses that to tell them apart)

You must use the case the documents specify

Item states that are not strings (like a switch ON) should not be quoted. “ON” is a string and not the same thing.

Likewise, switch_test is presumably a Dimmer type Item of yours, but “switch_test” is just a string

Every rule must have an end

rule "my on testing rule"
when
   Item switch_test received command ON
then
   // do stuff
end

rule "my next rule"
...

Hi @carmagician,

I do not know how your Somfy rollershutters work, but if I send an UP command to my EnOcean rollershutters followed by another UP, they will just STOP. That is the reason why I did not recommend to use the dimmer profile.

Best regards
Daniel

No, it won’t work. Use an Item.

Yes, i will have to check that when I have have physical control over my system again.

Okay, should definitively have chosen an easier advanced rule for the first time. Thank you so much for your great support here!!

Hi @carmagician,

what about these rules

var Number pressDIR1Timestamp
var Number pressDIR2Timestamp

rule "FT55 UP Pressed"
when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR1_PRESSED"
then
   pressDIR1Timestamp= now.millis
end

rule "FT55 UP Released"
when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR1_RELEASED"
then
   if(now.millis - pressDIR1Timestamp> 500) {
       // Long PRESS
       rollershutterItem.sendCommand(UP)
   } else {
      // Short PRESS
      hueItemColor.sendCommand(46,56,50)
      hueItemBrightness.sendCommand(50)
   }
end

rule "FT55 DOWN Pressed"
when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR2_PRESSED"
then
   pressDIR2Timestamp= now.millis
end

rule "FT55 DOWN Released"
when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR2_RELEASED"
then
   if(now.millis - pressDIR2Timestamp> 500) {
       // Long PRESS
       if(rollerShutter.state > 80 && rollershutter.state < 90) {
             rollershutter.sendCommand(DOWN)
       } else {
             rollershutter.sendCommand(85)
       }
   } else {
      // Short PRESS
      hueItem.sendCommand(OFF)
   }
end

I have not tested this rule :wink:

Best regards
Daniel

1 Like

Oh, I will test this.
You take the timestamps. This is brilliant, I have never thought about this - to be honest.

Is there any way I could gift you a coffee?

Only thing which which does not work correctly is the control of the lightstrip, which seams to be a „global“ problem.
I took it out of the code for now - I think i can figure it out by myself.

Really big thanks! It works like a charm!!! Thank you so much. It is nice that an open source and free system has these much possibilities and there is such a nice community which gives so much support.
Thank you!!

I have to dig up this one more time. Thanks to your example I was able to set up a lot of rules on my own - thanks for that.

I kept struggling with a special switch at my home trying to set up this “move as long as button is pushed”.

Short Button UP and DOWN was not a big deal at all, i used the dimmer-profile, because i thought that i have the needed triggers.

I wanted to set up a rule which sends the shutter down, when the command “decreasing” is sent, but only as long as DIR2 is pressed. The log shows no errors when saving the rule, only when triggering the rule.

Error:

Rule 'links manuell down': The name 'DIR2_PRESSED' cannot be resolved to an item or type; line 23, column 64, length 12

Code:

rule "links manuell down"
when
    Item S_Wohn_Jal_links received command DECREASE
then 
    if (enocean_rockerSwitch_FT2PVJS5_FEF73B6E_rockerswitchA = DIR2_PRESSED) 
    Wohn_Jalousie.sendCommand(DOWN)
    else
    Wohn_Jalousie.sendCommand(STOP)
end

I even tried to set it up the rocker as a channel:

rule "links manuell down"
when
    Item S_Wohn_Jal_links received command DECREASE
then 
    if Channel "enocean_rockerSwitch_FT2PVJS5_FEF73B6E_rockerswitchA" triggered "DIR2_PRESSED" 
    Wohn_Jalousie.sendCommand(DOWN)
    else
    Wohn_Jalousie.sendCommand(STOP)
end

Seems I make a huge mistake while thinking about it.

Thanks in advance :slight_smile:

Greets
Matthias

That one’s easy to dismiss - "when this instantaneous event and that instantaneous event at the same time … " - you simply can’t have rules that work like that. Grasp this and it will make future rules easier, I promise :grinning:

Okay, to the first rule -

What is enocean_rockerSwitch_FT2PVJS5_FEF73B6E_rockerswitchA ?
I guess it is an Item.
Item is an object with all sorts of properties - name, label, etc.
I guess you’re actually interested in its state?
enocean_rockerSwitch_FT2PVJS5_FEF73B6E_rockerswitchA.state

x = y
means set x equal to y
Within an if() statement you don’t usually want to make things equal.
Perhaps you want to test for equality? That’s different
x == y
returns true or false

So next, what is DIR2_PRESSED ? It’s not an Item of yours I suppose, nor does it seem to be a variable you’ve already defined. It’s not one of the predefined states we might expect in openHAB - ON, OFF, OPEN etc.
Remember the system has to try and guess what you mean here, working through the list of things it knows about.

I think here you need to find out what type of Item you are trying to compare the state of, and what values that state may take up.

Okay, the log normally shows

enocean:rockerSwitch:FT2PVJS5:FEF73B6E:rockerswitchA triggered DIR2_PRESSED

and as far as I know this is a channel. And all it triggers is

DIR1_PRESSED
DIR1_RELEASED
DIR2_PRESSED
DIR2_RELEASED

I checked the log:

[vent.ChannelTriggeredEvent] - enocean:rockerSwitch:FT2PVJS5:FEF73B6E:rockerswitchA triggered DIR2_PRESSED
[vent.ItemStateChangedEvent] - enocean_rockerSwitch_FT2PVJS5_FEF73B6E_receivingState changed from Rssi 68, repeated 0 to Rssi 61, repeated 0
[ome.event.ItemCommandEvent] - Item 'S_Wohn_Jal_links' received command DECREASE
[ome.event.ItemCommandEvent] - Item 'S_Wohn_Jal_links' received command DECREASE
[ome.event.ItemCommandEvent] - Item 'S_Wohn_Jal_links' received command DECREASE
[ome.event.ItemCommandEvent] - Item 'S_Wohn_Jal_links' received command DECREASE
[ome.event.ItemCommandEvent] - Item 'S_Wohn_Jal_links' received command DECREASE
[ome.event.ItemCommandEvent] - Item 'S_Wohn_Jal_links' received command DECREASE
[vent.ChannelTriggeredEvent] - enocean:rockerSwitch:FT2PVJS5:FEF73B6E:rockerswitchA triggered DIR2_RELEASED

So i tought about sendCommand(DOWN) till the button is released, all other options with it/while/for I found around here start working after the button is released because the rule has to determine how long the button was pressed.

Because the rockerSwitch is a channel i thought this might work.

I thought about setting a sendCommand(STOP) rule when either DIR is released but after a short press the DIR is released to, so the shutter moves for a small amount of time and stops then.

Hi @carmagician,

additionally to @rossko57 hints, you have to consider the kind of channel/item. There are State and Event channels. The first one hold a state like ON/OFF/UP/DOWN, the later do not hold a state but just emit events. The rockerSwitch channel is an event channel, so you cannot check its state like

if (enocean_rockerSwitch_FT2PVJS5_FEF73B6E_rockerswitchA == DIR2_PRESSED)

Try the following

rule "Move"
when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B6E:rockerswitchA" triggered "DIR2_PRESSED"
then
   Wohn_Jalousie.sendCommand(DOWN)
end

rule "Stop"
when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B6E:rockerswitchA" triggered "DIR2_RELEASED"
then
   Wohn_Jalousie.sendCommand(STOP)
end

Is there any way I could gift you a coffee?

Thanks a lot, you find a link in my repo

Best regards
Daniel

Yes, this will surely work!
But, as I said a few posts earlier i used parts of the old rules to let the shutters go down and up automatically by short presses.
If I use your rules it will interfere with my “short press” rules, doesn’t it? That’s why i didn’t try it that way.

The former intention was to reproduce the behavior of a dimmer. So when pressing the rockerswitchA short, it will send DOWN and directly afterwards the command STOP, right?

Found out you also accept paypal, nice, you will here from me next week :slight_smile:

Greets
Matthias

Hi Matthias @carmagician,

sorry I was not aware that you want to set these rules both on the same FT55. So you want to achieve the following with your FT55:

  • Short press => just move in one direction
  • Long press => start moving and after release stop moving
  • Press => move, release => stop independent of time between press and release
  • Do you want to do this on different roller shutters or on the same?

I have not slept so much this night, so I am a little bit slow today :wink:

Best regards
Daniel

Perhaps that requirement could be rewritten as -

When first pressed, start shutter moving to fully (open/closed)
If button released with a short time, do nothing else.
If button released after a longer time, stop the shutter.

You might need to work out what to do if the button is released after the shutter is already at the end.

This is correct!

No. There is no need to do this. These switches have SwitchA and SwitchB, as there are no more than to roller shutters per room. I will assign only one shutter to one switch.

This could be a possibility, but if i measure the time doesn’t that mean the roller shutter will only move after the button is released?

You can measure time, start or stop things, just as you please. You write the rules to suit. Try it and see, that costs nothing.

Hi,
I am new to OH3 and just playing with the same szenarios. I have OH3 on a Raspberry, Fibaro RS3s, Eltako and similar (PEHA) enocean switches, and outside blinds. So far, everything inluding lamella control works just fine (after figuring out how to get the enocean things to work).

Now I have some basic rules to control the blinds. Essentially these are based on reacting to the DIRx_PRESSED and DIRx_RELEASED events triggered by the enocean buttons.

But what I can’ figure out is how to get the state (not the position) of my blinds, so that I can create rules that e.g. send an UP command when a blind is not moving (which state is that?), but a STOP commmand in case the blind is currently moving for the same button pressed.

And one, probably really stupid, question: I can’t find out how I can write these nice advanced rules with varibales etc. in OH3? All I can do in OH3 is use the UX to “click together” a rule, and view (adapt?) it in the code tab.

You can’t from the basic RollerShutter Item, only position.
Your device may supply the moving/stopped info separately, that you could link to another partner Item. But most do not.

Usually the best you can do is guess, because of the device limitations. There’s more than one way to do that.

At simplest, set something to “running” at every up/down/position command and set it back to “stopped” after a fixed time that allows for the longest possible movement.
If a STOP command arrives, cancel timer and set “stopped” immediately.
That can be refined by using current position (if available) when a command arrives to calculate a variable maximum run time.

You’re probably looking for the UI rule action to be a script.