Push button Dimmer

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Push button Dimmer

#1 Post by Patou » 21 May 2018, 11:13

Hello
I want to use an espeasy board to replace existing push button dimmer and be able to control also the lights from remote by Domoticz
I understood good how to do it from Domoticz (write to a GPIO defined as "PWM"), but I want to have the dimmer also working from one push button locally.
This means :
Short push on button (0.25sec) : On at the latest programmed level, second short push on button : Off
Long push on button : Light up from existing level to max level in 1 ... 2 sec seconds, long push on button : light down from existing level to zero When switch is released stay at the level.
In basic like language i can create a loop and increment/decrement a variable ... and send this variable to a GPIO defined as a pwm output but we cannot created loops in rules !!
I saw on the "Devices" the possibility to configure a switch input as a dimmer with a dim level but found no explanation about this in the forum or tutorials
Can somebody help in starting this project ?
Patou

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Push button Dimmer

#2 Post by Patou » 13 Feb 2019, 23:00

Hello
I have posted this in may last year and get no answer
Probably what i want to do is not so easy with rules based on events
But maybe somebody reads this again and knows how to do
Patou


I want to use an espeasy board to replace existing push button dimmer and be able to control also the lights from remote by Domoticz
I understood good how to do it from Domoticz (write to a GPIO defined as "PWM"), but I want to have the dimmer also working from one push button locally.
This means :
Short push on button (0.25sec) : On at the latest programmed level, second short push on button : Off
Long push on button : Light up from existing level to max level in 1 ... 2 sec, second long push on button : light down from existing level to zero When switch is released stay at the level.
In basic like language i can create a loop and increment/decrement a variable ... and send this variable to a GPIO defined as a pwm output but we cannot created loops in rules !!
I saw on the "Devices" the possibility to configure a switch input as a dimmer with a dim level but found no explanation about this in the forum or tutorials
Can somebody help in starting this project ?

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Push button Dimmer

#3 Post by Patou » 15 Feb 2019, 21:16

Hello all,
This rules works but the timerset on 1 sec is too slow is there a plan to have an instruction timerset in msec or even in 100 msec ?
Or is there an other way to introduce a delay in the rules ?

On BP-Up#State=1 do
if [BP-Up#State]=1
event,up
timerset,1,1
endif
endon

On Rules#timer=1 do
if [BP-Up#State]=1
let,2,[var#2]+100
timerset,1,1
endif
endon

Thanks in advance for a reaction

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Push button Dimmer

#4 Post by grovkillen » 15 Feb 2019, 21:46

You could use double click or long push for the button.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Push button Dimmer

#5 Post by Patou » 15 Feb 2019, 22:06

Hello
Thanks for your reaction
But I do not see how long pulse or double click will increment a variable from 0 to 4000 in let's say 100 increments ( 0,100,200,300, ... 4000) in a controlable time of about 2 to 10 sec
Please explain
Patou

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Push button Dimmer

#6 Post by grovkillen » 16 Feb 2019, 10:44

The double click will trigger faster than once a second I think.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Push button Dimmer

#7 Post by Patou » 18 Feb 2019, 01:25

Hello
I found a solution with an external NE 555 to clock a frequency of about 2... 4 Hz.
When Bp is pushed at every clock puls a variable is incremented and the result is used in a pwm command.
If the internal pwm is used range : 0-1024 and step 32 gives about 10 sec from min to max with a reasonnable resolution ( total 30 steps)
For the external multiplexer the steps are of 128 because the max is 4096 (12bit)
The unit works on the internal pwm I am waiting for the multiplexer to text

Dimmer-project.png
Dimmer-project.png (565.73 KiB) Viewed 8495 times
Rules :
On SystemBoot do
timerset,1,5
endon

On Rules#timer=1 do
let,1,0 // 1=On/down, 0=Off/Up
let,2,0 // counter max value 1024
pwm,14,0
endon

On Pulse#State=1 do
If [Bp#State]=1 and [var#2]<1024 and [var#1]=1
let,2,[var#2]+32
endif
If [Bp#State]=1 and [var#2]>0 and [var#1]=0
let,2,[var#2]-32
endif
pwm,14,[var#2]
endon

On Bp#State=1 do
If [var#1]>0
let,1,0
event,LightOff
pwm,14,0
else
let,1,1
event,LightOn
pwm,14,[var#2]
endif
endon

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Push button Dimmer

#8 Post by grovkillen » 18 Feb 2019, 05:35

Thanks for that info! :)
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

Vitalik
New user
Posts: 3
Joined: 23 Dec 2019, 08:37

Re: Push button Dimmer

#9 Post by Vitalik » 08 Aug 2021, 19:31

Code: Select all

On System#Boot do  
let,1,0
let,2,0   
endon

on Kitchen_Led#Led3 do
if [Kitchen_Led#Led3]>0 
  timerResume,1
  gpio,14,0
  pcapwm, 14,3000
  let,2,round([Kitchen_Led#Led3]/3)
  loopTimerSet_ms,1,50,[var#2]
else
  timerPause,1
  let,1,0
  pcapwm, 14,0
  pcapwm, 0,0
  pcapwm, 1,0
  pcapwm, 2,0
endif
endon

On Rules#Timer=1 do
if [var#1]<[Kitchen_Led#Led3]
let,1,[var#1]+3
pcapwm, 0,[var#1]
pcapwm, 1,[var#1]
pcapwm, 2,[var#1]
endif
endon


implemented smooth inclusion

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Push button Dimmer

#10 Post by Patou » 08 Aug 2021, 21:08

Hello,
Using the newly implemented lop timer msec, an external oscillator is not any more necessairy as you have programmed in your rules.
It is now also possible to do indirect adressing and the number of variables is not any more limited to 16.
So I have created a table with 20 values from variable 1 to 20 with values following a logarythmic trend.
%v1=20 %v2%=30 %v3%=44 %v4%=63 %v5%=87 %v6%=116% v7%=150 %v8%=188 %v9%=231 %v10%=279 %v11%=333 %v12%=390 %v13%=452 %v14%=519 %v15%=591 %v16%=668 %v17%=750 %v18%=836 %v19%= 927 %v20%=1023.
Logarithmic trend is better than linear for dimmer( more smooth).
This program line make indirect adressing for the pwm value :

Code: Select all

 pwm,4,[var#%v21%]
The complete rule for 1 dimmer is as follow. (One Esp can handle 2 dimmers limitation is the precision of the loop timer msec!)
(You have to add the lines for the second dimmer usinf BP2 and all the second variables of the dummy devices)

Code: Select all

On Bp1#State=1 do
 TimerSet_ms,1,700
endon 

On Rules#Timer=1 do
 let,25,[Inc#1]*50 // time to dim
 If [Sw#1] = 0 and [Bp1#State=0]
   event,lighton_1
 elseif [Sw#1] = 1 and [Bp1#State=0]
   event,lightoff_1
 endif
endon

On Bp1#State=11 do
 let,25,10
 event, lighton_1
 TimerSet_ms,1,0
 Looptimerset_ms,2,600
endon

On Bp1#State=0 do
 Looptimerset_ms,2,0
 let,31,round([Inc#1]*12.75)
 If [Ct#1] = 0
  TaskValueSet,9,1,1 // Ct#1
 else
  TaskValueSet,9,1,0 // Ct#1
 endif
 Publish,%sysname%/Dim1,[int#31]
 Publish,%sysname%/Count1,[Ct#1]
endon

On lightoff_1 do
 pwm,4,0,%v25%
 TaskValueSet,8,1,0 // Sw#1
 Publish,%sysname%/State1,[Sw#1]
 Taskvalueset,10,1,0
endon

On lighton_1 do
 let,21,[Inc#1]
 pwm,4,[var#%v21%],%v25%
 TaskValueSet,8,1,1 // Sw#1
 Publish,%sysname%/State1,[Sw#1]
 Taskvalueset,10,1,[var#%v21%]
endon



On Rules#timer=2 do
 If [Inc#1] < 20 And [Ct#1] = 0
  TaskValueSet,7,1,[Inc#1]+1  //  Inc#1  Cnt Up
 elseif [Inc#1] > 1 And [Ct#1] = 1
  TaskValueSet,7,1,[Inc#1]-1 // Inc#1  Cnt Down
 endif
 let,21,[Inc#1]
 pwm,4,[var#%v21%]
endon

On DimSet#1 do // DimSet#1 1... 255
 let,41,[Inc#1]-([DimSet#1]/12.75) // Delta Dim / Target
 TaskValueSet,7,1,round([DimSet#1]/12.75) // Set new Inc value
 TaskValueSet,8,1,1 // Sw#1
 let,41,round((%v41%*%v41%)^0.5*200) // ABS of 
 let,21,[Inc#1]
 Taskvalueset,10,1,[var#%v21%]
 pwm,4,[Dim#1],%v41%
 let,31,round([Inc#1]*12.75)
 Publish,%sysname%/Dim1,[int#31]
 Publish,%sysname%/Count1,[Ct#1]
endon

On SwSet#1 do
 let,25,([Inc#1]*300)
 if [SwSet#1] = 1
  event,lighton_1
 else
  event,lightoff_1
 endif
 Publish,%sysname%/State1,[Sw#1]
endon


On System#Boot do
 Let,1,20
 Let,2,30
 Let,3,44
 Let,4,63
 Let,5,87
 Let,6,116
 Let,7,150
 Let,8,188
 Let,9,231
 Let,10,279
 Let,11,333
 Let,12,390
 Let,13,452
 Let,14,519
 Let,15,591
 Let,16,668
 Let,17,750
 Let,18,836
 Let,19,927
 Let,20,1023
 TaskValueSet,8,1,1  //Sw#1
 TaskValueSet,8,2,1  //Sw#2
 TaskValueSet,9,1,1  //Ct#1
 TaskValueSet,9,2,1  //Ct#2
 TimerSet_ms,1,0 // short/long press
 TimerSet_ms,2,0 // cnt up / down
 TimerSet_ms,3,0 
 TimerSet_ms,4,0
 let,21,[Inc#1]
 let,22,[Inc#2] 
 pwm,4,[var#%v21%]
 pwm,5,[var#%v22%]
endon

//On MQTTimport#Connected do
// event,publish_data
//endon

On ha_start do
 event,publish_data
endon

On publish_data do
 let,31,[Inc#1]*12.75
 Publish,%sysname%/Dim1,[int#31]
 let,32,[Inc#2]*12.75
 Publish,%sysname%/Dim2,[int#32]
 Publish,%sysname%/State1,[Sw#1]
 Publish,%sysname%/State2,[Sw#2]
 endon
The Devices are as follow :
Dimmer-devices.png
Dimmer-devices.png (34.62 KiB) Viewed 4648 times
Example of pcb with 2 dimmers :
Dimmer-devices.png
Dimmer-devices.png (34.62 KiB) Viewed 4648 times
Attachments
PWM-led-driver pcb.png
PWM-led-driver pcb.png (154.27 KiB) Viewed 4648 times

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Push button Dimmer

#11 Post by Patou » 08 Aug 2021, 21:09

Sorry I put 2 times the same picture of the devices !!

Vitalik
New user
Posts: 3
Joined: 23 Dec 2019, 08:37

Re: Push button Dimmer

#12 Post by Vitalik » 09 Aug 2021, 18:41

It is smoother and easier to implement for me.
I have no limit on the number of pins to manage
I am using PCA9685 to control LED room illumination
And I set the smoothness with the help of time and the divider coefficient

Patou
Normal user
Posts: 106
Joined: 21 May 2018, 10:33

Re: Push button Dimmer

#13 Post by Patou » 11 Aug 2021, 22:47

Hello Vitalik,
Can you share your rules and the settings of the PCA9685 ?
I do not understand what you mean with : "And I set the smoothness with the help of time and the divider coefficient"
Using the dim duration on an pwm command of a gpio from the Esp 8266 stops the execution of the rules for the dim duration. This is not very convinient !
Thanks in advance
Patou

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest