harperreed / eo-python

Electric Objects python library
http://harperreed.github.io/eo-python
MIT License
20 stars 7 forks source link

EO1 On/Off Api? #19

Open leoneleone opened 8 years ago

leoneleone commented 8 years ago

Hey guys. Great work here.

I'm just wondering if you know the Api commands to cal for simply switching the EO1 on and off.

Currently, the only option is to use the physical button at the top of the EO1 screen.

I'd like to toggle the EO1 screen on and off using a virtual switch/button.

Any ideas? You insight is much appreciated 😊

GaryBoone commented 8 years ago

Hi. I haven't found a way to control the screen on/off.

You can experiment, though. Go to https://www.electricobjects.com/api/beta/user/devices/ , then look for the number in "id:XXXX". That's your device id. You can then do https://www.electricobjects.com/api/beta/user/devices/XXXX and see device info. I would guess there could be a command like https://www.electricobjects.com/api/beta/user/devices/XXXX/sleep or https://www.electricobjects.com/api/beta/user/devices/XXXX?display=off. But I haven't found one.

I can suggest a hack if you promise not to tell anyone. There might be a way to set the sleep schedule to be all 24 hours in a day. The data JSON appears like "settings":{"sleep":{"enabled":true,"begin":"23:00:00","end":"06:00:00"} via the API. I wonder if we could post new values there. Something like this may work because that data is settable on the Settings page of the https://www.electricobjects.com web app.

leoneleone commented 8 years ago

Yes, I can't seem to find any ON/OFF command. I've already thought of using the "sleep setting" to achieve this, but I believe it to be too complicated for my purposes.

My end goal: to integrate my EO1s into Apple's HomeKit protocol via Homebridge: https://github.com/nfarina/homebridge So that the EO1s show up in my home automation set up as on/off toggles(switches) - preferably using http commands. Which can then be added to HomeKit scenes, and I'll be able to switch the EO1s on/off remotely if need be.

I've contacted Electric Objects about this and they're being very cagey about the Api. Apparently many people have indicated they'd like an ON/OFF switch as part of the online settings for EO1, but Electric Objects haven't implemented that yet, with no current schedule as to when they would add such a feature.

Have you sniffed the commands being sent to the EO1 device when the "Sleep Setting" takes action? I would presume a simple http ON command is being sent at the selected wake time, and an http OFF command to put the EO1 to sleep.

leoneleone commented 8 years ago

have you managed to find out what api command is being sent when using the physical touch button on the screen? I think the simplest way to achieving what I'm looking for would be to emulate that touch button somehow.

GaryBoone commented 8 years ago

have you managed to find out what api command is being sent when using the physical touch button on the screen?

I would guess there's no API function for that: it's likely handled directly by the firmware running on the device without making any external calls to the online API.

Similarly with the sleep command: I expect that there are API calls to save the sleep times to the device, but once the device knows the times, the internal firmware executes the sleep commands. So there's no 'go to sleep' command via the API.

vratiskol commented 7 years ago

To switch on and off the EO1, you have to use PATCH method with this parameters:

Target: devices-api.electricobjects.com Port: 443

PATCH /api/v6/devices/XXX?backlight_state=false HTTP/1.1

backlight_state=false => Switch off backlight_state=true => Switch on XXX => your device number

You can use paramaters like sleep_begin and sleep_end to program switch on and off too. For example to switch off at 19:54:10 in Paris Timezone

PATCH /api/v6/devices/XXX?sleep_begin=19%3A54%3A10&timezone=Europe%2FParis

vratiskol commented 7 years ago

After few tests, It works with PUT too !

tk421storm commented 6 years ago

@vratiskol does your method still work? I'm getting a 404 with that url construction, but I'm not 100% how to implement PATCH in python. My method (with external library requests):

r = requests.patch("https://devices-api.electricobjects.com/api/v6/devices/EO2", auth=(USERNAME, PASSWORD), data={'backlight_state':'false'} )

vratiskol commented 6 years ago

As I wrote, PUT method works too ! For the 404 error, the XXX is not the name of your EO, it's the id :) Signin on the EO website and go to https://www.electricobjects.com/api/v6/user/devices/ to retreive it.

tk421storm commented 6 years ago

Thank you so much!! that worked :)

tk421storm commented 6 years ago

@vratiskol how did you find that api link? were you just using trial and error, or is there some documentation of available urls/methods for the api?

I'm looking at playlists right now, and I can't figure out how to get a list of artworks included in a playlist. I've tried adding a bunch of random words to the url (eg. /playlists/artworks/ ) but I'm just stabbing in the dark.