Page 1 of 1
Slowly dim lights
Posted: Friday 04 May 2018 6:18
by Bianco
Hi all,
I am new at domoticz, and have a question. In our house, I have set up a few lamps with Kaku dimmable led bulbs. What i would like is when i trigger a scene, for instance romantic dining, that the lights dim slowly, not in an instance. is this possible and how?
greetings,
Bianco
Domoticz runs on an Raspberry Pi with a RFXCom
Re: Slowly dim lights
Posted: Friday 04 May 2018 8:37
by Egregius
Everything is possible but you'll need to start advanced scripting...
Re: Slowly dim lights
Posted: Friday 04 May 2018 8:59
by waaren
have a look
here to get the idea
Re: Slowly dim lights
Posted: Sunday 06 May 2018 6:21
by Bianco
That looks good.
I will try this in a bit.
Thanks in advance!
Re: Slowly dim lights
Posted: Sunday 06 May 2018 14:26
by alanlsmith
For an alternative here is the Lua script that I use to Fade up/dim lights.
I find it useful as it keeps a track of the light level so that it starts from the level the lights are currently set at,
Code: Select all
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 = 'Your_Lamp'
--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['My_Light_Level'] --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
You will need to install jq <sudo apt-get install jq> and you need to create a user variable (float) with the name of the light which are both used by the following bash script.
The following bash script will update the user variable created above and it is to be called from the On Action field in the lamp's switch. Note change the idx to yours in the bash script. Also change the ip address of Domoticz to your own and the path to jq-1.5 to the location where your's has installed.
Code: Select all
#!/bin/bash
deviceidx=73
name=$(/usr/bin/curl -S -s 'http://192.168.0.10:8080/json.htm?type=devices&rid='$deviceidx | /home/alan/jq-1.5/jq -r .result[]."Name")
level=$(/usr/bin/curl -S -s 'http://192.168.0.10:8080/json.htm?type=devices&rid='$deviceidx | /home/alan/jq-1.5/jq -r .result[]."Level")
data=$(/usr/bin/curl -S -s 'http://192.168.0.10:8080/json.htm?type=devices&rid='$deviceidx | /home/alan/jq-1.5/jq -r .result[]."Data")
if [ "$data" = 'Off' ]; then
level=0
fi
/usr/bin/curl -S -s 'http://192.168.0.10:8080/json.htm?type=command¶m=updateuservariable&vname='$name'_Level&vtype=0&vvalue='$level
echo "Name: $name : Data : $data Level: $level"
You will need to make the bash script executable <chmod +x filename.sh>
Re: Slowly dim lights
Posted: Thursday 14 May 2020 15:21
by stephito52
Hello,
I come back to a subject that dates back a long time.
I would like to dim my LEDs (FADE IN-FADE OUT).
I tried the script below, I declared a user variable, but it doesn't work.
this is the scritp lua
Code: Select all
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
and this is the file named fade.sh
i do a "chmod +x fade.sh"
and "./fade.sh" for execute +
Code: Select all
#!/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"
and this is my user variable
Variable name: Led4_Level
Variable type: float
Can anyone help me ?
Thank you