I’m not sure, why you have modified the bash script. But don’t replace the params $1, $2 and $3 with a static content. Otherwise you could use the script only once for one bulb and executing with 3 Schl_Bambus_bu_brightness"+ Schl_Bambus_bu_Color.state doesn’t make any sense
According to your example, I have the following suggestions:
items file should look like this … it makes actually no sense to implement the other channels for a colored tradfri bulb at the moment, because they don’t work (as expected).
Number Schl_Bambus_bu_brightness "Helligkeit [%.0f %%]" <bulb>
Number Schl_Bambus_bu_colorpicker "Farbwahl"
Color Schl_Bambus_bu_color "Farbwahl" { channel="hue:0200:00178821c409:6:color" }
rules files should look like this
// RGB Workaround Schlafzimmer Kugel
rule "RGB Workaround Schlafzimmer Kugel"
when
Item Schl_Bambus_bu_colorpicker changed
then
executeCommandLine("/etc/openhab2/scripts/hue_tradfri_color.sh 6 Schl_Bambus_bu_brightness " + Schl_Bambus_bu_colorpicker.state)
end
Where <6> is the number of your bulb (e.g. from hue:0200:00178821c409:6:color)
So use the script hue_tradfri_color.sh as provided by @ei_Gelb_Geek.
The only things, that have to be changed are:
openhab_ip -> set it to your openhab ip
hue_bridge_ip -> set it to your hue bridge ip
hue_bridge_user -> the user hash / secret, you’ll have already
#!/bin/bash
# -- $1 = Bulb ID -- $2 = Bulb Brightness Item -- $3 = Color Command
openhab_ip="192.168.1.10"
hue_brigde_ip="192.168.1.11"
#HUE_Bridge_User erstellen -> https://www.developers.meethue.com/documentation/getting-started
hue_bridge_user="zaishiyahl8eemee1aengud7zeikihe6aeDu"
case $3 in
0)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.5234,0.4023]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
1)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.3812,0.3385]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
2)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.5918,0.399]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "1" "http://$openhab_ip:8080/rest/items/$2"
;;
3)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.6409,0.3332]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
4)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.5465,0.4405]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
5)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.2642,0.6641]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
6)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.5049,0.4509]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
7)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.6566,0.3396]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
8)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.6289,0.34]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
9)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.6944,0.2986]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
10)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.434,0.1777]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
11)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.2454,0.0903]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
12)
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.1538,0.051]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
sleep 1
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
;;
*)
echo "Kommando nicht vorhanden!"
;;
esac
Copy this script to /etc/openhab2/scripts/hue_tradfri_color.sh and make it executable
chown openhab.openhab /etc/openhab2/scripts/hue_tradfri_color.sh
chmod 770 /etc/openhab2/scripts/hue_tradfri_color.sh
So check if everything is working as expected by calling that script with
bash /etc/openhab2/scripts/hue_tradfri_color.sh 6 Schl_Bambus_bu_brightness " + Schl_Bambus_bu_colorpicker.state
for debugging use
bash -x /etc/openhab2/scripts/hue_tradfri_color.sh 6 Schl_Bambus_bu_brightness " + Schl_Bambus_bu_colorpicker.state
In the script $1 is replaced with the bulb id (6), $2 is replaced with the (dummy) brightness item, $3 with the number from the dummy colorpicker (0 - 12).
The script will do a http request to the hue bridge
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.5234,0.4023]}' http://$hue_brigde_ip/api/$hue_bridge_user/lights/$1/state
like
curl -s -H "Accept: application/json" -X PUT --data '{"on": true,"xy": [0.5234,0.4023]}' http://192.168.1.11/api/zaishiyahl8eemee1aengud7zeikihe6aeDu/lights/6/state
and the color of the bulb will change.
Afterwards a rest call is done to the openhab api to update the dummy brightness item from the item definition. This has nothing to do with the “real” brightness state of the bulb. If you change the brightness of the bulb through the app, the item will not be updated.
I’m not sure, why @ei_Gelb_Geek has done this, maybee he wants a feedback in the sitemap and / or can tell more about that feature.
From
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://$openhab_ip:8080/rest/items/$2"
to
curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "50" "http://192.168.1.10:8080/rest/items/Schl_Bambus_bu_brightness"
Sitemap code should look something like this
Frame label="Ambiente" {
Switch item=Schl_Bambus_bu_color label="Farbkugel" icon=crystalball
Text item=Schl_Bambus_bu_brightness
Selection item=Schl_Bambus_bu_colorpicker label="Farbe:" 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 "
]
}
The real color item of the bulb (Schl_Bambus_bu_color) is mapped to a switch, because ON/OFF is actually the only command that works like expected.
Hope this helps to understand the workaround solution.!
The sitemap looks like that …