tobof / openhab-addons

The next-generation open Home Automation Bus (openHAB)
Eclipse Public License 2.0
39 stars 30 forks source link

Changing dimmer value of RGBW throws an error #87

Closed OliverHi closed 6 years ago

OliverHi commented 7 years ago

I am running openhab 2.1.0 and the version 2.2.0.201707241115 of the MySensors binding on a raspberry pi.

When trying to dim the RGBW leds via the paperUI's setting image or via the basic ui I get an error message. The node receives either no value at all or and V_RGBW of length 0. No V_DIMMER at all. This is the used sketch for the node: https://github.com/OliverHi/RGBW-Controller/blob/master/Software/RGBWDimmerV2/RGBWDimmerV2.ino

Looks like the converter function gets called with an empty string somehow.

Error:

00:04:31.311 [ERROR] [nternal.event.MySensorsEventRegister] - Event broadcasting throw an exception
java.lang.StringIndexOutOfBoundsException: String index out of range: 2
        at java.lang.String.substring(String.java:1963)[:1.8.0_131]
        at org.openhab.binding.mysensors.converter.MySensorsRGBWTypeConverter.fromString(MySensorsRGBWTypeConverter.java:27)
        at org.openhab.binding.mysensors.converter.MySensorsTypeConverter.stateFromChannel(MySensorsTypeConverter.java:33)
        at org.openhab.binding.mysensors.handler.MySensorsThingHandler.handleChildUpdateEvent(MySensorsThingHandler.java:275)
        at org.openhab.binding.mysensors.handler.MySensorsThingHandler.sensorUpdateEvent(MySensorsThingHandler.java:198)
        at org.openhab.binding.mysensors.internal.event.MySensorsEventRegister.lambda$4(MySensorsEventRegister.java:129)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at java.lang.Iterable.forEach(Iterable.java:75)[:1.8.0_131]
        at org.openhab.binding.mysensors.internal.event.MySensorsEventRegister.notifyNodeUpdateEvent(MySensorsEventRegister.java:125)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at org.openhab.binding.mysensors.internal.gateway.MySensorsGateway.handleSetReqMessage(MySensorsGateway.java:566)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at org.openhab.binding.mysensors.internal.gateway.MySensorsGateway.handleIncomingMessage(MySensorsGateway.java:461)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at org.openhab.binding.mysensors.internal.gateway.MySensorsGateway.messageReceived(MySensorsGateway.java:372)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at org.openhab.binding.mysensors.internal.event.MySensorsEventRegister.lambda$1(MySensorsEventRegister.java:85)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at java.lang.Iterable.forEach(Iterable.java:75)[:1.8.0_131]
        at org.openhab.binding.mysensors.internal.event.MySensorsEventRegister.notifyMessageReceived(MySensorsEventRegister.java:81)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at org.openhab.binding.mysensors.internal.protocol.MySensorsAbstractConnection$MySensorsReader.run(MySensorsAbstractConnection.java:365)[190:org.openhab.binding.mysensors:2.2.0.201707241115]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_131]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_131]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_131]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_131]
        at java.lang.Thread.run(Thread.java:748)[:1.8.0_131]
tobof commented 7 years ago

I'm able to reproduce this behaviour, definiatly a bug. Thank you for reporting in.

Starting point: MySensorsThingHandler Wrong adapter/converter is choosen: rgbw instead of percentage (dimmer)

OliverHi commented 7 years ago

@tobof I had a quick look at the code and although I am not familiar with the openhab concepts my best guess is that the problem is that RGBW has no dimmer channel So I guess the dimmer sends a RGBW message to the MySensorsRGBWTypeConverter. To fix this one could either add a dimmer channel, or implement typeFromChannelCommand() and adapt fromCommand() to detect dimmer values and send the right values?!

If you could point me in the right direction I might be able to implement some of this. Would be faster if someone else does it though I guess.

tobof commented 7 years ago

I suppose the best approach is your second suggestion. We should switch the channel to dimmer.

I'll give it a try.