TASMOTA Rules - Inter-lock Sonoff 4CH Pro Channels

2,079 views
Skip to first unread message

Michael Ingraham

unread,
Jul 12, 2018, 4:51:26 PM7/12/18
to SonoffUsers
I have several ceiling fans which I want to connect to my home automation hub (openHAB) and be able to control via the mobile app or via Google Assistant.

A Sonoff 4CH Pro is ideal for the four functions each of them has: the fan light and three fan speeds.I cannot use the 4CH Pro inter-locking mode (only one relay turns on at a time based on the button input) because some fans require more than one contact to be connected simultaneously for achieving some of the speed settings. Also, If I want to turn on the fan and also have the fan light on, the 4CH inter-locking mode would not allow those outputs on simultaneously. For these reasons, I am using the 4CH switches in self-locking mode... even when the particular brand of fan uses a single contact scheme for the fan speed.

Our ceiling fans are manufactured by three different companies: Hunter, Hampton Bay, & Harbor Breeze. These fans use two types of 4-position speed control switches. The connections for different types of fans:

Hunter
Low: Ch.1
Med: Ch.1 & Ch. 2
Hi: Ch.3
Light: Ch. 4

Harbor Breeze
Low: Ch.1
Med: Ch. 2
Hi: Ch.3
Light: Ch. 4

I haven't cracked open my Hampton Bay wiring yet, but I'm sure the fan speed switch falls into one of the two categories - single-contact (e.g., Harbor Breeze) or multi-contact (e.g. Hunter).

I would like to set up rules in the TASMOTA firmware to "prohibit" certain combinations of relays from being turned on simultaneously. The rules would vary slightly for each brand of fan connected.
Hunter: inter-lock Ch.1, & Ch. 3
Harbor Breeze: inter-lock Ch.1, Ch.2, & Ch. 3

1. Can "inter-lock" rules be implemented in TASMOTA?
2. I've never written a TASMOTA rule... so would appreciate any and all examples.

Thanks in advance.

Mike

Philip Knowles

unread,
Jul 13, 2018, 2:18:56 AM7/13/18
to Michael Ingraham, SonoffUsers

Do the logic in openHAB. I have a cooker hood with 3 speeds and a light (uses same scheme as your Harbor Brezze) so I can't use the interlock to only have 1 output on at a time. In my case I've connected an AM2301 temperature and humidity sensor to the 4ch and it switches on the light and low speed fan (ch1). If the humidity doesn't reduce it moves to the next rule which first switches off the fan output and then switches on the next speed (ch2) and so on for the third speed. The fan momentarily hesitates but is actually no different to normal pushbutton mode. In the sitemap I use a setpoint so I can manually control the speed via the app.
If you wish I'll send you the relevant items, rules and sitemap


--
You received this message because you are subscribed to the Google Groups "SonoffUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Ingraham

unread,
Jul 13, 2018, 10:17:45 AM7/13/18
to SonoffUsers
Philip,

Thanks for the openHAB details. Lots of good ideas I can file away for my own hub implementation.

I should have been more thorough in my original post.

I have the automation and inter-lock rules set up in openHAB with the appropriate rules to handle the different fan speed selections. Setting the fan speed them via the openHAB mobile app or via Google Assistant openHAB integration allows me to set the channels explicitly and there is no fear of improperly settings for the fan speed relays.

The reason I wanted to add rules in TASMOTA is that I am accounting for someone making a selection via the 4CH itself (via an RF remote control) rather than via openHAB. I want to allow this because when we have guests, I don't expect them to know know the Google Assistant voice command "syntax" and they won't have access to openHAB via the GUI. With the RF remote, I've assigned each speed and the light to each button on the remote.

The RF remote is essentially equivalent to pressing the buttons on the 4CH Pro itself. What happens is that it toggles the relay for the associated channel. That results in a status message being sent to openHAB which triggers the rule ensuring the appropriate inter-lock which results in turning on or off the speed as selected via the remote. For example: if fan is off and button C is pressed, set to high speed (ch. 3 - all done); if on high and button B is pressed, set to medium speed (ch.2 and ch. 3 are now on so turn off ch. 3 and turn on ch. 1 <Hunter fan>); etc.

I have the automation functioning as desired. For whatever reason, it sometimes takes 3-4 seconds for openHAB to respond to the state change event and complete sending the appropriate commands to ensure the relays end up in the requested state for the speed requested on the remote control.

On the Hunter fan, I'm not as concerned because having multiple "wrong" relays on actually only sets a slightly different speed based on the "selection" of the capacitor circuitry. In the Hunter fan circuitry, this is actually allowed. I could even play with permutations of speeds beyond the normally available three. I'm not ;-) The speeds aren't that different and why add confusion; three speeds is all that is needed.

My real concern is on the Harbor Breeze fan where I don't have insights into how the windings and associated capacitors are wired. No amount of searching for the model number or even generic Harbor Breeze has resulted in a diagram or schematic. However, assuming that since the pull-chain switch does not turn on more than one circuit at a time, I want to ensure that I emulate it as much as possible. Having more than one circuit path completed/closed for 3-4 seconds is what concerns me. My intent with the TASMOTA rule in the switch itself will ensure near instantaneous switching of the relays to avoid having multiple relays latched for any significant amount of time.

Thus, finally <grin>, why I want to configure rules into the 4CH. I should have included this in the original post.

So, I still need some guidance:

  1. I believe that the answer to my first question is yes in that one trigger event (a relay comes on) can "do" multiple commands (set the other two accordingly based on the type of fan).
  2. I still have no clue how to write the rules syntax to "see the separate trigger events for each relay (PowerN) nor how to actually implement them in the switch. I have compiled the firmware uploaded to the 4CH with USE_RULES.

Regards.

Mike
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Michael Ingraham

unread,
Jul 13, 2018, 10:25:35 AM7/13/18
to SonoffUsers
Further... I've investigated using ButtonTopic so that the switch does not control the relay except by sending an MQTT to openHAB which then sends back the appropriate MQTT to actually set the relays. I am thoroughly baffled about how to set up TASMOTA to use ButtonTopic for this operating mode... plus, with using rules, the fan can operate "manually" even if openHAB is out of commission for any reason.

Michael Ingraham

unread,
Jul 13, 2018, 2:38:18 PM7/13/18
to SonoffUsers
Philip,

"never had the courage to try it" - my sentiment exactly. I'd add, I've not had the fortitude to work through the frustration ;-)

It seems that the choice of what function the buttons perform is a personal preference ;-) I am always frustrated by the pull-chain and never knowing how many pulls to make to figure out if I've selected the speed I want or if I've actually turned the fan off. Once the fan is spinning, it's sometime difficult to know when the speed is changing to the desired speed or slowing to a stop altogether. That's why I decided to implement my automation buttons as a direct speed setting rather than speed up or speed down. Yes, having both up and down speed control removes a bit of the hit or miss frustration... but I still prefer the direct setting of the speed (or off directly) as long as I have only four things to control and I have four buttons to do so. Again, personal preference.

Hopefully I can get TASMOTA rules implemented (and get some much needed assistance from this community).

Cheers!

Mike


On Fri, Jul 13, 2018 at 11:58 AM Philip Knowles wrote:

Me too I’ve come to the conclusion ButtonTopic is for devices with one buttonand allocating a command to it.

I think it is possible to, essentially, break the link between the pushbutton and relay by using gpio(pin_ and sensor but never had the courage to try it.

I can agree with your thoughts about manual control when openHAB down – I have a micro PC on a UPS using a ESP-01 as a watchdog which triggers if openHAB or Mosquitto goes down. If I was using the rf remote I would have top left button configured turn light on and bottom left turn light off and top right increase fan speed and bottom right decrease fan speed. The rules then become a bit simpler (you don’t need to interlock can use ones like mine)  and the remote is a bit more elegant. Yes you have the issue of what happens when openHAB goes down but you sort of have that problem with a clean recovery when it comes back up.


Michael Ingraham

unread,
Jul 19, 2018, 1:22:22 AM7/19/18
to sonof...@googlegroups.com
Success!

Here are the three rules. Each rule is a variation of the toggling rule in the TASMOTA Rules wiki page examples. This rule set is for the Hunter fan which has the need to turn on two channels for Medium (Rule 2) but only one channel for either low or high. For my Harbor Breeze and Hampton Bay fans, each fan speed needs at most one relay latched. That rule set is a pretty straightforward variation of this set of rules.

I broke the rule syntax up into multiple lines for readability. The rule needs to be entered in the TASMOTA Console as a single line. I have included the "single line" rules as well for proper reference.

Rule1 on BUTTON1#State do
        Event toggling1=%var1%
      endon
      on event#toggling1<1 do
        Backlog
            Power2 OFF
          ; Power3 OFF
          ; Power1 ON
          ; var1 1
          ; var2 0
          ; var3 0
      endon
      on event#toggling1>0 do
        Backlog
            Power1 OFF
          ; Power2 OFF
          ; Power3 OFF
          ; var1 0
          ; var2 0
          ; var3 0
      endon

Rule1 on BUTTON1#State do Event toggling1=%var1% endon on event#toggling1<1 do Backlog Power2 OFF; Power3 OFF; Power1 ON; var1 1; var2 0; var3 0 endon on event#toggling1>0 do Backlog Power1 OFF; Power2 OFF; Power3 OFF; var1 0; var2 0; var3 0 endon

Rule2 on BUTTON2#State do
        Event toggling2=%var2%
      endon
      on event#toggling2<1 do
        Backlog
            Power3 OFF
          ; Power1 ON
          ; Power2 ON
          ; var1 0
          ; var2 1
          ; var3 0
      endon
      on event#toggling2>0 do
        Backlog
            Power1 OFF
          ; Power2 OFF
          ; Power3 OFF
          ; var1 0
          ; var2 0
          ; var3 0
      endon

Rule2 on BUTTON2#State do Event toggling2=%var2% endon on event#toggling2<1 do Backlog Power3 OFF; Power1 ON; Power2 ON; var1 0; var2 1; var3 0 endon on event#toggling2>0 do Backlog Power1 OFF; Power2 OFF; Power3 OFF; var1 0; var2 0; var3 0 endon

Rule3 on BUTTON3#State do
        Event toggling3=%var3%
      endon
      on event#toggling3<1 do
        Backlog
            Power1 OFF
          ; Power2 OFF
          ; Power3 ON
          ; var1 0
          ; var2 0
          ; var3 1
      endon
      on event#toggling3>0 do
        Backlog
            Power1 OFF
          ; Power2 OFF
          ; Power3 OFF
          ; var1 0
          ; var2 0
          ; var3 0
      endon

Rule3 on BUTTON3#State do Event toggling3=%var3% endon on event#toggling3<1 do Backlog Power1 OFF; Power2 OFF; Power3 ON; var1 0; var2 0; var3 1 endon on event#toggling3>0 do Backlog Power1 OFF; Power2 OFF; Power3 OFF; var1 0; var2 0; var3 0 endon

And don't forget to turn the rules on:
Backlog Rule1 1; Rule2 1; Rule3 1

Regards.

Mike

Alexandre Capcom

unread,
Feb 20, 2019, 12:52:25 PM2/20/19
to SonoffUsers
Hello, very good explanation, could you show me the configuration of openhabian? Thank you!

Em quinta-feira, 19 de julho de 2018 02:22:22 UTC-3, Michael Ingraham escreveu:
Success! Fortunately, I only need to inter-lock three channels... for which there are just enough TASMOTA rule "slots" available. Each rule uses 241 characters of the available 511.

Michael Ingraham

unread,
Feb 20, 2019, 2:09:58 PM2/20/19
to SonoffUsers
Items
String      ceiling_fan_speed
String      ceiling_fan_setSpeed { mqtt=">[broker:cmnd/fan/event:command:*:default]" }


Sitemap
Frame label="" icon="none"
{
   
Selection   item=ceiling_fan_speed
                label
="Fan Speed"
                icon
="fan_ceiling"
                mappings
=["OFF"="Off", "LOW"="Low", "MEDIUM"="Medium", "HIGH"="High"]
}


Rule
rule "Send Fan Speed"
when
   
Item ceiling_fan_speed received command
then
    val
String sFanState = receivedCommand.toString
   
if (sFanState == "OFF")    { ceiling_fan_setSpeed.sendCommand("toggling1=1") }
   
if (sFanState == "LOW")    { ceiling_fan_setSpeed.sendCommand("toggling1=0") }
   
if (sFanState == "MEDIUM") { ceiling_fan_setSpeed.sendCommand("toggling2=0") }
   
if (sFanState == "HIGH")   { ceiling_fan_setSpeed.sendCommand("toggling3=0") }
end



Alexandre Capcom

unread,
Feb 20, 2019, 3:04:09 PM2/20/19
to SonoffUsers
Wow what a fast response, thank you!
I'm getting out of hassio, a lot of problems related to mqtt and remote access, so I'm liking openhabian.

Alexandre Capcom

unread,
Feb 23, 2019, 1:43:36 PM2/23/19
to SonoffUsers
Hello Michael, it worked out perfectly, now to make it more interesting, I am putting a button on the GPIO02 to turn on the fan and each click increases the speed, and then also turns off in the 4th click, what do you think of the idea? Could I just do that with rules on Sonoff 4ch?


Em quarta-feira, 20 de fevereiro de 2019 16:09:58 UTC-3, Michael Ingraham escreveu:

Michael Ingraham

unread,
Feb 23, 2019, 4:00:37 PM2/23/19
to Alexandre Capcom, SonoffUsers
Alexandre,

Careful with using GPIO2 as it needs to be in a particular state (high or low, I don't recall which) at power up to allow the ESP8285 to boot up properly. I just stick to the four buttons on the 4Ch and also pair my RF remote control to those same buttons.

I opted for setting the of speed directly rather than cycling through the speeds with each "click". The problem I always have is I can never tell the difference whether the fan is on high or medium, or low or medium. So I always end up trying to set the speed twice. The first time I go past where I wanted. Then I realize I've selected the wrong speed and I then cycle the right number of speed settings. In my configuration, I can set a desired speed directly. I also have a Dimmer Item in openHAB so I can say "turn up"/"turn down". This let's me "cycle" up or down. So I can do both.

On the RF remote for the 4Ch. The first button is Off. The second chooses slow. The third medium. The fourth High. I plan on testing long press to see if I can detect that (on any button) and send an "speed off" and free up the fourth button for the fan light.

Further... I have fans from two manufacturers.

One type of fan uses the scheme:
  1. Channel 1 only - Low
  2. Channel 1 & 2 - Medium
  3. Channel 3 only - High

The other type of fan uses:
  1. Channel 1 only - Low
  2. Channel 2 only - Medium
  3. Channel 3 only - High

For the second type of fan, you could use the Interlock feature ('Interlock 1,2,3') available in the latest development version of TASMOTA. This way you only need to send On/Off to the channel you want to select for the speed... and the Interlock will make sure the "unused" channels get turned off for you. In fact, for the first brand of fan, I also use 'Interlock 1,3' and just worry about "managing" "medium" as a special case.

Mike


Reply all
Reply to author
Forward
0 new messages