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%.
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
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.
Thank you so much, it works great! And many thanks to your adivice
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%?
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?
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
If all items are dimmers, the first rule will work, but nos as intended 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