[openwebnet] adding CEN/CEN+ support to OH3

I almost finished adding CEN support to the OH3 official binding.
Before sumitting for approval I wanted to check with you some design changes that are summarized here.
(CEN+ will be added after, with same design changes)

things

Same configuration as before, no changes here:

bus_cen_scenario_control CEN_scenario "Living Room CEN" [ where="51", buttons="1,4" ]

channels

Channels now end with # instead of _ before the button number:

String iLR_scenario_btn1 "Scenario Button 1" <network> { channel="openwebnet:bus_cen_scenario_control:MyServer:51:button#1" }

Also channels are now trigger channels, which means they trigger events but do not keep a state.
They do not need to be associated to an item.

Possible values for triggered events will be the same as on the BUS, so for CEN:

START_PRESSURE
SHORT_PRESSURE
EXTENDED_PRESSURE
RELEASE_EXTENDED_PRESSURE

these are in fact the same found on the scenario configurations on the BTicino gateway and I think is much better to keep the same events (it also simplifies coding).

rule

Since we have trigger channels now, the syntax for the rule is slightly different:

// long pressure on CEN button will switch off dimmer
rule "CEN dimmer off"
when
    Channel "openwebnet:bus_cen_scenario_control:MyServer:51:button#1" triggered RELEASE_EXTENDED_PRESSURE
then
        sendCommand(iLR_dimmer, OFF)  
end

Any comments on this design?

1 Like

Here it is a version of the binding (based on latest 3.2.0-SNAPSHOT) which includes support for CEN events:

org.openhab.binding.openwebnet-3.2.0-SNAPSHOT_cen_v0.jar.pdf (204.4 KB)

(uninstall the official OH3 binding and add this file renaming it .jar to the addons folder)

2 Likes

Hi Massi,
this is good news! I will definitely try it this week.

I am starting to migrate the OpenHab 2.5 configuration to version 3.1.

I have problems with the openwebnet 3.1 binding … where can I post the questions for that version?
Thanks!

You can post on the main thread about the binding.
Always specify the version your are using and provide logs if you have them already.

Thanks @massi

One question:

I’m running the MH202 with the scenarios, therefore I’m just triggering them via .items file.

following syntax before:

String          RollEGoeffnen                 "Rolläden EG öffnen"               <network>         (gSzenarien)                                            {channel="openwebnet:bus_cen_scenario_control:mybridge:MH202_CEN_scenario:button_8" }

this should look like now:

Bridge openwebnet:bus_gateway:mybridge "MH202" [ host="10.0.1.50", passwd="xxxxxxx", port=20000, discoveryByActivation=false ]
String          RollEGoeffnen                 "Rolläden EG öffnen"               <network>         (gSzenarien)                                            {channel="openwebnet:bus_cen_scenario_control:MH202:51:button#8" }

is the channel line right in the items file?
should be the name MH202 in it like in the things file or the mybridge?

If all is right, I will test,

thanks, Christian

not doing anything… in both variants.

sitemap trigger is still right?

Switch item=RollEGoeffnen label="Rolläden EG öffnen"  mappings=[PRESSED="Start"]

rule is not needed in my case, right?

the channel must contain the name of the thing as defined in the .things file. This is plain OH configuration, please refer to the OH guides.

I do not use sitemaps, but at the moment the virtual activation for CEN is not added yet.
This means you can react to scenario activation events from the BUS, but not start a scenario activation from OH.
It’s not a big change, so I will add it in the following evenings.

Virtual activation will be designed differently: since channels are now trigger channels, activation of a scenario will be through an ACTION to be called from scripts/rules and not by setting the item/channel state. This is the right approach in OH. Of course one can create an item and when clicked start the rule to run the action. I will provide an example.

sorry, wanted to test but i cannot get it work with jython-rules. i use this things-code (no items defined):

bus_cen_scenario_control  Cen_MorgenFeiertag "Cen_MorgenFeiertag" @ "Cen/CenPlus" [ where="10#4#01", buttons="1,2" ]

in dsl this condition works:

when
    Channel "openwebnet:bus_cen_scenario_control:bticino:Cen_MorgenFeiertag:button#1" triggered START_PRESSURE
then...

but in jython when i write this rule:

@when("Channel openwebnet:bus_cen_scenario_control:bticino:Cen_MorgenFeiertag:button#1 triggered START_PRESSURE")

i receive this error when i save the rule:

2021-09-27 19:23:22.331 [WARN ] [jsr223.jython.core.triggers         ] - when: "Channel openwebnet:bus_cen_scenario_control:bticino:Cen_MorgenFeiertag:button#1 triggered" could not be parsed because 'openwebnet:bus_cen_scenario_control:bticino:Cen_MorgenFeiertag:button#1' is not a trigger Channel

2021-09-27 19:23:22.335 [WARN ] [jsr223.jython.core.rules            ] - rule: not creating rule 'Jython test (1_test.py)' due to an invalid trigger definition

i have no idea what i am doing wrong

@bastler thanks! the binding builds its channels dynamically and the trigger type was missing, despite I declared it in the things xml definition. It needs to be added programmatically (from code).
Strangely dsl rule works (that is what I test), while jython rule, probably more strict, doesn’t.

Here is a new snapshot version with the kind TRIGGER corrected. Can you test it again?

org.openhab.binding.openwebnet-3.2.0-SNAPSHOT_cen_v1.jar.pdf (204.5 KB)

you are amazing! thats it, now the jython-rules trigger, thanks a lot!

Thanks @massi ,
I will wait for your feedback to be tested

as far as i could test now i want to give a positive feedback. the channels trigger and i already could switch some cen-commands to the binding. great!

what i did not manage is to create an item that is triggered by the cen. not sure if this is not implemented yet or i am doing sth wrong. i have some items that are members of groups. so i can create rules that trigger if one member of this group changed. of course i could just add all the channes in the “when”-condition, but that are many and would not look very nice :wink:

Thanks Massi I will try and test this week. Just a question on triggers because they are new to me. Is there a way to create a generic rule for each CEN button for example using CASE. Otherwise I guess we have to create an individual rule for each type of button press?

when
Channel "openwebnet:bus_cen_scenario_control:MyServer:51:button#1" triggered
then 
 Channel.state  {
      case "PRESSED": {
      Lt_Masterbed_Walls.sendCommand(OFF)   
      }
      case "RELEASED": {
      }  
     case "PRESSED_EXT": {
     masterbed_tv.sendCommand(OFF)
      }
      case "RELEASED_EXT": {
    }
  }

i code in jython, but i think in dsl it should work like this:

rule "CEN-Test-test_cen"
    when
        Channel "openwebnet:bus_cen_scenario_control:bticino:Cen_Test:button#1" triggered START_PRESSURE
        Channel "openwebnet:bus_cen_scenario_control:bticino:Cen_Test:button#1" triggered SHORT_PRESSURE
    then
        switch(receivedEvent){
            case "START_PRESSURE":{
                logInfo("CEN-Test", "START_PRESSURE triggered")
            }
            case "SHORT_PRESSURE":{
                logInfo("CEN-Test", "SHORT_PRESSURE triggered!")
            }
        }
    end
1 Like

thanks @bastier I will try that

it looks correct, see this specific section of documentation “channel based triggers”:
https://next.openhab.org/docs/configuration/rules-dsl.html#channel-based-triggers

this is bejond my knowledge (very limited!) about how items-groups-channels-rules can interact together. I suggest to post a more general question to the community, not related to openwebnet, maybe with an example

Do you have something to test ready?

I now added CEN virtual pressure actions for rules.
You have to update the jar file:

org.openhab.binding.openwebnet-3.2.0-SNAPSHOT_cen_v2.jar.pdf (208.0 KB)

Here is an example to test CEN virtual pressure from a rule:
(I am not too much expert on rules, it’s just an example to show use of the rule action)

rule "CEN virtual pressure events using rule actions"
/* this rule triggers every minute, then loads the proper action from the
 openwebnet binding and sends on the BUS a sequence of "virtual pressure"
 events for thing: 
   openwebnet:bus_cen_scenario_control:myserver:51
 (a CEN scenario control thing, with address where=51)
 
 Exemple: to send EXTENDED_PRESSURE virtual pressure event from button 3 use this command in the rule:
   cenActions.virtualPress("EXTENDED_PRESSURE", 3)
*/
when
    Time cron "0 * * * * ? *"
then
   val cenActions = getActions("openwebnet","openwebnet:bus_cen_scenario_control:myserver:51")
    if(null === cenActions) {
            logInfo("cenActions", "Actions not found, check thingID")
            return
     }
     //logInfo("cenActions", " " + cenActions)
     cenActions.virtualPress("START_PRESSURE", 3)
     Thread::sleep(500)
     cenActions.virtualPress("EXTENDED_PRESSURE", 3)
     Thread::sleep(500)
     cenActions.virtualPress("EXTENDED_PRESSURE", 3)
     Thread::sleep(500)
     cenActions.virtualPress("EXTENDED_PRESSURE", 3)
     Thread::sleep(500)
     cenActions.virtualPress("RELEASE_EXTENDED_PRESSURE", 3)
end

If this approach works for your installations, I will then move on to add CEN+ support before publishing to the official repository.

Not sure if I get that right.

I just want to trigger (for example) button 8 on the bus to start a scenario stored in the MH202 scenary module to open all shutters in the basement.

item in the new style should be:

String          RollEGoeffnen                 "Rolläden EG öffnen"               <network>         (gSzenarien)                                            {channel="openwebnet:bus_cen_scenario_control:MH202:51:button#8" }

What I need to do now in the rules file?
And how should the items file look like? like the one I’m posted?