Sonoff Mini Modifications

Tags: #<Tag:0x00007f73a5f8fc30> #<Tag:0x00007f73a5f8fa28> #<Tag:0x00007f73a5f8f758>

LIGHTING | IRRIGATION | INPUT | TREATMENT | FILTRATION | SOLIDS

AQUAPONIC | PLC | SCREENS | SONOFF | myHome-Assistant Project

Sonoff Basic | [Sonoff Mini]

Sonoff Mini - My First Mods

Over the past 12 months I have found a lot of uses for modified Sonoff Basic devices but this is my first attempt to find some more uses for this new sonoff device.

After flashing Tasmota using the ‘solder 4 small leads on method’.
NOTE: Black is GND Red is 3.3V Yellow is TX and White is RX.

I moved on after a period of testing two flashed Mini’s for a while to have a go at setting one up to do a specific job which I have a Wemos D1 Mini doing at the moment. For a few reasons I have not been happy with the wemos performance so I was keen to see what the sonoff Mini could do!

In this project, what I need is to operate 3 lights (via a 4 relay module) and connect two PIR movement sensor modules.

First job was to setup the device to run on 5V power and connect to the available GPIO’s I was planning to use.

Step 1

Red is 5V supply, Black (on S_OUT) is GND supply, Orange is GPIO0, Yellow is GPIO2, Green is GPIO3 (RX) and Blue is GPIO1 (TX)

Step 2

Add Brown wire to connect to 3.3V which will be used to supply 2 X PIR Sensors and then arrange the wires to be brought outside the case for use in the project at hand.

DISCLAIMER: I am not (and never will be) using 240V at all on this sonoff Mini so having these wires pass by the 240V tracks is not an issue.

After that a small section was filed out of the case to allow the wires to pass neatly outside without being pinched as the case was closed up.

PHOTO COMING SOON: sorry but I missed the photo opportunity today.

Then the modified sonoff Mini was setup with the desired GPIO functionality and tested thoroughly with default settings from the Tasmota Flash prior to actually connecting to a 4 channel 5V Relay module and 2 X PIR sensor modules.

To setup the functionality in advance I used the ‘Configure Template’ interface in the sonoff web interface to setup GPIO’s required.

For now all you really need to know is that this is the area where you can setup how you want the GPIO’s to be used for your purposes. It’s also very good for prototyping a new project as you can chop and change as you are designing your new project.

What I’m connecting to.

On the relay board note the far right ‘JD’ terminal. Then note the bottom right GND, IN1, IN2, IN3, In4 and VCC terminals. See below for connection details.

Centre: 1.4mm 6 pin female header: GND = Black, IN1 = not connected (Spare), IN2 = Blue GPIO1, IN3 = Yellow (GPIO2), IN4 = Green (GPIO3) and VCC = Red (5V)

Right: I removed the yellow header jumper and connect the 5V to the ‘JD’ terminal.

Then when I open the ‘Main Menu’ and I see my sonoff Mini has 5 relays.

Relay 1 is the internal Mini Relay or GPIO12 while Relay 2 is GPIO1, Relay 3 is GPIO2, Relay 4 is GPIO3 and Relay 5 is GPIO5.

See Schematic below

Photo of the still prototype physical layout. Next step is to fabricate some PVC panels to improve the mechanical segregation of the 5V and 240V but there is plenty of space between them even though it may not look like that atm.

The sonoff Mini is tucked in behind and to the left end of a sonoff Basic which performs another separate task atm.
As of today this is day 2 of my new prototype period so I have tidied up the spaghetti a little.

But how does this all work?

Relay 1 (the internal sonoff Mini relay) is set to change state when PIR 1 detects movement and then simply going to be detected as a binary (Rumpus Occupied) sensor in HA. I dont actually use that relay for anything other than the MQTT messages it sends. However, it is actually good to hear that relay operate as I walk past to know things are working normally at the outside doorway.

Relay 2 will operate the Tank Pathway Light.

Relay 3 will operate the Patio Area Light

Relay 4 will operate Side Path 1 Light

Relay 5 is set to change state when PIR 2 detects movement on the Patio and then simply going to be detected as a binary (Patio Occupied) sensor in HA. The intersting thing about Relay 5 is that it is not actually connected to a physical relay. It doesn’t need to be as HA will still see the MQTT messages I require.

Project Cost

So in this project I have created a device that can operate 3 individual lights and sense movement in two separate areas using a $10 sonoff Mini. and a $7 relay module PLUS 2 HC-SR501 PIR sensors for $5…all up $22.

HA Config

To setup the lights I use:


light:
  - platform: mqtt
    name: "Patio"
    state_topic: "stat/sonoff33/POWER3"
    command_topic: "cmnd/sonoff33/POWER3"
    availability_topic: "tele/sonoff33/LWT"
    qos: 1
    payload_on: "ON" 
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false 

  - platform: mqtt
    name: "Tank"
    state_topic: "stat/sonoff33/POWER2"
    command_topic: "cmnd/sonoff33/POWER2"
    availability_topic: "tele/sonoff33/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "Side 1"
    state_topic: "stat/sonoff33/POWER4"
    command_topic: "cmnd/sonoff33/POWER4"
    availability_topic: "tele/sonoff33/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

Sonoff Rules

To setup the movement sensors I use “Rules” on my sonoff33 to send MQTT to the device I use to ‘Hold’ Occupancy Status.

sonoff33 Rule 1: Sends an 'Event' message to sonoff16
on power5#state=1 do publish cmnd/sonoff16/Event Movement_RUMPUS endon

sonoff16 Rule1: Receives an 'Event' message and holds 'Occupancy' status
on Event#Movement_rumpus do backlog power1 1; ruletimer1 240 endon on rules#timer=1 do power1 off endon


sonoff33 Rule 2: Sends an 'Event' message to sonoff13
on power1#state=1 do publish cmnd/sonoff13/Event Movement_Patio endon

sonoff13 Rule1: Receives an 'Event' message and holds 'Occupancy' status
on Event#Movement_Patio do backlog power1 1; ruletimer1 60 endon on rules#timer=1 do power1 off endon

Every time movement is detected the ruletimer is reset to start again (either 240 seconds in rule 1 or 60 seconds in rule 2)
If there is no further movement and as the ruletimer has counted down to 1 second remaining the power turns off.

On movement…the messages in the sonoff web interface at the Console will look like:

HA Config

To setup ‘Occupation’

binary_sensor:
  - platform: mqtt
    name: "Patio Occupied"
    state_topic: "stat/sonoff13/POWER"
    availability_topic: "tele/sonoff13/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    device_class: motion
  - platform: mqtt
    name: "Rumpus Occupied"
    state_topic: "stat/sonoff16/POWER"
    availability_topic: "tele/sonoff16/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    device_class: motion

Then I create automations to operate area lights on and off as required like:

#**********************************************************
# Patio Light Automation
# light.patio_occupied
#light.patio_bunker
#**********************************************************    
#light.patio_bunker Light: ON  
- id: PatioLightOnWhenOccupationSensedAndSunDown
  alias: Patio Light On When Occupied
  trigger:
    platform: state
    entity_id:  binary_sensor.patio_occupied
    to: 'on'
  condition:
    - condition: state
      entity_id: light.patio
      state: 'off' 
    - condition: state
      entity_id: binary_sensor.daylightsw_di_1day_0night
      state: 'off'     
  action:
    service: homeassistant.turn_on
    entity_id: light.patio


#light.Patio Light OFF after light.tank_path_occupied OFF after 1 min
- id: PatioLightOffWhenAreaBecomesUnoccupied
  alias: Patio Light Off when Unoccupied
  trigger:
    platform: state
    entity_id: binary_sensor.patio_occupied
    to: 'off'
    for:
      minutes: 1
  condition:
    condition: state
    entity_id: light.patio
    state: 'on'
  action:
    service: homeassistant.turn_off
    entity_id: light.patio    



#**********************************************************
# Rumpus Desk Light Automation
#light.rumpus_occupied
#light.rumpus_desk
#**********************************************************    
#light.rumpus_desk Light: ON#
- id: RumpusDeskLightOnWhenOccupationSensedAndSunDown
  alias: Rumpus Desk Light On When Occupied
  trigger:
    platform: state
    entity_id: binary_sensor.rumpus_occupied
    to: 'on'
  condition:
    - condition: state
      entity_id: light.rumpus_desk
      state: 'off' 
    - condition: state
      entity_id: binary_sensor.daylightsw_di_1day_0night
      state: 'off'     
  action:
    service: homeassistant.turn_on
    entity_id: light.rumpus_desk


#light.rumpus_desk Light OFF after light.rumpus_occupied OFF
- id: RumpusDeskLightOffWhenRoomBecomesUnoccupied
  alias: Rumpus Desk Light Off when Unoccupied
  trigger:
    platform: state
    entity_id: binary_sensor.rumpus_occupied
    to: 'off'
    for:
      minutes: 1
  condition:
    condition: state
    entity_id: light.rumpus_desk
    state: 'on'
  action:
    service: homeassistant.turn_off
    entity_id: light.rumpus_desk

NOTE: That an ‘ON’ and an ‘OFF’ automation needs to be made for each separate light you want to control within each area you monitor for ‘occupation’.

I hope the above may be useful for people here!

10 Likes

Hi, it is very nice. Can you send me more informations about sonnof Basic for more switch? I need Basic, Because i need RF.

Thank you

Tomas

1 Like

@tomaschrupka If you need the RF model Sonoff Basic you may find you don’t have many GPIO’s left for extra relays.
Others may confirm this if they are familiar with the RF model?

Anyone?

This is perfect i really like it. You squeeze maximum from this little guy. In my project i will be trying add second relay, motion detector and temperature humidity sensor. after i read your article i finally believe that it is possible

1 Like

Great work. Any possibility to share the wiring?
You hare using 3 sonoff. 1 mini and 2 basic?
Thanks

1 Like

@helio58 Yes I can share the schematic but I am a little busy atm…will try to get it done over the coming weekend and PM you when that is done.

@wellsy Thank you

I’d love to see how you wire this up. I am still learning the whole Sonoff/Tasmota/HA ecosystem before I take the plunge

1 Like

If you are not going to use 230V on this, why use a $10, require lots of soldering device instead of a cheaper ESP board ??? Or are you using the built-in PSU to power it, but not putting any load on the relay ?
A 8266 module with serial chip (power with MicroUSB) costs $2.80 - has pins to connect anything.

Well…As mentioned above I was just not happy with how the Wemos D1 Mini was performing doing the exact same task…The Sonoff Mini on the other hand has performed flawlessly from day one. I have 5 volt power supply already in that location. Using that to power the Sonoff Mini.

What was the problem with the D1 ? I know the difference is ESP8266 on some D1 vs ESP8285 in the Mini, that is 80 vs 160MHz. Or was the issue the antenna ? There is the D1 Mini Pro as well with external antenna (the main advantage of the Sonoff Mini as I see it).

I am looking at some DIY solution with HLK-PM01/PM03 as PSU, as there is very little room in wall outlets here. No room at all for the mini. By cutting a bit in the wall box I can just fit the shelly 1, which is smaller. But I have lamps that are 2 way controlled, and no Live at the lamp.

I out one mini in a lamp, and set it to power on when power gets back. Then I can monitor it, and use it for automation when it is powered on on the wall.

Now a D1 mini sized unit, and the independent PSU, I can fit into the wall. Have permanent power to the lamp (bypassing wall switch) with the mini. And use existing switch on the GPIO pins on a D1 to give me a dual wifi switch.

The problem was that it intermittantly became unresponsive and required a reboot to start working again. Very annoying and the exact same problem occurred on a second D1 which I swapped in. May have been due to the GPIO’s I was using…not really certain. Problem solved now using the Sonoff Mini.
PS: I do like the antenna on the Sonoff Mini…I think that makes it a very useful module for that reason alone. Seems very well made as well.

Love the Sonoffs I have been buying over the last couple years. Very good build quality. One friend even did a short on one with his garden lights, fuse blew. But the Sonoff just works.
Size is my major issue with the One Mini, way too big.
And I think the vendors should try to run GPIO pins out to solder pads.
220V on the switch port on the Shelly gives it other advantages as well, will use it with the PIR for garage light. Then that is the primary switch, but I can use other PIR or automation to have additional triggers.
Hope my D1 Minis will work. Really would be great to get things running more automated.

1 Like

Hi there, sorry for the lengthy delay but the Schematic has been posted now.

Cheers for your interest!

Steve Wells

Hello everyone,
is it possible to modify the sonoff mini and use the output likes isolated relay output with NO contacts?

Good idea! I’ll use a similar mod at my home.

@alexvr32 yes it is as I have explained above (using the 4 relay module). You just need to purchase a 5V Low Level Trigger One 1 Channel Relay Module Interface Board like this one:

Hook up 5V to VCC and GND to GND and then use a GPIO of your choice to trigger the relay on IN.

These type of modules are cheap and very reliable and have NO and NC contacts to use however you wish.

PS: try EBAY, Banggood, AlieExpress, Amazon, etc.

Hi, I connected all cables but PIR hc-sr501 continues to send signal up (3.3V) and down (1.6V) every two seconds. How does yours works?

Somewhat old post, but one of the first that shows up on google, so might be useful to have the information in here as well…

Could you verify whether S1/S2 end up at mains voltage if the device is powered from a 240 V supply?
Obviously if it’s embedded and there isn’t another one around then fret not, I should have one in a couple of weeks…