Slowly dim lights

Moderator: leecollings

Post Reply
Bianco
Posts: 3
Joined: Friday 04 May 2018 6:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Slowly dim lights

Post 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
User avatar
Egregius
Posts: 2582
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Slowly dim lights

Post by Egregius »

Everything is possible but you'll need to start advanced scripting...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Slowly dim lights

Post by waaren »

have a look here to get the idea
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Bianco
Posts: 3
Joined: Friday 04 May 2018 6:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Slowly dim lights

Post by Bianco »

That looks good.

I will try this in a bit.

Thanks in advance!
alanlsmith
Posts: 132
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: Latest β
Location: Near London (Saaarf!)
Contact:

Re: Slowly dim lights

Post 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&param=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>
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
stephito52
Posts: 1
Joined: Thursday 14 May 2020 12:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Slowly dim lights

Post 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&param=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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest