Hello all,
I’ve been trying for days now to get a rule working but it just won’t fire.
What i have now is coming from openhab wiki etc.
rule "Lamp bij binnenkomst"
when
Item Motion_Living_Motion changed to 1
then
logInfo("Verlichting", "Controleer lichtsterkte")
//var Number Lichtsterkte = Motion_Living_Lux.state as DecimalType
//logInfo("Verlichting", "Lichtsterkte = " + Lichtsterkte)
if(Motion_Living_Lux.state < 200) {
if(Dimmer_RGBWLiving_Red.state == OFF) {
logInfo("Verlichting", "Verlichting aanzetten")
sendCommand(Dimmer_RGBWLiving_Red, 35)
sendCommand(Dimmer_RGBWLiving_Green, 100)
}
} else {
if(Dimmer_RGBWLiving_Red.state == ON) {
logInfo("Verlichting", "Verlichting woonkamer is al aan")
}
}
end
I See the logInfo “Controleer Lichtsterkte” but the rest doesn’t show.
When i uncomment the var and loginfo i also see current lux in the log.
Any help would be really appreciated.
The items in my itemlist:
You should take a look for the information on using an endpoint=0:
The endpoint ID is only required/allowed when using the multi_instance
command class. In case a node consists of multiple instances or
endpoints, the instance number can be specified using this value. The
default value is not to use the multi_instance command class - the
number must be positive and must not be 0. An example of a
multi-endpoint device is the Fibaro FGS 221 double relay.
Thanks for the tips.
Oke, got rid of the endpoints, but still stuck at “controleer lichtsterkte”.
Furthermore i’ve added a typecast to the rule, but that didn’t help either.
Exactly what do you expect to see (“to be shown”)? I mean, depending on the state of your Dimmer_RGBWLiving_Ref item - given your if statements - there may actually be nothing to execute (and show).
If i understand the script correctly, then if the Dimmer_RGBWLiving_Red is off, and the lux is below 200 (which is always, just for testing) then i expect to see in the log “verlichting aanzetten” below the last line .
But if the status is on, then it would print “Verlichting woonkamer is al aan”
2015-10-14 22:02:26.621 [INFO ] [runtime.busevents ] - Motion_Living_Motion state updated to 1
2015-10-14 22:02:26.647 [INFO ] [enhab.model.script.Verlichting] - Controleer lichtsterkte
Please correct me if I’m wrong, I’m new to openhab and rules.
Given that the Lux item is read from the device, I am not sure you can guarantee that this is below 200, can you?
Apart from that, I think you may have misplaced the “else” clause in your rule. As it is now there are two possibilites of “falling through” (i.e nothing will happen):
If _Lux.state is less than 200 and _Red.state equals ON.
If _Lux.state is equal to or more than 200 and _Red.state equals OFF.
If you want one of two things to happen (depending on the value of _Red.state) only when _Lux.state is less than 200, you need to write something like this:
Correct me if I’m wrong but isn’t that the same rule that I already have and only the red.state == on removed?
Thought that it wouldn’t make a difference if i specified it (if it isn’t off then it’s on). If the lux is above 200 then nothing should happen. And if red.state is on then nothing should happen either.
The sensor is so located that it doesn’t reach the 200 lux (except when in summer the sun comes thru the window early in the morning), that’s the reason for the 200. If it works it wil go to something like 27 lux.
One other thing, now that I’ve removed the endpoint 0 the battery doesn’t get updated. It’s showing just - %.
Well, not exactly the same. In the original rule (that you show at the start of the thread) the else clause matches the following if statement:
if(Motion_Living_Lux.state < 200) {
In that case, if, as you say, the lux is always below 200 you will only get some action if the _Red.state == OFF (or 0). Your test for _Red.state == ON (or 1) was in the else part of the code, meaning it would only be executed if the lux was equal to or greater than 200.
@arjveld just out of curiosity…
This functionality is already build into the fibraro motion sensor, is there a specific reason that you want it as a rule in OH?
I wanted exactly the same, but used the buildin function. So that even if OH is down, this automatic switch of the light on & after a defined time off works well.
@marcel_verpaalen. I know that I can do that by association and give it a fixed time. The point is that I don’t always want the same lights to come on.
For example: between 16:00 and 1:00 I want the Red, Green and later some other to come on. But if I come out of bed in the middle of the night (between 1:00 and 6:00) I don"t want everything on. Then it’s enough to have one light on for 3 min.
This rule is basicly a startingpoint to expand.
Ah, yes I see, indeed that can only be done with some smart rule.
Challenge is only to get enough updates on the lux without draining the battery too fast. Or alternatively use the buildin funtion for the decision for brightness and the rule in oh for the smart other decisions.
@wolf_from_the_north
I’ve succeded partially. I was able to create a timer for one item. When I’ve added a second timer the first timer also stopped working. At the moment the computer running openhab is down, so I can’t paste the rule here. When I have it up an running again I’ll post the rule here.
How do you have it configured? I have defined 30 as a Night and day offset and it is still active even with Lux values of 37. If I set this as a smart rule, it works well, but I want to use the sensonr’s built in.