help on rules from tasmota to espeasy

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

help on rules from tasmota to espeasy

#1 Post by megamarco83 » 12 Feb 2022, 17:51

hi, i have a push button that is now on a tasmota device that make this:
when it's single press => send command to power on the light => publish cmnd/dimmer/power TOGGLE
when it is first time longpress => send the command to increase the dimmer => cmnd/dimmer/DIMMER +
when it is second time longpress => send the command to decrease the dimmer => cmnd/dimmer/DIMMER -
then the third time come back to "+" and so on.
of course it continue to send the command "+" or "-" till the duration of the pressing

the actual rule that manage it in tasmota is:

Code: Select all

rule2 ON system#boot DO Backlog var1 +; var2 1 ENDON
ON switch1#state=2 DO publish cmnd/dimmer/power TOGGLE ENDON
ON switch1#state=4 DO publish cmnd/dimmer/DIMMER %var1% ENDON
ON switch1#state=7 DO mult2 -1 ENDON
ON var2#state==-1 DO var1 - ENDON
ON var2#state==1 DO var1 + ENDON
ON dimmer#state==1 DO mult2 -1 ENDON
ON dimmer#state==100 DO mult2 -1 ENDON
how i can menage it with espeasy now?
for short press to toggle the power is very easy, but how i can perform that fist time that i longpres it published

Code: Select all

cmnd/dimmer/DIMMER +  
//continue feeding this command still i continue to press the button
and second time that is longpressed will publish

Code: Select all

cmnd/dimmer/DIMMER -
//continue feeding this command still i continue to press the button
the third time taht is longpressed publish

Code: Select all

cmnd/dimmer/DIMMER +
//continue feeding this command still i continue to press the button
the fourth time that is longpressed publish

Code: Select all

cmnd/dimmer/DIMMER -
//continue feeding this command still i continue to press the button
and so on?

thanks

lindadieggoo
New user
Posts: 1
Joined: 24 Feb 2022, 04:30

Re: help on rules from tasmota to espeasy

#2 Post by lindadieggoo » 24 Feb 2022, 04:33

it's a complex piece of code. Did you find the solution? drift hunters

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: help on rules from tasmota to espeasy

#3 Post by megamarco83 » 24 Feb 2022, 09:26

lindadieggoo wrote: 24 Feb 2022, 04:33 it's a complex piece of code. Did you find the solution? drift hunters
hi, unfortunately not ;(
i'm still using tasmota for this device but i would like to move on espeasy because i have already an esp with espeasy that control other relays...

to control the push button when it's single press => send command to power on the light => publish cmnd/dimmer/power TOGGLE it's very easy, so no matter here


the difficulties are on:

when it is first time longpress => continuously send the command to increase the dimmer (that should continuously sending this command till i maintain pressed the push button), that's => publish cmnd/dimmer/DIMMER +
when it is second time longpress => continuously send the command to decrease the dimmer (that should continuously sending this command till i maintain pressed the push button), that's => publish cmnd/dimmer/DIMMER -

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: help on rules from tasmota to espeasy

#4 Post by chromo23 » 26 Feb 2022, 21:42

Code: Select all

On Button#State=1 do
  timerSet_ms,1,300
endon

On Rules#Timer=1 do 
 if [Button#State]=0 
  event,toggle
 else
   timerSet,2,1
 endif
endon

On Rules#Timer=2 do
 if [Button#State]=1 
   if [var#1]=0
    //your code for dimmercommand+ here
   else
    //your code for dimmercommand- here
   endif   
   timerSet_ms,2,1000
 else
   let,1,![var#1]
 endif
endon
Last edited by chromo23 on 28 Feb 2022, 13:10, edited 1 time in total.

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: help on rules from tasmota to espeasy

#5 Post by megamarco83 » 28 Feb 2022, 11:32

chromo23 wrote: 26 Feb 2022, 21:42

Code: Select all

On Button#State=1 do
  timerSet_ms,1,300
endon

On Rules#Timer=1 do 
 if [Button#State]=0 
  event,toggle
 else
   timerSet,2,1
 endif
endon

On Rules#Timer=2 do
 if [Button#State]=1 
   if [var#1]=0
    dimmercommand+
   else
    dimmerecommand- 
   endif   
   timerSet_ms,2,1000
 else
   let,1,![var#1]
 endif
endon
hi, thanks for your suggestion!!!
starting from this i use the internal function of longpress(task=10) and shorpress (task=0)
i report here the code:

Code: Select all

on pcf_73_camera_dx#State do
if [pcf_73_camera_dx#State]=10 
 event, dimmer
 else
   let,1,![var#1]
 endif
  if [pcf_73_camera_dx#State]=0  
  event,toggle
 else
   let,1,![var#1]
endif
endon

On event#dimmer do
   if [var#1]=0
    dimmercommand+
   else
    dimmerecommand- 
   endif   
endon

On toggle do
  Publish cmnd/dimmer/power1,'2' // tasmota toggle luce dimmer cameraDX
endon

On dimmercommand+
  Publish cmnd/dimmer/dimmer,'+' // tasmota dimmer+ luce dimmer cameraDX
endon

On dimmercommand-
  Publish cmnd/dimmer/dimmer,'-' // tasmota dimmer- luce dimmer cameraDX
endon

but there is an issue, with shortpress no matter => it works
but longpress espeasy not send out the command for dimmering + or dimmering -
can you help me on understand why?
below the log


Code: Select all

689129374: PCF : Port=73 State=0 Output value=0
689129387: EVENT: pcf_73_camera_dx#State=0.00
689129517: ACT : let,1,!0.00
689129519: Command: let
689129527: ACT : event,toggle
689129528: Command: event
689129528: EVENT: toggle
689129628: ACT : Publish cmnd/dimmer/power1,'2'
689129630: Command: Publish
689130469: PCF : LongPress: Port= 73 State=0 Output value=10
689130475: EVENT: pcf_73_camera_dx#State=10.00
689130573: ACT : let,1,!1.00
689130575: Command: let
689130582: ACT : event,toggle
689130583: Command: event
689130584: EVENT: toggle
689132462: ACT : Publish cmnd/dimmer/power1,'2'
689132464: Command: Publish
689132809: WD : Uptime 11486 ConnectFailures 4 FreeMem 16200 WiFiStatus 3
689133399: PCF : Port=73 State=1 Output value=1
689133411: EVENT: pcf_73_camera_dx#State=1.00
689133487: ACT : let,1,!0.00
689133489: Command: let
689133500: ACT : let,1,!1.00
689133501: Command: let

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: help on rules from tasmota to espeasy

#6 Post by chromo23 » 28 Feb 2022, 13:01

starting from this i use the internal function of longpress(task=10) and shorpress (task=0)
hi,
my code it somewhat "oldschool" because there was an issue with longpress in the past. it seems to be fixed now...

your code is not quite right. to call an event you have to do it like this:

Code: Select all

event, dimmercommand+  //not so good
event, dimmerplus //better
...and it is always good to avoid characters like + because they serve a function in rules (i used it only as pseudocode....fixed it in the last post)

to react on an event it is simply:

Code: Select all

On dimmer do
so it should be:

Code: Select all

on pcf_73_camera_dx#State do
if [pcf_73_camera_dx#State]=10 
 event,dimmer
 else
   let,1,![var#1]
 endif
  if [pcf_73_camera_dx#State]=0  
  event,toggle
 else
   let,1,![var#1]
endif
endon

On dimmer do
   if [var#1]=0
    event,dimmerplus
   else
    event,dimmerminus 
   endif   
endon

On toggle do
  Publish cmnd/dimmer/power1,'2' // tasmota toggle luce dimmer cameraDX
endon

On dimmerplus do
  Publish cmnd/dimmer/dimmer,'+' // tasmota dimmer+ luce dimmer cameraDX
endon

On dimmerminus do
  Publish cmnd/dimmer/dimmer,'-' // tasmota dimmer- luce dimmer cameraDX
endon

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: help on rules from tasmota to espeasy

#7 Post by megamarco83 » 28 Feb 2022, 13:46

chromo23 wrote: 28 Feb 2022, 13:01
your code is not quite right. to call an event you have to do it like this:

Code: Select all

event, dimmercommand+  //not so good
event, dimmerplus //better
...and it is always good to avoid characters like + because they serve a function in rules (i used it only as pseudocode....fixed it in the last post)

to react on an event it is simply:

Code: Select all

On dimmer do
so it should be:
thanks again for support, really appreciated!
i apply your suggestion but it seams that the rules for longpress are wrong.

here the logs:

Code: Select all

418841: PCF : Port=73 State=0 Output value=0
418847: EVENT: PCF#73=0
419075: EVENT: pcf_73_camera_dx#State=0
419191: ACT : let,1,!1
419207: ACT : event,toggle
419209: EVENT: toggle
419337: ACT : Publish cmnd/dimmer/power1,'2'
419901: PCF : LongPress: Port= 73 State=0 Output value=10
419904: EVENT: PCF#73=10
420135: EVENT: pcf_73_camera_dx#State=10
420251: ACT : let,1,!0
420265: ACT : event,toggle
420267: EVENT: toggle
420402: ACT : Publish cmnd/dimmer/power1,'2'
424780: PCF : Port=73 State=1 Output value=1
424786: EVENT: PCF#73=1
424935: EVENT: pcf_73_camera_dx#State=1
425050: ACT : let,1,!1
425068: ACT : let,1,!0
if i longress the light turn on and then after a second it torn off without dimmering.

unfortunately the command that tasmota expect to receive trought mqtt is:
topic = cmnd/dimmer/dimmer
payload = +
or
payload = -

but it seams from the log that it's not a matter of publishing (+) or (-) because espeasy send nothing....isn't it?

thanks for help again


p.s. here the code:

Code: Select all

on pcf_73_camera_dx#State do
if [pcf_73_camera_dx#State]=10 
 event,dimmer
 else
   let,1,![var#1]
 endif
  if [pcf_73_camera_dx#State]=0  
  event,toggle
 else
   let,1,![var#1]
endif
endon

On dimmer do
   if [var#1]=0
    event,dimmerplus
   else
    event,dimmerminus 
   endif   
endon

On toggle do
  Publish cmnd/dimmer/power1,'2' // tasmota toggle luce dimmer cameraDX
endon

On dimmerplus do
  Publish cmnd/dimmer/dimmer,'+' // tasmota dimmer+ luce dimmer cameraDX
endon

On dimmerminus do
  Publish cmnd/dimmer/dimmer,'-' // tasmota dimmer- luce dimmer cameraDX
endon

User avatar
chromo23
Normal user
Posts: 827
Joined: 10 Sep 2020, 16:02
Location: germany

Re: help on rules from tasmota to espeasy

#8 Post by chromo23 » 28 Feb 2022, 14:05

can you please test my code?

Code: Select all

on pcf_73_camera_dx#State=0 do
  timerSet_ms,1,300
endon

On Rules#Timer=1 do 
 if [pcf_73_camera_dx#State]=1 
  event,toggle
 else
   timerSet,2,1
 endif
endon

On Rules#Timer=2 do
 if [pcf_73_camera_dx#State]=0 
   if [var#1]=0
    event, dimmerplus 
   else
    event, dimmerminus
   endif   
   timerSet_ms,2,1000
 else
   let,1,![var#1]
 endif
endon

On toggle do
  Publish cmnd/dimmer/power1,'2' // tasmota toggle luce dimmer cameraDX
endon

On dimmerplus do
  Publish cmnd/dimmer/dimmer,'+' // tasmota dimmer+ luce dimmer cameraDX
endon

On dimmerminus do
  Publish cmnd/dimmer/dimmer,'-' // tasmota dimmer- luce dimmer cameraDX
endon
edit: my code is firing dimmerplus ore dimmerminus every second while holding the button...it is intentionally. but now i am not sure if i understood you correctly.
if only once it should be (untested):

Code: Select all

On Rules#Timer=2 do
 if [pcf_73_camera_dx#State]=0 
   if [var#1]=0
    event, dimmerplus 
   else
    event, dimmerminus
   endif   
    let,1,![var#1]
 endif
endon

megamarco83
Normal user
Posts: 230
Joined: 13 Apr 2017, 23:09

Re: help on rules from tasmota to espeasy

#9 Post by megamarco83 » 28 Feb 2022, 15:45

chromo23 wrote: 28 Feb 2022, 14:05 can you please test my code?

Code: Select all

on pcf_73_camera_dx#State=0 do
  timerSet_ms,1,300
endon

On Rules#Timer=1 do 
 if [pcf_73_camera_dx#State]=1 
  event,toggle
 else
   timerSet,2,1
 endif
endon

On Rules#Timer=2 do
 if [pcf_73_camera_dx#State]=0 
   if [var#1]=0
    event, dimmerplus 
   else
    event, dimmerminus
   endif   
   timerSet_ms,2,1000
 else
   let,1,![var#1]
 endif
endon

On toggle do
  Publish cmnd/dimmer/power1,'2' // tasmota toggle luce dimmer cameraDX
endon

On dimmerplus do
  Publish cmnd/dimmer/dimmer,'+' // tasmota dimmer+ luce dimmer cameraDX
endon

On dimmerminus do
  Publish cmnd/dimmer/dimmer,'-' // tasmota dimmer- luce dimmer cameraDX
endon
yes, of course. thanks for your kindness.
i tested it, and it works perfectly!!!
chromo23 wrote: 28 Feb 2022, 14:05 edit: my code is firing dimmerplus ore dimmerminus every second while holding the button...it is intentionally. but now i am not sure if i understood you correctly.
if only once it should be (untested):
you understand correctly: when i dim, i need to continue feed the command:
Publish cmnd/dimmer/dimmer,'-'
or
Publish cmnd/dimmer/dimmer,'+'
and your code is according to this: till i press the button it send coniusoly (every seconds) => timerSet_ms,2,1000
so it's very good working.
i not understand why using longress plugin (instead of timers) it not works :(

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: help on rules from tasmota to espeasy

#10 Post by Ath » 28 Feb 2022, 15:57

megamarco83 wrote: 28 Feb 2022, 15:45 i not understand why using longress plugin (instead of timers) it not works :(
LongPress event is generated only once, and not repeating if the button is being pressed for prolonged time.
/Ton (PayPal.me)

Sminter4
Normal user
Posts: 18
Joined: 04 Aug 2021, 23:25

Re: help on rules from tasmota to espeasy

#11 Post by Sminter4 » 04 Jan 2024, 15:34

I have a similar problem. When I query for "longpress" (11) or "Doubleclick" (3), %eventvalue1%=1 is always output first. This means I always get two commands instead of one.
How can I prevent this without a timer?

For example:

Code: Select all

on drei#state do //Rolladen
 LongPulse_mS,14,1,100
 if [drei#state]=1
   http://192.168.178.109/roller/0?go=open
  endif
  if [drei#state]=11
   http://192.168.178.109/roller/0?go=close
 endif
endon

Post Reply

Who is online

Users browsing this forum: No registered users and 103 guests