I’ll start out with the actual problem I’m trying to solve, in case anybody has a better approach to do this. Essentially, I have a bunch of z-wave dimmers. When you turn the dimmer on from the physical location, they remember their last brightness level, and return to that level. However when I use my Amazon Echos to “turn kitchen lights on”, an “ON” command gets sent, which sends the dimmer to 100% brightness.
My idea to combat this, was to create a “LastValue” item for each of my dimmers, and a rule that sends the previous state of the dimmer to this item on ever change. The overall logic of this seems to work fine, but what I can’t figure out is why the LastValue item seems to always be divided by 10 when it gets stored.
For example:
The kitchen dimmer item is currently 50, and gets a change to 0 (I turned the light off). My logging shows the state changed from 50 to 0. This means the LastValue item SHOULD be getting a value of 50, since that was the previous state of the dimmer item. Instead, my logs show the LastValue item getting a new value of 5 (rounded to an int).
I feel like I’m missing something simple, but I can’t seem to figure it out. My rule is below:
rule "All Lights Change"
when
Item g_Lights_All changed
then
try {
Thread::sleep(100) // give persistence time to catch up
val lightItem = g_Lights_All.allMembers.filter[s|s.lastUpdate("mapdb") !== null].sortBy[lastUpdate("mapdb")].last as DimmerItem
logInfo(logName, "{} - {} changed from {} to {}.", fileName, lightItem.name, previousState,lightItem.state.toString)
val lastUpdatedItem = g_Lights_LastUpdated.allMembers.filter[dt | dt.name == lightItem.name + "_LastUpdated"].head as DateTimeItem
val lastUpdatedOldValue = lastUpdatedItem.state
val lastUpdatedNewValue = new DateTimeType
lastUpdatedItem.postUpdate(lastUpdatedNewValue)
logInfo(logName, "{} - {} changed from {} to {}.", fileName, lastUpdatedItem.name, lastUpdatedOldValue, lastUpdatedNewValue)
val lastValueItem = g_Lights_Scenes.allMembers.filter[lv | lv.name == lightItem.name + "_LastValue"].head as NumberItem
lastValueItem.postUpdate(previousState)
logInfo(logName, "{} - {} changed from {} to {}.", fileName, lastValueItem.name, lastValueItem.state, previousState)
} catch (Throwable e) {
logError(logName, "{} - Exception in 'All Lights Change' rule {}", fileName, e.toString())
}
end
And here are a couple of log entries. In this example, I went from 0 to about 45, then to 0, then up to 43.
2018-03-19 11:49:34.840 [INFO ] [eclipse.smarthome.model.script.rules] - group_proxies.rules - Light_Kitchen_Pendant_LastValue changed from 0.00000000 to 4.50000000.
2018-03-19 11:49:37.171 [INFO ] [eclipse.smarthome.model.script.rules] - group_proxies.rules - Light_Kitchen_Pendant changed from 0.00000000 to 43.
2018-03-19 11:49:37.173 [INFO ] [eclipse.smarthome.model.script.rules] - group_proxies.rules - Light_Kitchen_Pendant_LastUpdated changed from 2018-03-19T11:49:34.837-0400 to 2018-03-19T11:49:37.172-0400.
2018-03-19 11:49:37.175 [INFO ] [eclipse.smarthome.model.script.rules] - group_proxies.rules - Light_Kitchen_Pendant_LastValue changed from 4.50000000 to 0.00000000.
2018-03-19 11:49:38.940 [INFO ] [eclipse.smarthome.model.script.rules] - group_proxies.rules - Light_Kitchen_Pendant changed from 4.30000000 to 0.
2018-03-19 11:49:38.942 [INFO ] [eclipse.smarthome.model.script.rules] - group_proxies.rules - Light_Kitchen_Pendant_LastUpdated changed from 2018-03-19T11:49:37.172-0400 to 2018-03-19T11:49:38.942-0400.
2018-03-19 11:49:38.944 [INFO ] [eclipse.smarthome.model.script.rules] - group_proxies.rules - Light_Kitchen_Pendant_LastValue changed from 0.00000000 to 4.30000000.
Edit: Changed rule and log examples to remove various casting I was doing to try to figure out the problem. I don’t want any red herrings here.