Hass.io Add-on: Sonoff Server / Sonoff no need of flash

Hi there, this is my working in progress addon for ha, is a sonoff server based on https://github.com/mdopp/simple-sonoff-server

you can add sonoff devices and configure name for every channel in case you have multichannel device

Setup a new device
There are two ways of setting up the devices. Either with the sonoff.setupdevice.js script, or with wget (or anything else that can post an http request to a specific server).

currently just wget works

sonoff.setupdevice.js
Start sonoff.setupdevice.js on a computer you like. It will connect to the SONOFF device, so you will lose internet connection. When the scripts runs, you must long-click the black button on the device, and it will be configured to use the “server” as its cloud. Which now runs in your own network.

To run this on a linux device, the network manager must be installed. On an raspberry pi I would suggest to do the setup process manually with wget.

wget

Put the SonOff/Wemos device in AP mode (press and hold button for 5s)
Find the device and connect to it (SSID: ITEAD-10000xxxxx Password: 12345678)
Add route if necessary sudo route change 0.0.0.0 mask 0.0.0.0 10.10.7.1
(optional) use wget to read device info wget -O- 10.10.7.1/device
use wget to send local WiFi settings to device wget -O- --post-data=’{“version”:4,“ssid”:“yourSSID”,“password”:“yourSSID_PASSWORD”,“serverName”:“n.n.n.n”,“port”:1081}’ --header=Content-Type:application/json “http://10.10.7.1/ap”
The device will automatically drop out of AP mode and tries to connect to WiFi and server.

Web UI for name config
http://HASSIOIP:1080

this is the custom component for the addon
https://gist.github.com/gerswin/0cac4f8df4a947b0fec196b84a5e8d8b

20 Likes

Great work, it’s not for me but I’m surprised you haven’t had any thanks from the ‘don’t want to flash’ group.

Obviously won’t keep the ones who still want to use the eWelink app happy but I don’t think anything that’s likely to happen will :slight_smile:

2 Likes

I added the custom component.
However, it seem to be missing the following file “sonoff.ha.json”.
What is that file exactly and where can I get an exemple of it ?

tx,

sorry, i will fix that, create a sonoff.ha.json with the content of youip:1080/hadevices

Sorry, but how to setup server? Do i need to install simple-sonoff-server or only your component?

  1. Install https://www.home-assistant.io/addons/samba/, you need this addon for access sonoff.config.json

  2. install and start the addon

  3. go to /config and edit sonoff.config.json change “IP”: “192.168.0.20” for you HA instance ip addr

  4. restart the addon

  5. config every sonoff device with wget or postman

curl -X POST
http://10.10.7.1/ap
-H ‘Cache-Control: no-cache’
-H ‘Postman-Token: 1d4976ed-77c9-4dcc-a909-527d21de82a8’
-d ‘{“version”:4,“ssid”:YOURWIFINAMEl",“password”:“YOURPASSWORD”,“serverName”:“YOUHASSIOIP”,“port”:1081}’

  1. go to http://hassio.local:1080/ and config your device. https://youtu.be/lnAYCGgyFeA

  2. install custom component in you hassio https://gist.github.com/gerswin/0cac4f8df4a947b0fec196b84a5e8d8b

let me know

My HA works in docker and i don’t understand you again )

  1. Ok, i don’t need samba and can configure from ssh
  2. How to install and start addon? Please give me more information.
  3. Why port 1080 will be opened in my HA? What is the interface in video?

Can i use your addon not in hass.io?

1 Like

i don’t know if works on docker, if you have addon store available you can install it I think.
1080 is sonoff server, and the interface is for config your sonoff devices.

This sounds really promising… I’d been really keen to see this in action (even just a mobile phone shot YouTube video). I’m still a novice at all this and time poor at the moment so I’ll be locking this idea away for my next project.

I tried original sonoff server and it doesn’t work with sonoff firmware >= 1.6.1
Additional information: https://github.com/mirko/SonOTA/issues/58

If one can master Home Assistant, flashing a Sonoff is not a barrier. I would rather not open the Sonoff device to flash it, but I’ll wait for this add-on to mature a bit more. Meanwhile, I flash my Sonoff devices manually once, then OTA if I need to make changes.

Sig

What’s your point? This isn’t meant for those that already appreciate what Tasmota and the like offers.

Hi @gerswin

I’ve got the hassio addon running and can get to the hassio.local:1080. But I have been unable to get step 5 working: “config every sonoff device with wget or postman”

I’m using postman with the headers:

Cache-Control:no-cache
Postman-Token:1d4976ed-77c9-4dcc-a909-527d21de82a8
Content-Type:application/json

And the body:

{
	"version":4,
	"ssid":"MyWireless",
	"password":"Password",
	"serverName":"192.168.1.51",
	"port":1081
}

I’ve also turn off SSL validation in the general settings, but I get the following:

Could not get any response

There was an error connecting to http://192.168.1.54/ap.

Why this might have happened:

* The server couldn't send a response:

Ensure that the backend is working properly

* Self-signed SSL certificates are being blocked:

Fix this by turning off 'SSL certificate verification' in  *Settings > General*

* Proxy configured incorrectly

Ensure that proxy is configured correctly in  *Settings > Proxy*

* Request timeout:

Change request timeout in  *Settings > General*

I’ve also tried a GET on 192.168.1.54/device but get nothing.

And when in AP mode, I don’t see it broadcasting as an access point to connect to

EDIT:

Ok so on my 4ch pro I had to hold a button down for 7 seconds twice, as per:

I then got this on my get:

{
    "deviceid": "xxxxxxx",
    "apikey": "xxxxxxxxxxxxxxxxxx",
    "accept": "post"
}

The post to /ap however doesn’t respond. I’m on firmware 2.0.1

One thing to note for anyone else, that I didn’t immediately cotton on to, is that the ip of your sonoff device is when you are connected to it as an access point, as it says above, 10.10.7.1.

What is the Postman-Token, should that be the value of the apiKey returned from the GET or something else? I tried with the apiKey to no avail so far.

I also managed to install and start the addon, but the above step is too techie for my knowledge. Can you please help out on how to do it in more detailed form. Thanks

I’ve not managed to get the POST command to work as yet.

Best thing is to get postman and do a get once connected over wifi to your device. http://10.10.1.7/device. I’ve not got past this point. but if you read my post it contains all the details for the various postman fields if you want to try.

I’m not sure if the postman-token is or isn’t needed, I’ve read various explanations about this process and some include it, some don’t specify any headers except Context-Type

This is a little clearer to read: https://blog.ipsumdomus.com/sonoff-switch-complete-hack-without-firmware-upgrade-1b2d6632c01

Thanks will have a read … I do have a small problem now, my laptop is broken, and my desktop does not connect to WiFi, will I be able to setup the Sonoff with a android smartphone, or too difficult?

you might find an app you can send requests with like postman, but I don’t know of any off the top of my head

Also would like to know how this integreates with HASS, will it create a switch? What is available ON/OFF and state, or maybe also power for the POW?

Has anyone had any luck getting this to work? I’m stuck on posting the server details to the device.

what’s your problem?