Hello,
I’m new here. I’ve been using openhab for about 1 year. Mostly very simple stuff. Now I’m trying to control my lights.
My setup is as follows: 3 lights which I can control via http (REST). The lights are dimmable. I can read their status but only digital, so on or off. Hence when someone touches the physical switch to turn the lights on, openhab doesn’t know which level they are set to. I have two groups of items: dimmer and status:
Group:Dimmer:MAX gLightCorridors "The max corridor light is [%d]"
Group:Number:MAX gLightCorridorsStatus "The status of the light"
Dimmer LightF1Corridor "Light Floor 1 Corridor" <light> (gLightCorridors)
Dimmer LightF2Corridor "Light Floor 2 Corridor" <light> (gLightCorridors)
Dimmer LightF3Corridor "Light Floor 3 Corridor" <light> (gLightCorridors)
Number LightF1Corridor_State "Light F3 corridor state [%s]" (gLightCorridorsStatus) { http="<[lightF1CorridorCache:10000:REGEX(.*?<val>(.*?)</val>.*)]" }
Number LightF2Corridor_State "Light F3 corridor state [%s]" (gLightCorridorsStatus) { http="<[lightF2CorridorCache:10000:REGEX(.*?<val>(.*?)</val>.*)]" }
Number LightF3Corridor_State "Light F3 corridor state [%s]" (gLightCorridorsStatus) { http="<[lightF3CorridorCache:10000:REGEX(.*?<val>(.*?)</val>.*)]" }
I have 2 rules which react to members of these two:
rule "dimmer changed"
when
Member of gLightCorridors received command // trigger was set to changed before
then
val dimmer = triggeringItem
var state = dimmer.state as Number
val int x = state.intValue
// get the IP address
logDebug("light.rules", "Received command:" + receivedCommand)
logDebug("light.rules", "Light target state:" + x.toString)
...
end
rule "light state changed"
when
Member of gLightCorridorsStatus changed
then
val light = triggeringItem
val state = light.state as Number
val int x = state.intValue
// get the corresponding dimmer
val dimmer = gLightCorridors.members.findFirst[ t | t.name ==
light.name.split("_").get(0) ]
// check if x = 0 & the dimmer is also above 0
if (x == 0 && dimmer.state > 0 ) {
dimmer.postUpdate(0)
}
if (x > 0 && dimmer.state == 0 ) {
dimmer.postUpdate(100)
}
end
The problem I face is the following: when that status changes to e.g. on, I’d like to set the dimmer to 100 without trigger the rule which sends out the http request. I first hat the trigger for the first rule as changed. But then I read in the Documentation that for this case I’d need to use received command. So I changed that. But the receivedCommand only contains the target value and the implicit variable previousState is not set (as would be when the trigger is set to changed) . So when the dimmer in the GUI is changed from 40 to 50 it’s 50. In the documentation is also say, that the received command triggers before that state is updated. So I thought I can use the state to get the previous value. But when testing I see that this is not always the case. Sometimes the receivedCommand is the same as the state of the item. So I’m confused.
Am I missing something, is the documentation wrong or is the implementation not correct? Any ideas how to resolve this?