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

Use your internal home assistant IP address. I’d love to be able to access the interface via HTTPS so I can make a panel quick link to it, but can’t see how to get it to serve as HTTPS. I noticed there is an SSL port of 1081, but that didn’t seem to work either.

Looking forward to the update, it seems so close! This is a really amazing feature for home assistant, I could see it being an integration at some point, like the Sonos or hue integrations.

Got it. This didn’t solve the issue but I’ll use the internal IP from now on. The port is 1081, as in your example, right ?

I’m wondering because I can access the server using 1080.

Currently, I have the same error message as you do, hopefully the update will solve this issue.

Hi @gerswin

Just wondered if there is any update on your changes? Also I think I’ve got the custom component in and I can control my sonoff using the server directly, but I’m not sure what the naming convention of the entities should be in home assistant and how to go about using the custom component to use lights within a group for example?

Thanks in advance

Andy

EDIT:

Ok so I formatting the Json from the /hadevices endpoint, it needed quotes around the field names to work:

[
    {
        "name": "Back Door Light",
        "service": "Lightbulb",
        "type": "",
        "outlet": 0,
        "state": false,
        "device": "1234567890",
        "uid": "abc1234gh",
        "intID": 2
    }
]

After this, I restarted and could see my devices with the names I gave them. I no longer get errors and can control my devices. Would just be great to get some of the niggles sorted but other than that it’s great.

Hi @mcinnes01,

A few questions if I may:

  • I’m stuck with an error similar to what you previously got:

Error while setting up platform sonoff
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 129, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/light/sonoff.py”, line 44, in setup_platform
for device in json.loads(f.read()):
File “/usr/local/lib/python3.6/json/init.py”, line 354, in loads
return _default_decoder.decode(s)
File “/usr/local/lib/python3.6/json/decoder.py”, line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/local/lib/python3.6/json/decoder.py”, line 357, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

How did you overcame this ? Did you edit /config/sonoff.devices.json ?

Thanks for any help you can provide.

The error is telling you that the JSON is invalid.

raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

You need to ensure the JSON you paste into sonoff.ha.json looks exactly like my example. so you need quotes around all the JSON field names:

[
    {
        "name": "Back Door Light",
        "service": "Lightbulb",
        "type": "",
        "outlet": 0,
        "state": false,
        "device": "1234567890",
        "uid": "abc1234gh",
        "intID": 2
    }
]

Give HA a restart afterwards and check the logs, you should only see one warning about the custom component then, and no errors.

@mcinnes01 Ok got it, the explanation is clear, thank you.
One last thing because I’m dumb: How do you get device, uid and other info ? I guess I should define the name myself but for the others, I’m not sure.

It’s the JSON you get from the sonoff server endpoint. You need to go to the server http://hassio.local:1080, then you should see your device id in the drop down. Select it and configure the channels pressing save.

After that if you click the link on the left to devices, you should see your device’s channels with green button you can use to toggle the state.

Then follow this instruction to get he device JSON that goes in your sonoff.ha.json which contains all the uid’s for your device(s):

gerswin

3d

create a sonoff.ha.json in your config directory with the content of http://hassio.local:1080/hadevices 1

i will fix many issues soon

Then you need to make sure you fixup the JSON formatting as described above.

I also noticed a bug, you can set the service e.g. lightbulb, switch, etc when you add your device channels, but it only seems to save one if you have multiple channels, I think it’s likely a UI bug. So if you look at my JSON I set the service on them all. No idea what the type field is for.

That’s my issue, the dropdown is empty. There must be something wrong with my post request I guess, because everytime I configure my sonoff (=fast blinking led after pressing the button), it goes back to blinking twice once I send the post request.

This means the device is connected to hte router, but can’t reach the sonoff server.

Damn I really can’t figure out that one :confused:

i’m testing the fix! :slight_smile:

done, is fixed.

just config you sonoff devices and sonoff.ha.json will create automatically

you need ip address, sonoff devices don’t work with web address

@gerswin. First, thanks for the work you’ve done and your support.
I no longer have the error message when the server is starting.

However, I’m still not able to get my device in the admin pannel. To me, everything looks in order:

To be absolutely sure, we are indeed talking about this kind of device
image

Right ?

In my config folder, I have those two files, both empty:

I also have the custom component folder in the config folder:
image

Last, the feed from the addon looks like this (only the end copied here):

is watching: disabled ok ?.. I’m not sure what’s going on :confused:

That POST looks like it worked, hence error=0.

To confirm can you see the sonoff in the ewelink app, as in can it still connect or is it orange and says offline?

If it’s offline (when switched on and connected to your wifi), then it’s worked correctly.

Try port 1080 on your POST instead of 1081, I’m yet to work out what 1081 is for.

@gerswin is there a way to add an iframe panel link to the Sonoff server, when you are running HA under an SSL?

Also I wonder if there is a way to make it easier to setup your new devices, i.e. not having to use postman. I guess the only difficulty would be getting your pi to connect to the sonoff over wifi.

My thinking would be, if your pi is connected to your network by ethernet, then you can use the wifi radio to search for available networks.

From that list you can select your network and enter the password.

Then tell the user to put there sonoff in pairing mode.

Do another scan of the network, filtering SSIDs containing “sonoff”.

User selects their device.

You fire the POST command using the details they’ve provided.

Then add the device as usual using your server details.

No luck whatsoever:
image

I haven’t installed the ewelink app or anything, maybe I should.

yeah give it a go, make sure your firmware is up to date etc: https://github.com/mirko/SonOTA/wiki#Known-Working-Configurations

Hum, interesting link you gave here. My firmware is 1.8.1 for sonoff basic … should I downgrade ? The device is working (their app is a nightmare ^^)

Edit: new thing though: in the debug feed of the addon

you still have invalid json

i can check if is possible at weekend, i think is possible