Et hop, situation actuelle: j'ai créé un simple fichier texte "hex.txt" dans le répertoire domoticz, avec les valeurs hex (sans le #) prises dans la première réponse la :
https://stackoverflow.com/questions/100 ... -to-humans
Une valeur par ligne, donc
00ffff
f0ffff
f5f5dc
000000
0000ff
a52a2a
etc
43 lignes en tout pour l'instant, ce que j'utilise dans le code lua.
Je n'ai pas nettoyé les valeurs: à priori certaines couleurs ne sont pas possibles avec milight et je ne suis même pas sur que le rendu par milight corresponde à ce que cela devrait être (i.e. darkgrey: "#a9a9a9" à priori impossible, darksalmon: "#e9967a" est-il vraiment un darksalmon quand rendu par milight)
Code actuel dans l'interface lua - il semblerait que ceci soit la façon la plus rapide de récupérer la valeur sur la ligne x dans un fichier.
Code : Tout sélectionner
commandArray = {}
if devicechanged['TestSwitch2'] then
RandomLine=math.random(1,43)
local filename = 'hex.txt'
local n=0
for l in io.lines(filename) do
n=n+1
if n==RandomLine then
print("random is "..RandomLine.." and value is "..l)
commandArray['OpenURL']='127.0.0.1:7373/json.htm?type=command¶m=setcolbrightnessvalue&idx=7&hex='..l..'&brightness=40&iswhite=false'
break
end
end
end
return commandArray
Ça fonctionne

mais..
- la couleur est obtenue en 2 étapes, souvent visible (d'abord couleur puis brightness ?) - est-il possible de changer cela ?
- le tout n'est pas bien rapide
2017-11-19 10:48:26.130 User: Admin initiated a switch command (37/TestSwitch2/Off)
2017-11-19 10:48:26.134 (GenericDummyHardware) Light/Switch (TestSwitch2)
2017-11-19 10:48:26.239 LUA: random is 1 and value is 00ffff
2017-11-19 10:48:26.239 EventSystem: Fetching url...
2017-11-19 10:48:26.240 EventSystem: Script event triggered: zz - Read file3
2017-11-19 10:48:26.878 (MiLight Gateway) Lighting Limitless/Applamp (ML - Couch)
2017-11-19 10:48:27.384 (MiLight Gateway) Lighting Limitless/Applamp (ML - Couch)
2017-11-19 10:48:28.833 User: Admin initiated a switch command (37/TestSwitch2/On)
2017-11-19 10:48:28.837 (GenericDummyHardware) Light/Switch (TestSwitch2)
2017-11-19 10:48:28.941 LUA: random is 19 and value is 9400d3
2017-11-19 10:48:28.942 EventSystem: Fetching url...
2017-11-19 10:48:28.942 EventSystem: Script event triggered: zz - Read file3
2017-11-19 10:48:29.573 (MiLight Gateway) Lighting Limitless/Applamp (ML - Couch)
2017-11-19 10:48:30.078 (MiLight Gateway) Lighting Limitless/Applamp (ML - Couch)
2017-11-19 10:48:31.339 User: Admin initiated a switch command (37/TestSwitch2/Off)
2017-11-19 10:48:31.343 (GenericDummyHardware) Light/Switch (TestSwitch2)
2017-11-19 10:48:31.449 LUA: random is 21 and value is ffd700
2017-11-19 10:48:31.450 EventSystem: Fetching url...
2017-11-19 10:48:31.450 EventSystem: Script event triggered: zz - Read file3
2017-11-19 10:48:32.089 (MiLight Gateway) Lighting Limitless/Applamp (ML - Couch)
2017-11-19 10:48:32.595 (MiLight Gateway) Lighting Limitless/Applamp (ML - Couch)