Rule for the Philips Hue Lightsensor / HomeMatic Weather Station (HmIP-SWO-B) OpenHab 2.0

Hello, I automate my smart home piece by piece and use devices from HomeMatic, homematic IP Philips Hue, Xiaomi and so on.

A few weeks ago I installed OpenHab 2.0 on my Raspberry 4 and it works fine. On the Raspberry there is a RaspBee (Conbee) for controlling the Zigbee devices. It is integrated into Openhab 2.0 via the binding deconZ.

So far it has not been possible for me to create a functioning rule that gets the lighting in the front yard to work with the light sensor from Homematic (weather station) or Philips Hue.

I imagine that from a value of e.g. <40 lux the lighting is switched on and dimmed to 10%. The rule should also include that when motion is detected, the light is dimmed to 100%, after 3 minutes to 50% and after 5 minutes to 10%.

Is that possible? Can somebody help me with it?

Sensor:

Number  OU_Balcony_Wetterstation1ILLUMINATION   "Helligkeit (Lux) Wetterstation"          <sun_clouds>    (OU_Balcony, gWeather)   {channel="homematic:HmIP-SWO-B:3014F711A0001F98A99A4659:0017D8A99540C7:1#ILLUMINATION"}


Number:Illuminance   BewegungsmelderLichtsensorLightlux      "Helligkeit (Lux)"      <sun_clouds>    (OU_FrontYard, gWeather)             {channel="deconz:lightsensor:homeserver:00178801064417b8020400:lightlux"}
Dimmer gHue_Balconyspot1_Brightness                "BalkonSpot 1"          (gHue_Balconyspot1)           ["Lighting"]           {channel="hue:0220:00212E062123:14:brightness"}

Dimmer gHue_Balconyspot2_Brightness                 "BalkonSpot 2"          (gHue_Balconyspot2)          ["Lighting"]            {channel="hue:0220:00212E062123:15:brightness"}

Dimmer gHue_GarageSpot1_Brightness            "GarageSpot 1"          (gHue_GarageSpot1)          ["Lighting"]    {channel="hue:0220:00212E062123:11:brightness"}

Dimmer gHue_GarageSpot2_Brightness            "Garage Spot 2"          (gHue_GarageSpot2)        ["Lighting"]      {channel="hue:0220:00212E062123:12:brightness"}

Dimmer gHue_GarageSpot3_Brightness            "Garage Spot 3"          (gHue_GarageSpot3)      ["Lighting"]        {channel="hue:0220:00212E062123:13:brightness"}

Dimmer gHue_GarageWandlampe_Brightness        "Garage Wandlampe"    (gHue_GarageWandlampe)    ["Lighting"]          {channel="hue:0100:00212E062123:10:brightness"}

Dimmer gHue_SchuppenWandlampe1_Brightness     "Schuppen Wandlampe 1"          (gHue_SchuppenWandlampe1)     ["Lighting"]       {channel="hue:0100:00212E062123:19:brightness"}

Dimmer   gHue_SchuppenWandlampe2_Brightness     "Schuppen Wandlampe 2"          (gHue_SchuppenWandlampe2)   [ "Lighting" ]         {channel="hue:0100:00212E062123:20:brightness"}

Switch OU_FrontYard_LichtVorgartensteuerung1STATE            "Licht Fallrohr"                      <outdoorlight>    (OU_FrontYard, gLight)      ["Lighting"]          {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:1#STATE"}

Switch OU_FrontYard_LichtVorgartensteuerung2STATE            "Licht Stein links"                   <outdoorlight>    (OU_FrontYard, gLight)      ["Lighting"]          {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:2#STATE"}

Switch OU_FrontYard_LichtVorgartensteuerung3STATE            "Licht Stein rechts"                  <outdoorlight>    (OU_FrontYard, gLight)      ["Lighting"]          {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:3#STATE"}

Switch OU_FrontYard_LichtVorgartensteuerung4STATE            "Licht Dachrinne"                     <outdoorlight>    (OU_FrontYard, gLight)      ["Lighting"]          {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:4#STATE"}

Dimmer OU_FrontYard_LichtHausfassade4LEVEL                   "Licht Hausfassade"                       <slider>      (OU_FrontYard, gLight)      ["Lighting"]          {channel="homematic:HmIP-BDT:3014F711A0001F98A99A4659:0008DA49A431FC:4#LEVEL"}

Greetings
Steffen

Please use code fences (it’s possible to edit written postings).

1 Like

Hm… not that type of code fences… :wink:

Number OU_Balcony_Wetterstation1ILLUMINATION "Helligkeit (Lux) Wetterstation" <sun_clouds> (OU_Balcony, gWeather) {channel="homematic:HmIP-SWO-B:3014F711A0001F98A99A4659:0017D8A99540C7:1#ILLUMINATION"}
Number:Illuminance BewegungsmelderLichtsensorLightlux "Helligkeit (Lux)" <sun_clouds> (OU_FrontYard, gWeather) {channel="deconz:lightsensor:homeserver:00178801064417b8020400:lightlux"}
Dimmer gHue_Balconyspot1_Brightness "BalkonSpot 1" (gHue_Balconyspot1) ["Lighting"] {channel="hue:0220:00212E062123:14:brightness"}
Dimmer gHue_Balconyspot2_Brightness "BalkonSpot 2" (gHue_Balconyspot2) ["Lighting"] {channel="hue:0220:00212E062123:15:brightness"}
Dimmer gHue_GarageSpot1_Brightness "GarageSpot 1" (gHue_GarageSpot1) ["Lighting"] {channel="hue:0220:00212E062123:11:brightness"}
Dimmer gHue_GarageSpot2_Brightness "Garage Spot 2" (gHue_GarageSpot2) ["Lighting"] {channel="hue:0220:00212E062123:12:brightness"}
Dimmer gHue_GarageSpot3_Brightness "Garage Spot 3" (gHue_GarageSpot3) ["Lighting"] {channel="hue:0220:00212E062123:13:brightness"}
Dimmer gHue_GarageWandlampe_Brightness "Garage Wandlampe" (gHue_GarageWandlampe) ["Lighting"] {channel="hue:0100:00212E062123:10:brightness"}
Dimmer gHue_SchuppenWandlampe1_Brightness "Schuppen Wandlampe 1" (gHue_SchuppenWandlampe1) ["Lighting"] {channel="hue:0100:00212E062123:19:brightness"}
Dimmer gHue_SchuppenWandlampe2_Brightness "Schuppen Wandlampe 2" (gHue_SchuppenWandlampe2) [ "Lighting" ] {channel="hue:0100:00212E062123:20:brightness"}
Switch OU_FrontYard_LichtVorgartensteuerung1STATE "Licht Fallrohr" <outdoorlight> (OU_FrontYard, gLight) ["Lighting"] {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:1#STATE"}
Switch OU_FrontYard_LichtVorgartensteuerung2STATE "Licht Stein links" <outdoorlight> (OU_FrontYard, gLight) ["Lighting"] {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:2#STATE"}
Switch OU_FrontYard_LichtVorgartensteuerung3STATE "Licht Stein rechts" <outdoorlight> (OU_FrontYard, gLight) ["Lighting"] {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:3#STATE"}
Switch OU_FrontYard_LichtVorgartensteuerung4STATE "Licht Dachrinne" <outdoorlight> (OU_FrontYard, gLight) ["Lighting"] {channel="homematic:HM-LC-Sw4-DR:3014F711A0001F98A99A4659:PEQ1836228:4#STATE"}
Dimmer OU_FrontYard_LichtHausfassade4LEVEL "Licht Hausfassade" <slider> (OU_FrontYard, gLight) ["Lighting"] {channel="homematic:HmIP-BDT:3014F711A0001F98A99A4659:0008DA49A431FC:4#LEVEL"}

Ok thank you for your advice Udo, perhaps you can get me some hints for the rules, so that I figure it out by myself :slight_smile:

I tried this rule just for on/off, but it doesnt work at all :expressionless:

rule "Vorgartenbeleuchtung EIN"
when 
    Item OU_Balcony_Wetterstation1ILLUMINATION.state <25
then 
    Item OU_FrontYard_LichtVorgartensteuerung1STATE.sendcommand(on)
    Item OU_FrontYard_LichtVorgartensteuerung2STATE.sendcommand(on)
    Item OU_FrontYard_LichtVorgartensteuerung3STATE.sendcommand(on)
    Item OU_FrontYard_LichtVorgartensteuerung4STATE.sendcommand(on)
    Item OU_FrontYard_LichtHausfassade4LEVEL.sendcommand(100%)
    Item gHue_Balconyspot1_Brightness.sendcommand(100%)
    Item gHue_Balconyspot2_Brightness.sendcommand(100%)
    Item gHue_GarageSpot1_Brightness.sendcommand(100%)
    Item gHue_GarageSpot2_Brightness.sendcommand(100%)
    Item gHue_GarageSpot3_Brightness.sendcommand(100%)
    Item gHue_GarageWandlampe_Brightness.sendcommand(100%)
    Item gHue_SchuppenWandlampe1_Brightness.sendcommand(100%)
    Item gHue_SchuppenWandlampe2_Brightness.sendcommand(100%)
end


rule "Vorgartenbeleuchtung AUS"
when 
    Item OU_Balcony_Wetterstation1ILLUMINATION.state >60
then 
    Item OU_FrontYard_LichtVorgartensteuerung1STATE.sendcommand(off)
    Item OU_FrontYard_LichtVorgartensteuerung2STATE.sendcommand(off)
    Item OU_FrontYard_LichtVorgartensteuerung3STATE.sendcommand(off)
    Item OU_FrontYard_LichtVorgartensteuerung4STATE.sendcommand(off)
    Item OU_FrontYard_LichtHausfassade4LEVEL.sendcommand(0%)
    Item gHue_Balconyspot1_Brightness.sendcommand(0%)
    Item gHue_Balconyspot2_Brightness.sendcommand(0%)
    Item gHue_GarageSpot1_Brightness.sendcommand(0%)
    Item gHue_GarageSpot2_Brightness.sendcommand(0%)
    Item gHue_GarageSpot3_Brightness.sendcommand(0%)
    Item gHue_GarageWandlampe_Brightness.sendcommand(0%)
    Item gHue_SchuppenWandlampe1_Brightness.sendcommand(0%)
    Item gHue_SchuppenWandlampe2_Brightness.sendcommand(0%)
end

Rules consist of two parts, these are the when-part and the then-part.
The then-part contains the code to be executed.
The when-part contains a list of triggers. A trigger is always a moment, not a state or a boolean expression.
You can’t trigger on a greater than or less than.
But of course you can trigger on changed.
Next thing is, this is not the state (although the state is what changes) but the item itself. So the trigger part is written

Item OU_Balcony_Wetterstation1ILLUMINATION changed

You can’t restrict this to a level, but of course it’s possible to do this in the execute-part of the rule.

Now to the then-part:
The word Item is only part of the when-part of the rule, this is to be deleted.
Command as well as state is written in upper case, so it’s not on and off but ON and OFF. A PercentType number must not be written with a %.
The method (as well as the corresponding action) is called sendCommand() (upper case C). Upper/lower case is essential in openHAB, and each letter counts.
As a conditional branch will always take effect only to the next command, we have to build a block of commands. That is done with curly brackets.

So, all in all you will need one rule (not two!) to do the job:

rule "Vorgartenbeleuchtung"
when 
    Item OU_Balcony_Wetterstation1ILLUMINATION changed
then 
    if(!(OU_Balcony_Wetterstation1ILLUMINATION.state instanceof Number))      // falls keine gültige Zahl
        return;                                                               // Abbruch der Rule
    if((OU_Balcony_Wetterstation1ILLUMINATION.state as Number) < 25) {        // falls dunkel
        OU_FrontYard_LichtVorgartensteuerung1STATE.sendCommand(ON)
        OU_FrontYard_LichtVorgartensteuerung2STATE.sendCommand(ON)
        OU_FrontYard_LichtVorgartensteuerung3STATE.sendCommand(ON)
        OU_FrontYard_LichtVorgartensteuerung4STATE.sendCommand(ON)
        OU_FrontYard_LichtHausfassade4LEVEL.sendCommand(100)
        gHue_Balconyspot1_Brightness.sendCommand(100)
        gHue_Balconyspot2_Brightness.sendCommand(100)
        gHue_GarageSpot1_Brightness.sendCommand(100)
        gHue_GarageSpot2_Brightness.sendCommand(100)
        gHue_GarageSpot3_Brightness.sendCommand(100)
        gHue_GarageWandlampe_Brightness.sendCommand(100)
        gHue_SchuppenWandlampe1_Brightness.sendCommand(100)
        gHue_SchuppenWandlampe2_Brightness.sendCommand(100)
    } else if((OU_Balcony_Wetterstation1ILLUMINATION.state as Number) > 60) { // falls hell
        OU_FrontYard_LichtVorgartensteuerung1STATE.sendCommand(OFF)
        OU_FrontYard_LichtVorgartensteuerung2STATE.sendCommand(OFF)
        OU_FrontYard_LichtVorgartensteuerung3STATE.sendCommand(OFF)
        OU_FrontYard_LichtVorgartensteuerung4STATE.sendCommand(OFF)
        OU_FrontYard_LichtHausfassade4LEVEL.sendCommand(0)
        gHue_Balconyspot1_Brightness.sendCommand(0)
        gHue_Balconyspot2_Brightness.sendCommand(0)
        gHue_GarageSpot1_Brightness.sendCommand(0)
        gHue_GarageSpot2_Brightness.sendCommand(0)
        gHue_GarageSpot3_Brightness.sendCommand(0)
        gHue_GarageWandlampe_Brightness.sendCommand(0)
        gHue_SchuppenWandlampe1_Brightness.sendCommand(0)
        gHue_SchuppenWandlampe2_Brightness.sendCommand(0)
    }
end

Please be aware that it would be far more easy to do this with a group Item (all items which shall be switched put together in one group - an item can be put in more than one group) Then the rule would be:

rule "Vorgartenbeleuchtung"
when 
    Item OU_Balcony_Wetterstation1ILLUMINATION changed
then 
    if(!(OU_Balcony_Wetterstation1ILLUMINATION.state instanceof Number))      // falls keine gültige Zahl
        return;                                                               // Abbruch der Rule
    val cCommand = NULL                                                       // default
    if((OU_Balcony_Wetterstation1ILLUMINATION.state as Number) < 25) {        // falls dunkel
        cCommand = ON                                                         // Befehl ON
    } else if((OU_Balcony_Wetterstation1ILLUMINATION.state as Number) > 60) { // falls hell
        cCommand = OFF                                                        // Befehl OFF
    }
    if(cCommand != NULL)                                                      // falls Befehl gesetzt
        gMyGardenGroup.sendCommand(cCommand)                                  // an Gruppe senden
end

Please note that a sendCommand(ON/OFF) to a dimmer item will result in a sendCommand(100/0), openHAB is capable to do this automatically. :slight_smile:

Thank you so much, it works great! And many thanks to your adivice :slight_smile:

I had forgotten to post my presence sensor item. So would it be possible to dimm the light up to 100%, for e.g. 5 minutes if it recognize presence and when the time passed by, that it will come back to 10%?

Switch               BewegungsmelderBewegungPresence         "Bewegung"              <motion>        (OU_FrontYard, gWeather)             {channel="deconz:presencesensor:homeserver:00178801064417b8020406:presence"}

I think the solution with the group wouldnt work for me fine, because I dont want to have 100% all the time. If I unterstood it right, the ON Command will trigger the lights on with the value of 100% or am I wrong?

Yes, of course. If you want to use another level for all dimmers, another solution would be something like this:

rule "Vorgartenbeleuchtung"
when 
    Item OU_Balcony_Wetterstation1ILLUMINATION changed
then 
    if(!(OU_Balcony_Wetterstation1ILLUMINATION.state instanceof Number))      // falls keine gültige Zahl
        return;                                                               // Abbruch der Rule
    val cCommand = NULL                                                       // default
    if((OU_Balcony_Wetterstation1ILLUMINATION.state as Number) < 25) {        // falls dunkel
        val Number nLevel = 60                                                // Level für Dimmer (hier fix...)
        gMyGardenGroup.members.filter[i|i instanceof SwitchItem].forEach[j|   // alle Switch Items in der Gruppe
            j.sendCommand(ON)
        ]
        gMyGardenGroup.members.filter[i|i instanceof DimmerItem].forEach[j|   // alle Dimmer Items in der Gruppe
            j.sendCommand(nLevel)
        ]
    } else if((OU_Balcony_Wetterstation1ILLUMINATION.state as Number) > 60)   // falls hell
        gMyGardenGroup.sendCommand(OFF)                                       // Befehl OFF
end

Ok i tried to make a rule for the presence sensor, will it work or is it trash? :sweat_smile:

At this rule I made a group for my items in the Frontyard called gFrontyard. I don’t intend to switch off the lamps all the time, but rather to dim them from 100% back to 10% each time after the motion detector were activated
.

rule "Bewegungsmelder mit Timeout"
when
    Item BewegungsmelderBewegungPresence received command ON             
then 
    tBewegung?.cancel                                                 
    if(gFrontYard.state != ON) gFrontYard.sendCommand(100)           
    tBewegung = createTimer(now.plusSeconds(60), [ |                
        if(gFrontYard.state != OFF) gFrontYard.sendCommand(10)      
        tBewegung = null                                           
    ])
end

or this one?

rule "Bewegungsmelder mit Timeout"
when
    Item BewegungsmelderBewegungPresence received command ON                                      
then 
    tBewegung?.cancel                                                                          
    if(OU_FrontYard_LichtHausfassade4LEVEL.state != ON) gFrontYard.sendCommand(100)           
    tBewegung = createTimer(now.plusSeconds(60), [ |                                         
        if(OU_FrontYard_LichtHausfassade4LEVEL.state != OFF) OU_FrontYard_LichtHausfassade4LEVEL.sendCommand(10)
        if(gHue_Balconyspot1_Brightness.state != OFF) gHue_Balconyspot1_Brightness.sendCommand(10)
        if(gHue_Balconyspot2_Brightness.state != OFF) gHue_Balconyspot2_Brightness.sendCommand(10)
        if(gHue_GarageSpot1_Brightness.state != OFF) gHue_GarageSpot1_Brightness.sendCommand(10)
        if(gHue_GarageSpot2_Brightness.state != OFF) gHue_GarageSpot2_Brightness.sendCommand(10)
        if(gHue_GarageSpot3_Brightness.state != OFF) gHue_GarageSpot3_Brightness.sendCommand(10)
        if(gHue_GarageWandlampe_Brightness.state != OFF) gHue_GarageWandlampe_Brightness.sendCommand(10) 
        if(gHue_SchuppenWandlampe1_Brightness.state != OFF) gHue_SchuppenWandlampe1_Brightness.sendCommand(10) 
        if(gHue_SchuppenWandlampe2_Brightness.state != OFF) gHue_SchuppenWandlampe2_Brightness.sendCommand(10)      
        tBewegung = null                                                                    
    ])
end

If all items are dimmers, the first rule will work, but nos as intended :wink: If the group Item is of type dimmer, too, its state will always be of type Number, so it will never be ON or OFF but only 0 to 100, so the sendCommand is always executed.
Another point is, it’s the state of the group Item, not every single state of every item. This is better done via a filter:

rule "Bewegungsmelder mit Timeout"
when
    Item BewegungsmelderBewegungPresence received command ON             
then 
    tBewegung?.cancel                                                 
    gFrontYard.members.filter[i.i.state != 100].forEach[j|j.sendCommand(100)]
    tBewegung = createTimer(now.plusSeconds(60), [ |                
        gFrontYard.members.filter[i|i.state != 0].forEach[j|j.sendCommand(10)]
//        tBewegung = null // you don't need this line of code
    ])
end