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

  • Platform information:
    • Hardware: Raspberry Pi 3B+
    • OS: openhabianpi (newest Version)
    • Java Runtime Environment: no idea
    • openHAB version: openhabianpi (newest Version)

Hello Community, I don’t want you to do my job but I spent a few sleepless nights with my first advanced rule.
Maybe you can give me some hints or assistance.

The parts I were not able to solve by me are masked with (??..??)

Circumstances:

  • openHab
  • EnOcean with dongle and switch (EEP: F6-02)
  • roller shutters Somfy IO + Somfy Tahoma Hub

I have everything set up and running, so I can control these things through my PaperUI!

Fruggy83 (developer of the EnOcean-binding) said things should be possible with a rule/script set up.

What I want:

Press the up-button shortly (DIR1_PRESSED) - two hue lamps on
Press the up-button longer - roller shut open to final position

Press the down-button shortly - two hue lamps off
Press the down-button longer - roller shut down to 85%

Press the down-button longer AND roller shuter is already between 80% and 90% - roller shutter down to final position.

To be honest - I have big problems sending the commands to the roller shuters and the timer events.

import org.openhab.model.script.actions.Timer

var timer = 0

rule "Schalter Schlaf Doppelfunktion"

when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR1_PRESSED"
then
   timer = createTimer(now.millis)

when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR1_RELEASED"
then 
   timer.cancel

if timer < 500 ms 
then 
   hue_0210_001788a7963d_13_color.sendCommand(46,56,50)
   hue_0220_001788a7963d_1_brightness.sendCommand(50)

if timer > 500 ms 
then 
   ??somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control.sendCommand(UP)??

when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR2_PRESSED"
then
   timer = createTimer(now.millis)

when Channel "enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA" triggered "DIR2_RELEASED"
then 
   timer.cancel

if timer < 500 ms 
then 
   hue_0210_001788a7963d_13_color.sendCommand(46,56,0)
   hue_0220_001788a7963d_1_brightness.sendCommand(0)

if timer > 500 ms 
then 
   ??somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control.sendCommand(85%)??
   
if timer > 500 ms and somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control(??between 80% and 90%??)
then 
   somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control.sendCommand(85%)


// EnOcean SWITCH
// enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA triggered DIR1_PRESSED   <- UP Switch
// enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA triggered DIR1_RELEASED  <- UP Switch
// enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA triggered DIR2_PRESSED   <- DOWN Switch
// enocean:rockerSwitch:FT2PVJS5:FEF73B49:rockerswitchA triggered DIR2_RELEASED  <- DOWN Switch
//
// Somfy Roller Shutter
// somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control
// roller shutters (UP, DOWN, STOP control of a roller shutter). IO Homecontrol devices are allowed to set exact position of a shutter (0-100%)
//
// Hue Lights
// hue_0210_001788a7963d_13_color (Lightstrip)
// hue_0220_001788a7963d_1_brightness (lamp)

I rather think createTimer() is not what you think. It creates a scheduled job, and should have a block of code attached to be carried out at a future specified time.
It’s definitely not a stopwatch.

Maybe an approach to look at is to store the value of now when button down, and compare with now after button up.

This suggests that you should be able to use the profile feature to get short/long presses

I’m not familiar with EnOcean at all, but it looks like if you link a rocker switch to an openHAB Rollershutter type Item you pretty much get what you want.

That can be a “dummy” Item unconnected to a real device, and you can have rules listening for commands to it and translating into different commands for a real device.

Yeah, I tried these things, but I only get DIRX_PRESSED and DIRX_RELEASED.

But as I write this, I remember getting other commands while using it as a dimmer switch.

Then I get the commands ON (short up), OFF (short down), INCREASE (long up) and DECREASE (long down)

So you would recommend something like:

when item "switch_test" received command "ON"
then 
hue_0210_001788a7963d_13_color.sendCommand(46,56,50)
hue_0220_001788a7963d_1_brightness.sendCommand(50)

when item "switch_test" received command "INCREASE"
then
somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control.sendCommand(UP)
// I don't know if this will work

when item "switch_test" received command "OFF"
then 
hue_0210_001788a7963d_13_color.sendCommand(46,56,0)
hue_0220_001788a7963d_1_brightness.sendCommand(0)

when item "switch_test" received command "DECREASE"
then
somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control.sendCommand(DOWN)
if 
somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control > 80 or < 90
else somfytahoma:rollershutter:be96c7ed:e4bfe155-0cf2-4b8e-97f0-9a04de637f03:control.sendCommand(85)
// I don't know if I can add this "between" thing.

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.