How to use iHost Open API to Control Sonoff Switches?

Need some help figuring out how to control Sonoff Basic Switches via iHost Open API.

Got an iHost and a Sonoff Basic R2. Was able to use eWeLink add-on to sync the BasicR2, and then made API calls to iHost, retrieving a list of devices connected to it (which includes the Sonoff BasicR2 switch and its details).

My problem is that I cannot find on the Open API v2 documentation the proper API endpoint to control the said switch. Best I could do is to query this specific switch’s details. Anyone have any idea on how to control LAN Sonoff switches via iHost API? Or is it a matter of this particular switch model is not iHost API supported?

Thanks

Please refer to here

And checkout the DeviceStatesChangeReport Device status change report.
It enables you to control device via open api.

The document I sended is open api v2, if you are using v1, please refer to here:

I was able to use the API Post request (DeviceStatesChangeReport) you outlined and got the response in the sampled in the documentation (see screenshot of Postman). I could see the switch on the iHost Home dashboard changing power status from on to off or vice versa(see screenshot), but the actual switch itself is not changing power states.

Am I missing something here?

PS: Sonoff MiniR2 is registered on my eWeLink account and synced via iHost eWeLink Smart Home Add-on


Does control from the iHost dashboard makes the device itself switch?

Yes, manually switching via the iHost dashboard turns on and off the Sonoff Switch properly

Just to add, I’ve also tried the same procedure in a different network and with a Sonoff Basic R2 switch. So far I’ve got the same exact API response and exact power situation (switch on dashboard changes on/off status, but the actual switch does not). I’m guessing theres a problem between iHost and the eWeLink add-on

My bad.
I gave you the wrong api.
Try find in the url above for: h. Update Specified Device Information or State.
That one should helps you.
I’ve tried.
It’s wroking for me

Tried doing the new one. I’m getting something wrong. Can you show the exact URL and the parameters you’ve used? How exactly do you specify on Postman the device to be controlled?

I’m getting the error “Method Not Allowed” when I use the specified body with the endpoint (PUT method) with params key serial_number and value 93bd0009-7277-4964-8568-27900961f024):

open-api/v1/rest/devices/?serial_number=93bd0009-7277-4964-8568-27900961f024

on the other hand, when I use a hard coded serial num on the URL (same body and PUT method), I get a success message (with both power on and off commands). Problem is that the switch itself does not change power status (neither on nor off), and compared to before, the switch power status on the iHost dashboard is not indicated anymore (see screenshot)


Okay something totally random happened. I’ve tried the exact same procedures again with the hard coded serial num in the endpoint and for whatever reason its started working. Meaning the actual switch and the virtual switch works (on or off) and I am getting a success response from API Calls on Postman.

In the interest of consistency during actual use, any idea why the successful API calls did not trigger the actual switch?

Another add on question. Is there a way to connect Sonoff switches to iHost over LAN without an eWeLink account? Or is this currently only available via Zigbee?

From my test, every api call trigger the device successfully.
Can you reproduce the problem?

It’s only available via Zigbee.

I’ll try to reproduce the problem and post back on this when it happens.

Thanks for the help!

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.