Issues with passing variables form openhab to outside script

Hello all,

I have several IKEA Tradfri Color bulbs connected to a HUE bridge and i am not able to change color form openhab.
Nothing new here, for it has already been discussed in this (IKEA Tradfri Color Changing bulb on Hue Bridge no control of colors).

In this post, there is reference of a script that has a static value applied to it when executed form the rules.
How can i change the rules file, so when i chose one of my light bulbs it is passed directly to the script (value $1)?
Also, the same applies to the HSB (value $2). How can i obtain the value form colorpicker?

My files (copy paste from the original post):

.rules

rule “RGB Farbe Wohnzimmer Schrank”
when
Item colorpicker_wohnzimmer_schrank changed
then
executeCommandLine("/etc/openhab2/scripts/hue_tradfri_color.sh 10 Stehlampe_Wohnzimmer_Schrank_Brightness " + colorpicker_wohnzimmer_schrank.state)
end

Current .mappings file:

Selection item=colorpicker_wohnzimmer_schrank label=“Farbe:” icon=“colorpicker” visibility=[Stehlampe_Wohnzimmer_Schrank_Switch==ON] mappings=[
0=" Warmes Licht “,
1=” Tageslicht “,
2=” Nachtlicht “,
3=” Sonnenuntergang “,
4=” Gelb “,
5=” Helles Gelb “,
6=” Helles Grün “,
7=” Orange “,
8=” Helles Orange “,
9=” Rot “,
10=” Pink “,
11=” Helles Lila “,
12=” Blau "
]

I want to replace the above section with:

Colorpicker item=colorpicker_wohnzimmer_schrank label=“Farbe:” icon=“colorpicker”

So, i need to get the value of the lamp, and the output of colorpicker and pass it to the script:
How can it be done? Is it possible? I dont have the budget to buy an bridge Tradfri just for this lamps.

Again thanks for a very nice program and all your input!

The colorpicker Item is returning the names of colors. A Color element on the sitemap isn’t going to give you nice names of colors. It’s going to give you three values, hue, saturation, and brightness. You either need to:

  1. Convert that HSB coordinate to the name of a color to pass to the script
  2. Modify the script so it can translate the HSB coordinate itself

I do have the script already. I just need to pass the values form openhab into the script.

OK, if the script already undersands “h,s,b” as an argument, than change the colorpicker Item to be a Color Item and put it on the sitemap as a Colorpicker element.


Sorry, but i dont understand. I see on the examples and handbooks you have provided, references to %d, and others that i would assume to be variables.
Is this correct? What variable letter does colorpicker have, and how can i pass it to the script?

Thanks again for your help!

Items:

Color colorpicker_wohnzimmer_schrank "Some Label"

Sitemap:

Colorpicker item=colorpicker_wohnzimmer_schrank

The Item will appear on your sitemap as a color picker widget. When the Item changes it wall trigger your rule and the HSB value will be passed to your script of the format H,S,B, for example 320,75,50.

This is really super basic stuff. The Colorpicker determines what UI element is used to represent the Item on the sitemap. Any changes made on the sitemap end up becoming commands sent to the Item.

Thanks. I am fairly new to this.
But i am used to pass variables to a script with $1 $2 $3 etc. It’s the same here? the executeCommandLine will append to the end of the script the HSB values? Or do i have to add the colorpicker_wohnzimmer_schrank.state?

Again thanks for your help. This is a blast!

With openHAB the devil is in the details. You will need to constantly be going back to the docs. In this case, looking back at the executeCommandLine docs you will find:

  • executeCommandLine(String commandLine): Executes a command on the command line without waiting for the command to complete
  • executeCommandLine(String commandLine, int timeout): Executes a command on the command and waits timeout milliseconds for the command to complete, returning the output from the command as a String

Note

Simple arguments that contain no spaces can be separated with spaces, for example executeCommandLine(“touch file.txt”). When one or more arguments contain spaces, use @@ instead of a space as the argument separator. For example the bash command touch -t 01010000 “some file with space.txt” will have to be written as touch@@-t@@01010000@@some file with space.txt.

That means that in your command is passed as one big String. Often, the arguments need to be separated using @@. (NOTE: this has changed in OH 3 where the command and it’s arguments are passed as separate strings).

So look again at the rule you copied.

executeCommandLine("/etc/openhab2/scripts/hue_tradfri_color.sh 10 Stehlampe_Wohnzimmer_Schrank_Brightness " + colorpicker_wohnzimmer_schrank.state)

Notice that + colorpicker_wohnzimmer_schrank.state. That’s adding the state of the colorpicker Item to the end of the string that is passed to executeCommandLine.

1 Like

Thanks!!