Close
0%
0%

Internet Accessible Home Automation with Sonoff

Create a home automation gateway, you can access from anywhere, using a Raspberry PI, Sonoff switches with Tasmota and FlashLex.

Public Chat
Similar projects worth following
Making a home automation system shouldn't give a giant or foreign company information on how my home works. I also want something hackable and based on "off the shelf" components I can buy online with little work. This project lets you put a home automation system on the internet securely using a Raspberry Pi, Sonoff switches running the Tasmota firmware and the FlashLex IoT platform. https://flashlex.com/project/sonoff-switch/

Overview

This guide provides instructions, code and components on how to build a internet enabled home automation system that allows scheduled control of multiple sonoff wifi enabled switches as well as routed control messages over the internet using the FlashLex IoT internet gateway.  

Architecture Elements

  • FlashLex API - Cloud platform to route messages to your thing.
  • The Thing - Your Raspberry PI IOT Device
    • FlashLex SDK App - Python service that will take messages from the thing's topic and store them locally.
    • Sonoff Switch App - Python service that listens to messages and will execute Sonoff commands by device name, also schedules commands to items.
  • Sonoff WIFI Switch - Independent In Line switches that are individually addressable on a local wifi network

Steps for Tasmota Installation

This isnt a Tasmota installation tutorial, there are tons of links above to get going on that. This is a cookbook for enableing your home automation hub to be a FlashLex device, so we will limit the instructions to that.

Important Links

Using esptool to flash Tasmota

Remember to hold the button down on the sonoff to put it in firmware update mode.

python3 -m venv ./venv
source venv/bin/activate
python
pip install esptool
pip install --upgrade pip
esptool.py -h
ls -l /dev/tty.usb*
esptool.py -p /dev/tty.usbserial-A50285BI write_flash -fs 1MB -fm dout 0x0 sonoff_6_6_0.bin

Installing the FlashLex Service

All the FlashLex projects rely on the FashLex SDK, which collects messages from the gateway using a locally running Python service. More information on installing the FlashLex service can be found in the FlashLex Docs.

Installing FlashLex SDK

The Sonoff Scheduler Hub Backend

Devices are managed and scheduled by code on the your FlashLex thing that sends commands to the individual sonoff switches over wifi. Essentially the sonoff switch software both automates scheduling of commands as well as provides a message manager for sending commands to your sonoff switches.

Sonoff Switch Commands

Message SyntaxSonoff SyntaxDescription
onPower%20onTurn the switch on.
offPower%20offTurn the switch off.
togglePower%20TOGGLEToggle the switch state.

Sonoff Scheduler Links

The Scheduler Config

For each switch that your scheduler will control provide an entry and the the schedule as well as the command you would like to send.

devices:
  - name: living-room
    ip: 192.168.8.59
    schedule:
      - time: "17:00"
        command: Power%20on
      - time: "23:41"
        command: Power%20off
      - time: "06:30"
        command: Power%20on
      - time: "07:54"
        command: Power%20off
  - name: bedroom-01-tv
    ip: 192.168.8.199
    schedule:
      - time: "19:30"
        command: Power%20on
      - time: "01:01"
        command: Power%20off
  - name: bedroom-01-lamp
    ip: 192.168.8.66
    schedule:
      - time: "17:00"
        command: Power%20on
      - time: "23:41"
        command: Power%20off
      - time: "06:30"
        command: Power%20on
      - time: "07:54"
        command: Power%20off

Creating the sonoff-switch service

You will want to have your sonoff switch running as a service so that even if your Raspberry Pi restarts it will come back up. To enable your sonoff-switch hub to run as a service install the service file and enable the service with systemctl.

$(pwd)/venv/bin/python3 makeservice.py -d $(pwd) \
   -t sonoff.service.mustache > sonoff.service

Instructions...

Read more »

  • Working in My House

    Clay Graham12/26/2019 at 21:07 0 comments

    So I managed to get the entire system up and running in my house. Right now I just use the Tasmota UIs to manually turn stuff on and off but i would love some battery powered wifi switches so my girlfriend would stop manually turning them off. Maybe that's another project. :)

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates