Hello,
I want to create a rule, that sends via mqtt when one of the defined items changes. The item SetMode is working (its a number item), but the color item (colorpicker) isnt working. There are no error messenges in my openhab.log, but when i change the state of the color item, there is a error in eventlog.
2019-10-12 13:42:57.829 [ome.event.ItemCommandEvent] - Item 'Color' received command 235,90,100
2019-10-12 13:42:57.900 [nt.ItemStatePredictedEvent] - Color predicted to become NULL
rule:
rule "led_nanoleaf"
when
Item Color changed or Item SetMode changed
then
var mode = (SetMode.state as Number).intValue
var rgb = Color.state
executeCommandLine("mosquitto_pub -d -t home/light/nanoleaf -m {0:"+mode+",2["+rgb+"]}")
end
rule "split_rgb_values"
when
Item Color received command
then
executeCommandLine("mosquitto_pub -d -t home/light/nanoleaf -m {0:1,2["+receivedCommand+"]}")
end
Item Color received command or Item SetMode changed
I just changed my rule to
rule "led_nanoleaf"
when
Item Color received command or Item SetMode changed
then
var mode = (SetMode.state as Number).intValue
var rgb = Color.state
if(rgb == NULL){
rgb = "174,94,100"
}
executeCommandLine("mosquitto_pub -d -t home/light/nanoleaf -m {0:"+mode+",2["+rgb+"]}")
end
Its sending via mqtt when I change the SetMode item and the Color item. The problem is, when Color item changed, it sends the rgb value that is initialized in "if rgb == NULL). I think there is a problem with
What you have would be fine if your Item did have a value, a state.
Your underlying problem is that it does not, it has NULL.
You cannot fix that in your rule, you cannot get what is not there.
You can get your command, just as you did in your other rule.
In my view, you are focused on the wrong thing. Why is your Item staying NULL?