HomeAssistant shuttercontrol with Sonoff 4CH Pro

From OISecWiki


I wanted to control my shutters with homeassistant, mainly to make them go up and down automatic at preset times. This can be done with a SonOff. Most people selected the SonOff dual for this task, but it has no mechanical/electrical protection to prevent from both outlets to be powered on at the same time. I was a bit weary about this because a software glitch may damage the shutter motors.  The SonOff 4CH Pro has relays with 2 outputs (NC/NO/COM) which makes it possible to mechanically/electrically only have 1 output on at the same time, thus making sure a software glitch would not fry the shutter motors. So i've selected the 4CH Pro. In my case this adds an extra benefit and that is I have 2 shutters next to each others, which I could drive now with only 1 SonOff. Still hoping SonOff releases a 2CH Pro :)

Flashing the SonOff 4CH Pro with Tasmota

Connecting to serial

If you have a 3.3v FTDI you have to solder on 1 header. If you have a 5V FTDI and an external power source (like me) solder on 2 headers.

One 5 pin header goes on the ESP program header.

The other 4 pin header goes on the top STM32 program header.

Connect the RX/TX/GND header on the ESP pin header, and connect 3.3V + GND on the STM32 header.

You should be good to go now.

Flash mode

The Sonoff 4CH Pro has an alternative method of getting into firmware upload mode. Normal SonOff's use one off the trigger buttons, while on the SonOff 4CH Pro GPIO0 has to be shorted to ground. (source).  Ground GPIO0 for at least 3 seconds when applying power.

Flashing

Download the sonoff.bin file from tasmota's github and prepare esptool to flash it.

esptool.py --port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 sonoff.bin

Connecting the shutters

The shutters have 4 wires (NEUTRAL, PE, LOAD_UP, LOAD_DOWN). They are to be connected as following:

RELAY1 NC - empty

NO - jumper wire to RELAY2 COM

COM - 230V

RELAY2 NC - Shutter 1 LOAD_UP

NO - Shutter 2 LOAD_DOWN

COM - jumper wire to RELAY 1 NO

RELAY3 NC - empty

NO - jumper wire to RELAY4 COM

COM - 230V

RELAY4 NC - Shutter 2 LOAD_UP

NO - Shutter 2 LOAD_DOWN

COM - jumper wire to RELAY 3 NO

I've used some WAGO's to connect RELAY 1 COM, RELAY 2 COM, sonoff load and the mains load together, another WAGO is used to connect the mains neutral, sonoff neutral and the shutters neutral. A third wago is used to connect up all the protective earths.

Configuring Home Assistant

Setup MQTT in home assistant and let the SonOff connect to it. It should publish the switches to home assistant as long as discovery is true.

Too manually switch them one, add the following to configuration.yaml:

input_boolean:

  rolluiken_up:

    name: INP Rolluiken Omhoog

    initial: off

    icon: mdi:lightbulb

  rolluiken_down:

    name: INP Rolluiken Omlaag

    initial: off

    icon: mdi:lightbulb

These enable manual input switches in the frontend to start the automations that will control the shutters.

In my case I want to control both shutters at the same time, so my automations.yaml looks like this:

automations.yaml
- id: auto_rolluiken_omhoog

  alias: Rolluiken Omhoog   trigger:   - entity_id: input_boolean.rolluiken_up     platform: state     to: 'on'   action:   - data:       entity_id: switch.sonoff3     service: switch.turn_on   - data:       entity_id: switch.sonoff     service: switch.turn_on   - data:       entity_id: switch.sonoff2     service: switch.turn_on   - data:       entity_id: switch.sonoff4     service: switch.turn_on   - delay: 00:01:00   - data:       entity_id: switch.sonoff     service: switch.turn_off   - data:       entity_id: switch.sonoff2     service: switch.turn_off   - data:       entity_id: switch.sonoff3     service: switch.turn_off   - data:       entity_id: switch.sonoff4     service: switch.turn_off - id: auto_rolluiken_omlaag   alias: Rolluiken Omlaag   trigger:   - entity_id: input_boolean.rolluiken_down     platform: state     to: 'on'   action:   - data:       entity_id: switch.sonoff3     service: switch.turn_on   - data:       entity_id: switch.sonoff     service: switch.turn_on   - data:       entity_id: switch.sonoff2     service: switch.turn_off   - data:       entity_id: switch.sonoff4     service: switch.turn_off   - delay: 00:01:00   - data:       entity_id: switch.sonoff     service: switch.turn_off   - data:       entity_id: switch.sonoff2     service: switch.turn_off   - data:       entity_id: switch.sonoff3     service: switch.turn_off   - data:       entity_id: switch.sonoff4     service: switch.turn_off

I didn't want the relays to keep providing power to the motors. So after 1 minute it disables those, you might have to change this to suit your own needs. Most shutters should be down or up in at most 30 seconds