Code Monkey home page Code Monkey logo

sonoff-basic-openhab's Introduction

A Sonoff Basic firmware to work with openHAB

This firmware drives Sonoff Basic from iTead Studio, and powered by Mongoose OS. It targets to work with openHAB 2.4 or newer using the MQTT binding.

Features

  • LED blink pattern to indicate connectivity
  • On board button to toggle the switch manually in case of no connectivity
  • Bounce protection
  • Device local schedule timer
  • Countdown timer to toggle the switch
  • Switch ON duration counter for energy consumption analysis
  • Night Mode to turn off status LED
  • Web interface for setting up WiFi SSID and password
  • Reset to firmware defaults by holding the on board button for over 5 seconds

Configuration options

You have 2 options to implement this firmware:

  1. automatic configuration by Homie Convention

Homie Convention enables auto-discovery of the device by openHAB. Things, Channels and Items will be automatically setup.

  1. manual configuration with text files

openHAB UI

openHAB UI

energy consumption chart

Build for Homie support

Build using default cloud service:

cat mos-homie.yml > mos.yml
mos build --platform esp8266 \
  --build-var FLASH_SIZE=1048576 --build-var BOARD=esp8266-1M

Build for manual configuration

Build using default cloud service:

cat mos-manual.yml > mos.yml
mos build --platform esp8266 \
  --build-var FLASH_SIZE=1048576 --build-var BOARD=esp8266-1M

Flash

Sonoff Basic has only 1Mbytes flash.

mos flash --esp-flash-params "dout,8m,40m"

WiFi Setup

  1. Switch your PC or smartphone to the device's WiFi network. The SSID is named like Sonoff_??????, and the password is SonoffBasic.

  2. Use your browser to open http://192.168.4.1/

openHAB Configuration

If you choose the manual configration option, please check the manual folder.

Local schedule timer

Before using the local timer, make sure to set correct time zone via timer.tz.

For Example, a Hong Kong user:

mos config-set timer.tz=+0800

And a user in California (DST):

mos config-set timer.tz=-0700

Then, create a JSON file schedules.json and upload to the filesystem. Please reference the supplied sample for syntax.

Countdown timer

When the countdown timer reached zero, the switch will be toggled.

The local schedule timer will be disabled until the countdown is completed.

This timer is not persisted across reboots.

Night Mode

Example: set night mode from 23:00 to 6:30:

mos config-set nm.enable=true nm.bh=23 nm.bm=0 nm.eh=6 nm.em=30

Reset to firmware defaults

Press and hold the on board button for over 5 seconds.

sonoff-basic-openhab's People

Contributors

cpq avatar michaelfung avatar scaprile avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sonoff-basic-openhab's Issues

Autodiscovery on openHAB 2.4+

Hi,
I have modified init.js so the device announces and behaves according to the Homie convention 4.0.0. This way, openHAB automatically discovers the thing and channels are added with just a mouse click.
Even though modifications in init.js can be considered trivial, the openHAB part of the example will not work with this new code, and reworking it or providing for dual functionality will require some time I can't devote to it. (Some users still run the 1.x binding and don't care about auto-discovery)
I wonder if branching this example is possible. Otherwise, I can just publish a fork with my mods on my account and let a comment pointing to it here.
Regards

Flash sonoff with mongoose os via wifi

Tell me please, is it possible to flash sonoff with mongoose os via wifi without any wires?
Or how i can generate .bin with MOS file and upload it with OTA mechanism?
Thanks, for help.

Frequent core dump

Boot Log:

esp_main.c:172 openhab_sonoff_basic 1.1_20200227r3 (20200227-120849/t1-7-ge0cea59-master-dirty)
esp_main.c:174 Mongoose OS 2.17.0 (20200227-120849/2.17.0-gc31a745)
esp_main.c:178 CPU: ESP8266EX, 160 MHz, RAM: 52248 total, 47504 free
esp_main.c:180 SDK 2.2.1(1247cc5); flash: 1M
esp_exc.c:211 Reset cause: 4 (soft reset)
mg_lwip_ev_mgr.c:77 Mongoose 6.16, LwIP 1.4.1
mg_ssl_if_mbedtls.c:57 mbed TLS 2.16.3-cesanta9
mgos_vfs_dev.c:73 sfl0: sysflash (), size 1048576
mgos_vfs_dev.c:73 root: part ({"dev": "sfl0", "offset": 897024, "size": 131072}), size 131072
mgos_vfs.c:174 /: SPIFFS @ root, opts {"bs":4096,"ps":256,"es":4096}
mgos_vfs.c:347 /: size 113201, used: 107930, free: 5271
mgos_sys_config.c:232 Loading conf9.json
mgos_sys_config.c:316 Sending logs to UDP 192.168.0.1:514
esp_debug.c:56 UDP log set up to 192.168.0.1:514
mgos_sys_config.c:366 MAC: 5e:cf:7f:a7:f6:3d
mgos_sys_config.c:374 WDT: 30 seconds
bcn 0
del if1
del if0
usl
mode : null
mgos_wifi.c:88 WiFi STA: Using config 0 (MYSSID)
mgos_wifi.c:468 WiFi mode: STA
esp_wifi.c:108 WiFi mode: STA
mode : sta(5c:cf:7f:a7:f6:3d)
add if0
sleep disable
mgos_wifi.c:270 WiFi STA: Connecting to MYSSID
mgos_http_server.c:343 HTTP server started on [80]
mgos_rpc_channel_ua:313 0x3fff174c UART0
mgos_init.c:36 Init done, RAM: 52248 total, 42856 free, 42864 min free

Log around crash:

init.js:228 Published:OK topic:sonoff_basic/a7f63d/state msg:{"cdt":"OFF","sch_enable":"ON","skip_once":"OFF","oncount":0,"relay_state":"OFF","mem
ory":29368,"uptime":15002.169043}
init.js:228 Published:OK topic:sonoff_basic/a7f63d/state msg:{"cdt":"OFF","sch_enable":"ON","skip_once":"OFF","oncount":0,"relay_state":"OFF","mem
ory":29368,"uptime":15302.169134}
init.js:228 Published:OK topic:sonoff_basic/a7f63d/state msg:{"cdt":"OFF","sch_enable":"ON","skip_once":"OFF","oncount":0,"relay_state":"OFF","mem
ory":29368,"uptime":15602.169967}
init.js:119 Countdown timer disabled
init.js:228 Published:OK topic:sonoff_basic/a7f63d/state msg:{"cdt":"OFF","sch_enable":"ON","skip_once":"OFF","oncount":0,"relay_state":"ON","memo
ry":29008,"uptime":15736.752359}
init.js:119 Countdown timer disabled
init.js:228 Published:OK topic:sonoff_basic/a7f63d/state msg:{"cdt":"OFF","sch_enable":"ON","skip_once":"OFF","oncount":4,"relay_state":"OFF","mem
ory":29000,"uptime":15741.059476}
mac 684

HW WDT @ 0x40102880
A0: 0x40102880 A1: 0x3ffffd10 A2: 0x00000008 A3: 0x00000000
A4: 0x00000000 A5: 0x60000000 A6: 0x00000003 A7: 0x3ffffc43
A8: 0x00000000 A9: 0x00000000 A10: 0x00000000 A11: 0x00000000
A12: 0x00000048 A13: 0x7fffffff A14: 0x00000002 A15: 0x00000148

(exc SP: 0x3ffffb50)

--- BEGIN CORE DUMP ---
{"app": "openhab_sonoff_basic", "arch": "esp8266", "version": "1.1_20200227r3", "build_id": "20200227-120849/t1-7-ge0cea59-master-dirty", "build_image": "dock
er.io/mgos/esp8266-build:2.2.1-1.5.0-r5",
"REGS": {"addr": 1073740672, "data": "
gCgQQBD9/z8IAAAAAAAAAAAAAAAAAABgAwAAAEP8/z8AAAAAAAAAAAAAAAAAAAAASAAAAP///38CAAAASAEAAIAoEEAEAAAAAAAAAAAAAAAAAAAAMAAAAA==", "crc32": 1360293999},
"DRAM": {"addr": 1073643520, "data": "
voEhQAAAAAAQgP4/AAAAAAIAAAD8gv4/ZIP+P8yD/j8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK2iBAAQAAADDNIUBkEP8/AAAAANx3/z+8D/8/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJ+hlrfX/wMiDjPNqzQSbebs3gUACwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AA

Changes to build under newer releases

Hi,
mos.yml requires a manifest_version entry
manifest_version: 2017-05-18
and main.c requires changes in the include paths:

#include "mgos_app.h"
#include "mgos_gpio.h"
#include "mgos_sys_config.h"
#include "mgos_timers.h"
#include "mgos_hal.h"
#include "mgos_dlsym.h"
#include "mgos_mqtt.h"
#include "mjs.h"
#include "common/cs_dbg.h"

The OpenHAB example setup works on 1.x bindings, the newer 2.4+ mqtt binding with the things binding requires you to setup a broker, then add a Generic MQTT Thing, then a channel, and then you can setup your switch item:

Switch Bedroom_Lights_Switch {channel="mqtt:topic:mythingid:mychannelid"}

All other items are a bit more involved and I guess at this time following one of the supported conventions for autodiscovery is worth it.
Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.