Avant toute chose, je précise que je suis totalement novice dans le domaine des scripts.
Je commande avec DOMOTICZ mes ampoules LED "SMART LSC" de chez ACTION grâce au wifi intégré.
J'aimerai , si cela est possible, faire un script qui permettrait de faire un allumage progressif (fade in) et une extinction identique (fade out) de mes LEDS.
En recherchant sur le web, j'ai trouvé cet article (https://www.domoticz.com/forum/viewtopic.php?t=23310) qui traite du sujet.
J'ai suivi le tuto de mon coté, sans résultats probant.
pour être plus précis, j'ai déclaré une variable utilisateur "LED2" de type "float" , avec la valeur 0. Je ne sais pas si la valeur 0 est la bonne...
Ensuite, j'ai déclaré dans les évènements DOMOTICZ un script nommé "script.lua" , dont voici le code :
Code : Tout sélectionner
commandArray = {}
--Round to a set number of decimal places
function round(what, precision)
if (what) then
return math.floor(what*math.pow(10,precision)+0.5) / math.pow(10,precision)
else
return math.floor(val+0.5)
end
end
local light = 'Led4'
--For fading
local lightstepsfull = 20 --100% in 5% steps --These need to be adjusted top suit the--
local lightstep = 5 --number of steps to suit your light/dimmer--
local timestep = 1 -- Time in seconds between each light level step--
local delay = 0 --Delay, (if any) before start of dimming/fading up--
local lightlevel = uservariables['Led4'] --This needs to be the name of your light, as the bash script updates the variable
local lightstepsnow = round( lightlevel / lightstep , 0 )
local lightsteps = lightstepsfull - lightstepsnow
--Turning on*************************************************
if(devicechanged[switch] == 'On') then
--Fade up Light--
for i = 1,lightsteps do
lightlevel = lightlevel + lightstep
delay = delay + timestep
commandArray[#commandArray+1] = {[light] = 'Set Level ' ..lightlevel.. ' AFTER ' ..delay}
end
--Turning off*************************************************
elseif(devicechanged[switch] == 'Off') then
--Dim Light--
for i = 1,lightstepsnow do
lightlevel = lightlevel - lightstep
delay = delay + timestep
commandArray[#commandArray+1] = {[light] = 'Set Level ' ..lightlevel.. ' AFTER ' ..delay}
end
end
return commandArray Code : Tout sélectionner
#!/bin/bash
deviceidx=4
name=$(/usr/bin/curl -S -s 'http://192.168.1.61:8080/json.htm?type=devices&rid=$
level=$(/usr/bin/curl -S -s 'http://192.168.1.61:8080/json.htm?type=devices&rid$
data=$(/usr/bin/curl -S -s 'http://192.168.1.61:8080/json.htm?type=devices&rid=$
if [ "$data" = 'Off' ]; then
level=0
fi
/usr/bin/curl -S -s 'http://192.168.1.61:8080/json.htm?type=command¶m=updat$
echo "Name: $name : Data : $data Level: $level"
Quand j 'execute script.lua dans les évènements , il ne se passe rien dans les logs, et quand j'actionne l'interrupteur de la LED sous DOMOTICZ, celle ci s'allume normalement sans fade in .
Bref, je ne sais pas ce qui bloque vraiment.
Pour info, je tourne sur la dernière version de DOMOTICZ 2020.2 sur un PI4.
Si quelqu'un pourrais m'aider, ce serait vraiment très sympa.
Merci à tous.