Hi,
I’ve installed hyperion on my RPi 3 (to control LEDs) and encountered the following problem with my rule.
To describe the aim of the rule – it should convert value from colorpicker to hex-formatted RGB (it has to be RRGGBB, not RGB) and then execute command: hyperion-remote -c RRGGBB.
The problem is, when I try to dim, e.g. green color, it is suddenly converted at particular level to red, not dimmed green.
Rule (partly modified by myself so it may be coded really badly ):
import org.openhab.core.library.types.*
rule “Set RGB value duzy led”
when
Item duzy_led_hsb changed
then
val hsbValue = duzy_led_hsb.state as HSBType val brightness = hsbValue.brightness.intValue
val redValue = ((((hsbValue.red.intValue * 255) / 100) * brightness) / 100) val greenValue = ((((hsbValue.green.intValue * 255) / 100) * brightness) / 100) val blueValue = ((((hsbValue.blue.intValue * 255) / 100) * brightness) / 100)
var red = Integer::toHexString( redValue ) var green = Integer::toHexString( greenValue ) var blue = Integer::toHexString( blueValue )
val rr = red val gg = green val bb = blue
if (red.length() < 2) { red = rr + rr }
if (green.length() < 2) { green = gg + gg }
if (blue.length() < 2) { blue = bb + bb }
val hex = red + green + blue
val komenda = 'hyperion-remote -c ' + hex
executeCommandLine( komenda )
end
Logs (to see values being converted and the results):
11:33:05.642 [INFO ] [marthome.event.ItemStateChangedEvent] - duzy_led_hsb changed from 95.019915,96.289492,83.890374 to 95.019915,96.289492,32.820856
11:33:05.689 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine ‘hyperion-remote -c bb1900’
Alternatively I can send TCP packet with JSON-formatted string but I had problems with the binding. When the hyperion was started, it didn’t work. However, it worked while listening with netcat, so I guess it is some hyperion – or port – issue, and so I tried another way – the one with command execution.
EDIT: Eventually I solved it after another approach with TCP binding (had to add postamble to make it work).