I have a couple of these that I control switches in my sitemap and via rules invoked by tapping buttons on a WallMote Quad. When turning on the bulbs using my sitemap, the bulbs return to their previous dim level. But when turning them on using the WallMote, they always go to 100%. In the rules that control the bulbs, I have to sendCommand(ON) to the dimmer item, as the switch item does not respond to sendCommand(ON). I suspect this the problem. Here is one of the Item definitions, all 3 of them are setup the same:
Could you please post the whole rule including how it is triggered?
Also, what is the value of StairLight_Dimmer.state before you issue command StairLight_Dimmer.sendCommand(ON). You can add an entry in the openhab.log file by using logInfo command in your rules file
logInfo("State of StairLight_Dimmer = ",StairLight_Dimmer.state)
I have done some logging. Here’s the entire rule that I would like to use, with logging added:
rule "Adjust Stair Light"
when
Item stair_scene received update // stair_scene is button 1 tap on WallMote
then
val sceneval = stair_scene.state
if(sceneval == 1.0){
val stairlightstate = StairLight_Switch.state
logInfo("SwitchState", StairLight_Switch.state.toString) // ON when ON, OFF when OFF
if(StairLight_Switch.state == OFF){
logInfo("SwitchState", "Turning ON") // This is called when ON
StairLight_Switch.sendCommand(ON) // Never works
StairLight_Switch.postUpdate(ON)
}
else{
logInfo("SwitchState", "Turning OFF") // This is called when OFF
StairLight_Switch.sendCommand(OFF)
StairLight_Switch.postUpdate(OFF)
}
}
From your original post, your main issue was that the state was not remembered when you used a physical switch. Let’s try and solve that first. You could try to declare a variable to hold the state. This variable must be updated every time you change the state of your dimmer item and then be used every time the switch item is changed to ON to update the dimmer item to its previous state. You would then have a new rules file with a variable an two rules in it. Please note that the code below has not been tested… it’s just as an example and there is also a possibility that you will need a third rule or an “if-else block” to handle the state when the switch item goes to OFF state.
var Number dimmerState = 50 //Set initial state
rule "Stair Light switched" //restore state of dimmer when switch is switched ON
when
Item stair_scene changed to ON
then
StairLight_Dimmer.state = dimmerState
logInfo("Dimmer state restored to ->", dimmerState.toString())
end
rule "Stair Light dimmed" // Save state of dimmer when dimmer state is updated
when
Item StairLight_Dimmer received update
then
dimmerState = StairLight_Dimmer.state
logInfo("Dimmer state saved ->", dimmerState.toString())
end
If I understand what you’re saying here, I can store the dim level of the bulb in an item and use the value of that item to restore the dim state when turned on based on the changed state of the WallMote.
I’m actually pretty comfortable using rules, the problem I have with these bulbs is that they don’t behave the same as other bulbs I use, both zwave and wemo. Those bulbs always go to their previous dim level without the need for rules.
i got it working using your advice. I added a new ‘received command’ rule, modified the current rule, and an Item to store the dim level of the bulb. I provide a default value for the bulb in the case where the Item’s value is either NULL or 0, otherwise, I use the last dim level stored in the item. Here are the results:
rules:
rule "Adjust Stair Light"
when
Item stair_scene received update
then
val sceneval = stair_scene.state
if(sceneval == 1.0){
val stairlightstate = StairLight_Dimmer.state
if(stairlightstate == 0){
StairLight_Switch.sendCommand(ON)
StairLight_Switch.postUpdate(ON)
}
else{
stair_light_level.state = StairLight_Dimmer.state
StairLight_Switch.sendCommand(OFF)
StairLight_Switch.postUpdate(OFF)
}
}
rule "Toggle Stair Light"
when
Item StairLight_Switch received command
then
var Number dimmer_state = 30
if(receivedCommand == ON){
if(stair_light_level.state != NULL && back_door_1_level.state != 0){
dimmer_state = stair_light_level.state as DecimalType
}
StairLight_Dimmer.sendCommand(dimmer_state)
StairLight_Switch.postUpdate(ON)
}
else{
stair_light_level.state = StairLight_Dimmer.state
StairLight_Dimmer.sendCommand(OFF)
StairLight_Switch.postUpdate(OFF)
}
end