From 4cfe895be1b31e5b91da8da4ee4e8398bcf2fbd3 Mon Sep 17 00:00:00 2001 From: MMV Date: Sun, 11 Feb 2024 02:54:36 +0300 Subject: [PATCH 1/3] add rules to basic switch actions --- contrib/T5-3C-86/README.md | 14 ++++++++++++++ contrib/T5-3C-86/t5-3c.be | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 contrib/T5-3C-86/README.md create mode 100644 contrib/T5-3C-86/t5-3c.be diff --git a/contrib/T5-3C-86/README.md b/contrib/T5-3C-86/README.md new file mode 100644 index 0000000..675779f --- /dev/null +++ b/contrib/T5-3C-86/README.md @@ -0,0 +1,14 @@ +# Simple rules for T5-3C + +If added to txultimate.be impkement actual switch function. + +## Functions + +- short press - TOGGLE power in gang and haptic feedback +- swipe right - switch on all gangs and haptic feedback +- swipe left - switch off all gangs and haptic feedback + +## Install + +- Upload t5-3c.be to tasmota filesystem +- Add to autoexec.be a line load("t5-3c.be") \ No newline at end of file diff --git a/contrib/T5-3C-86/t5-3c.be b/contrib/T5-3C-86/t5-3c.be new file mode 100644 index 0000000..d4f7e07 --- /dev/null +++ b/contrib/T5-3C-86/t5-3c.be @@ -0,0 +1,37 @@ +def TXUltimate_Short(value, trigger, msg) + print("message:") + print(msg) + var Channel = msg['TXUltimate']['Channel'] + if Channel <= 3 + tasmota.cmd('Power1 2') + elif Channel >3 && Channel < 8 + tasmota.cmd('Power2 2') + else + tasmota.cmd('Power3 2') + end + tasmota.cmd('Buzzer 1,2') +end + +def TXUltimate_Action(value, trigger, msg) + print("message:") + print(msg) + var Action = msg['TXUltimate']['Action'] + if Action == 'Swipe right' + tasmota.cmd('Power1 1') + tasmota.cmd('Power2 1') + tasmota.cmd('Power3 1') + tasmota.cmd('Buzzer 1,2') + elif Action == 'Swipe left' + tasmota.cmd('Power1 0') + tasmota.cmd('Power2 0') + tasmota.cmd('Power3 0') + tasmota.cmd('Buzzer 1,2') + end +end + +tasmota.remove_rule("TXUltimate#Action=Short", "TXUltimate_Short") +tasmota.add_rule("TXUltimate#Action=Short", TXUltimate_Short, "TXUltimate_Short") + +tasmota.remove_rule("TXUltimate#Action", "TXUltimate_Action") +tasmota.add_rule("TXUltimate#Action", TXUltimate_Action, "TXUltimate_Action") + From 2c4905a55eeb3cf09f645b06cce4411b3481e676 Mon Sep 17 00:00:00 2001 From: MMV Date: Wed, 13 Mar 2024 19:46:52 +0300 Subject: [PATCH 2/3] Refactoring - tasmota.cmd('Power ') is slow, replace by tasmota.set_power - Separate handlers for different events --- contrib/T5-3C-86/t5-3c.be | 58 ++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/contrib/T5-3C-86/t5-3c.be b/contrib/T5-3C-86/t5-3c.be index d4f7e07..35609a0 100644 --- a/contrib/T5-3C-86/t5-3c.be +++ b/contrib/T5-3C-86/t5-3c.be @@ -1,37 +1,57 @@ +# Touch events handlers + +def TXUltimate_Touch(value, trigger, msg) + tasmota.cmd('Buzzer') +end + def TXUltimate_Short(value, trigger, msg) - print("message:") - print(msg) + #print("message:") + #print(msg) var Channel = msg['TXUltimate']['Channel'] + var ind if Channel <= 3 - tasmota.cmd('Power1 2') + ind = 0 + #tasmota.cmd('Power1 2') + tasmota.set_power(ind, ! tasmota.get_power(ind)) elif Channel >3 && Channel < 8 - tasmota.cmd('Power2 2') + ind = 1 + #tasmota.cmd('Power2 2') + tasmota.set_power(ind, ! tasmota.get_power(ind)) else - tasmota.cmd('Power3 2') + ind = 2 + #tasmota.cmd('Power3 2') + tasmota.set_power(ind, ! tasmota.get_power(ind)) end - tasmota.cmd('Buzzer 1,2') end -def TXUltimate_Action(value, trigger, msg) - print("message:") - print(msg) +def TXUltimate_Swipe(value, trigger, msg) + #print("message:") + #print(msg) var Action = msg['TXUltimate']['Action'] + var targetstate if Action == 'Swipe right' - tasmota.cmd('Power1 1') - tasmota.cmd('Power2 1') - tasmota.cmd('Power3 1') - tasmota.cmd('Buzzer 1,2') + targetstate = '1' + var From = msg['TXUltimate']['From'] + var To = msg['TXUltimate']['To'] + # Fix: Power0 manage all channels include backlight + tasmota.cmd('Power0 1') elif Action == 'Swipe left' - tasmota.cmd('Power1 0') - tasmota.cmd('Power2 0') - tasmota.cmd('Power3 0') - tasmota.cmd('Buzzer 1,2') + targetstate = '0' + var From = msg['TXUltimate']['From'] + var To = msg['TXUltimate']['To'] + # Fix: Power0 manage all channels include backlight + tasmota.cmd('Power0 0') end end +tasmota.remove_rule("TXUltimate#Action=Touch", "Touch") +tasmota.add_rule("TXUltimate#Action=Touch", TXUltimate_Touch, "TXUltimate_Touch") + tasmota.remove_rule("TXUltimate#Action=Short", "TXUltimate_Short") tasmota.add_rule("TXUltimate#Action=Short", TXUltimate_Short, "TXUltimate_Short") -tasmota.remove_rule("TXUltimate#Action", "TXUltimate_Action") -tasmota.add_rule("TXUltimate#Action", TXUltimate_Action, "TXUltimate_Action") +tasmota.remove_rule("TXUltimate#Action=Swipe right", "TXUltimate_Swipe_right") +tasmota.add_rule("TXUltimate#Action=Swipe right", TXUltimate_Swipe, "TXUltimate_Swipe_right") +tasmota.remove_rule("TXUltimate#Action=Swipe left", "TXUltimate_Swipe_left") +tasmota.add_rule("TXUltimate#Action=Swipe left", TXUltimate_Swipe, "TXUltimate_Swipe_left") From 5472149cd77e91ac70d60af1be86c6ed390ece05 Mon Sep 17 00:00:00 2001 From: MMV Date: Fri, 13 Jun 2025 15:47:49 +0300 Subject: [PATCH 3/3] Publish events Long, swipe, Multi to MQTT --- contrib/T5-3C-86/t5-3c.be | 48 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/contrib/T5-3C-86/t5-3c.be b/contrib/T5-3C-86/t5-3c.be index 35609a0..0e401c5 100644 --- a/contrib/T5-3C-86/t5-3c.be +++ b/contrib/T5-3C-86/t5-3c.be @@ -1,5 +1,7 @@ # Touch events handlers +var eventtopic = "stat/tasmota_E09620" + def TXUltimate_Touch(value, trigger, msg) tasmota.cmd('Buzzer') end @@ -7,6 +9,7 @@ end def TXUltimate_Short(value, trigger, msg) #print("message:") #print(msg) + import mqtt var Channel = msg['TXUltimate']['Channel'] var ind if Channel <= 3 @@ -22,36 +25,75 @@ def TXUltimate_Short(value, trigger, msg) #tasmota.cmd('Power3 2') tasmota.set_power(ind, ! tasmota.get_power(ind)) end + mqtt.publish(eventtopic .. "/Short", str(ind+1), false) +end + +def TXUltimate_Long(value, trigger, msg) + #print("message:") + #print(msg) + import mqtt + var Channel = msg['TXUltimate']['Channel'] + var ind + if Channel <= 3 + ind = 0 + #tasmota.cmd('Power1 2') + elif Channel >3 && Channel < 8 + ind = 1 + #tasmota.cmd('Power2 2') + else + ind = 2 + #tasmota.cmd('Power3 2') + end + mqtt.publish(eventtopic .. "/Long", str(ind+1), false) end def TXUltimate_Swipe(value, trigger, msg) #print("message:") #print(msg) + import mqtt var Action = msg['TXUltimate']['Action'] var targetstate if Action == 'Swipe right' targetstate = '1' var From = msg['TXUltimate']['From'] var To = msg['TXUltimate']['To'] - # Fix: Power0 manage all channels include backlight + mqtt.publish(eventtopic .. "/EVENT", "SwipeRight", false) + # NOTE: Power0 manage all channels include backlight tasmota.cmd('Power0 1') elif Action == 'Swipe left' targetstate = '0' var From = msg['TXUltimate']['From'] var To = msg['TXUltimate']['To'] - # Fix: Power0 manage all channels include backlight + mqtt.publish(eventtopic .. "/EVENT", "SwipeLeft", false) + # NOTE: Power0 manage all channels include backlight tasmota.cmd('Power0 0') end end -tasmota.remove_rule("TXUltimate#Action=Touch", "Touch") + +def TXUltimate_Multi(value, trigger, msg) + print("Handler Multi.") + #print("message:") + #print(msg) + import mqtt + mqtt.publish("stat/tasmota_E09620/EVENT", "Multi", false) + # tasmota.publish_result("{'Action': 'Multi'}", "EVENT") +end + +tasmota.remove_rule("TXUltimate#Action=Touch", "TXUltimate_Touch") tasmota.add_rule("TXUltimate#Action=Touch", TXUltimate_Touch, "TXUltimate_Touch") tasmota.remove_rule("TXUltimate#Action=Short", "TXUltimate_Short") tasmota.add_rule("TXUltimate#Action=Short", TXUltimate_Short, "TXUltimate_Short") +tasmota.remove_rule("TXUltimate#Action=Long", "TXUltimate_Long") +tasmota.add_rule("TXUltimate#Action=Long", TXUltimate_Long, "TXUltimate_Long") + tasmota.remove_rule("TXUltimate#Action=Swipe right", "TXUltimate_Swipe_right") tasmota.add_rule("TXUltimate#Action=Swipe right", TXUltimate_Swipe, "TXUltimate_Swipe_right") tasmota.remove_rule("TXUltimate#Action=Swipe left", "TXUltimate_Swipe_left") tasmota.add_rule("TXUltimate#Action=Swipe left", TXUltimate_Swipe, "TXUltimate_Swipe_left") +tasmota.remove_rule("TXUltimate#Action=Multi", "TXUltimate_Multi") +tasmota.add_rule("TXUltimate#Action=Multi", TXUltimate_Multi, "TXUltimate_Multi") +print("Events loaded.")