If you make a dummy device called timer1 set the value name to state and the decimals to 0 with a 1 second interval.
You will get the value 1 on the mqtt immediately after you release the button on the short press, your cycle time is still 1 sec, it may be 2 before you can press again but the button feels responsive on the short press.
on Button1#State=1 do
TaskValueSet 3,1,0
TimerSet,1,1
Delay 200
endon
on rules#timer=1 do
TaskValueSet 3,1,1
if [Button1#State]=1
//Action if button is still pressed
Publish cmnd/21cameron/lounge_dimmer1/button1/state,2
Delay 200
Publish cmnd/21cameron/lounge_dimmer1/button1/state,0
endif
endon
on Button1#State=0 do
if [Timer1#State]=0
Publish cmnd/21cameron/lounge_dimmer1/button1/state,1
Delay 200
Publish cmnd/21cameron/lounge_dimmer1/button1/state,0
endif
endon
This is my latest implementation and what I recommend, this is the rule in espeasy configuration on the dimmer
on rotary1#state do
TaskValueSet 2,1,[rotary1#state]*[rotary1#state]
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
endon
on button1#state=1 do
if [dimmer1#state]!=0 and [timer1#state]=2
TaskValueSet 2,1,0
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
TaskValueSet 12,1,1
else
TaskValueSet 12,1,0
endif
TimerSet,1,1
endon
on button1#state=0 do
else
if [timer1#state]=0 and [dimmer1#state]=0
TaskValueSet 2,1,256
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
TaskValueSet 12,1,0
Delay 100
endif
endon
on rules#timer=1 do
TaskValueSet 12,1,2
if [button1#state]=1
TaskValueSet 2,1,[rotary1#state]*[rotary1#state]
Publish cmnd/21cameron/%sysname%/dimmer1/state,[dimmer1#state]
endif
endon
All of the button / encoder logic is done on the ESP easy. It works like this.
Button Press > On > Light On full brightness (256 published) > rotary encoder works and will dim light on turning it will dim from last position, 16 steps in non linear (to the power of 2 between 0 and 256)
Button Press > Off > Light Off zero brightness (0 published)
Long Button Press > On to the last dimmer setting
It took me hours to work at the logic with the limited nested statements available but it is the least amount of code and configuration in home assistant with the most functionality. It could be used to control a dimmer directly without home assistant and you can use multiple dimmer controls/locations on the same light, it can mimic the old hallway/2 way setups. Hope it helps someone
Thanks for the nice post. I do not get it set-up correctly though. My ESP Mega does not show a rules section. I have the rules1.txt file and can edit that I just put your content there. However nothing ever gets published.
Hello. This an amazing project I really want to get implemented into my own design. I don’t suppose you are able to upload your config files and easyesp files?
The rotary encoder will work with 3v3. Not sure about 3v.
As I understand it this works with lights that are dimmable using wifi, zwave etc, They could be 240v, 120v, 24/12/5v leds, in fact it is voltage agnostic, as long as home assistant can control the light.
This project supports only smart bulbs.
It’s essentially a mqtt controller.
It is not a standard dimmer and will not dim an incandescent or non smart led bulb