Skip to content

Commit

Permalink
API updated to be RESTful
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Oct 29, 2013
1 parent 102690a commit f9d712d
Show file tree
Hide file tree
Showing 7 changed files with 471 additions and 413 deletions.
89 changes: 48 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,47 +34,54 @@ A screenshot of the debug interface (battery and charging states are controlled

To interface with the API requests should include the parameter api_password which matches the api_password in home-assistant.conf.

The following API commands are currently supported:

/api/state/categories - POST
parameter: api_password - string
Will list all the categories for which a state is currently tracked. Returns a json object like this:

```json
{"status": "OK",
"message":"State categories",
"categories": ["all_devices", "Paulus_Nexus_4"]}
```

/api/state/get - POST
parameter: api_password - string
parameter: category - string
Will get the current state of a category. Returns a json object like this:

```json
{"status": "OK",
"message": "State of all_devices",
"category": "all_devices",
"state": "device_home",
"last_changed": "19:10:39 25-10-2013",
"attributes": {}}
```

/api/state/change - POST
parameter: api_password - string
parameter: category - string
parameter: new_state - string
parameter: attributes - object encoded as JSON string (optional)
Changes category 'category' to 'new_state'
It is possible to sent multiple values for category and new_state.
If the number of values for category and new_state do not match only
combinations where both values are supplied will be set.

/api/event/fire - POST
parameter: api_password - string
parameter: event_name - string
parameter: event_data - object encoded as JSON string (optional)
Fires an 'event_name' event containing data from 'event_data'
All API calls have to be accompanied by an 'api_password' parameter and will
return JSON. If successful calls will return status code 200 or 201.

Other status codes that can occur are:
- 400 (Bad Request)
- 401 (Unauthorized)
- 404 (Not Found)
- 405 (Method not allowed)

The api supports the following actions:

`/api/states` - GET
Returns a list of categories for which a state is available
Example result:
```json{
"categories": [
"Paulus_Nexus_4",
"weather.sun",
"all_devices"
]
}```
`/api/states/<category>` - GET
Returns the current state from a category
Example result:
```json{
"attributes": {
"next_rising": "07:04:15 29-10-2013",
"next_setting": "18:00:31 29-10-2013"
},
"category": "weather.sun",
"last_changed": "23:24:33 28-10-2013",
"state": "below_horizon"
}```
`/api/states/<category>` - POST
Updates the current state of a category. Returns status code 201 if successful
with location header of updated resource.
parameter: new_state - string
optional parameter: attributes - JSON encoded object
`/api/events/<event_type>` - POST
Fires an event with event_type
optional parameter: event_data - JSON encoded object
Example result:
```json{
"message": "Event download_file fired."
}```
Android remote control
----------------------
Expand Down
Binary file modified android-tasker/Home_Assistant.apk
Binary file not shown.
137 changes: 82 additions & 55 deletions android-tasker/Home_Assistant.prj.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<TaskerData sr="" dvi="1" tv="4.1u3m">
<Profile sr="prof24" ve="2">
<cdate>1381116787665</cdate>
<edate>1381116787665</edate>
<clp>true</clp>
<edate>1382062270688</edate>
<id>24</id>
<mid0>20</mid0>
<Event sr="con0" ve="2">
Expand All @@ -11,8 +12,7 @@
</Profile>
<Profile sr="prof25" ve="2">
<cdate>1380613730755</cdate>
<clp>true</clp>
<edate>1381001553706</edate>
<edate>1382769497429</edate>
<id>25</id>
<mid0>23</mid0>
<mid1>20</mid1>
Expand All @@ -26,7 +26,7 @@
<Profile sr="prof26" ve="2">
<cdate>1380613730755</cdate>
<clp>true</clp>
<edate>1381110280839</edate>
<edate>1383003483161</edate>
<id>26</id>
<mid0>22</mid0>
<mid1>20</mid1>
Expand All @@ -37,13 +37,27 @@
<Int sr="arg0" val="3"/>
</State>
</Profile>
<Profile sr="prof3" ve="2">
<cdate>1380613730755</cdate>
<clp>true</clp>
<edate>1383003498566</edate>
<id>3</id>
<mid0>10</mid0>
<mid1>20</mid1>
<nme>HA Power AC</nme>
<pri>10</pri>
<State sr="con0">
<code>10</code>
<Int sr="arg0" val="1"/>
</State>
</Profile>
<Profile sr="prof5" ve="2">
<cdate>1380496514959</cdate>
<cldm>1500</cldm>
<clp>true</clp>
<edate>1381110261999</edate>
<edate>1382769618501</edate>
<id>5</id>
<mid0>7</mid0>
<mid0>19</mid0>
<nme>HA Battery Changed</nme>
<Event sr="con0" ve="2">
<code>203</code>
Expand All @@ -53,14 +67,14 @@
<Project sr="proj0">
<cdate>1381110247781</cdate>
<name>Home Assistant</name>
<pids>24,26,5,25</pids>
<pids>5,3,25,26,24</pids>
<scenes>Variable Query,Home Assistant Start</scenes>
<tids>14,16,4,15,7,20,6,8,22,23,9,11,12,13</tids>
<tids>19,8,10,6,16,9,20,14,11,4,23,15,12,13,22</tids>
<Kid sr="Kid">
<launchID>12</launchID>
<pkg>nl.paulus.homeassistant</pkg>
<vnme>1.0</vnme>
<vnum>10</vnum>
<vnme>1.1</vnme>
<vnum>14</vnum>
</Kid>
<Img sr="icon" ve="2">
<nme>cust_animal_penguin</nme>
Expand All @@ -69,7 +83,7 @@
<Scene sr="sceneHome Assistant Start">
<backColour>-637534208</backColour>
<cdate>1381113309678</cdate>
<edate>1381118413367</edate>
<edate>1381162068611</edate>
<heightLand>-1</heightLand>
<heightPort>688</heightPort>
<nme>Home Assistant Start</nme>
Expand Down Expand Up @@ -308,9 +322,24 @@
<Int sr="arg2" val="255"/>
</ImageElement>
</Scene>
<Task sr="task10">
<cdate>1380613530339</cdate>
<edate>1383030846230</edate>
<id>10</id>
<nme>Charging AC</nme>
<Action sr="act0" ve="3">
<code>130</code>
<Str sr="arg0" ve="3">Update Charging</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="5"/>
<Str sr="arg3" ve="3">ac</Str>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
</Action>
</Task>
<Task sr="task11">
<cdate>1381110672417</cdate>
<edate>1381116046765</edate>
<edate>1383030844501</edate>
<id>11</id>
<nme>Open Debug Interface</nme>
<pri>10</pri>
Expand All @@ -321,7 +350,7 @@
</Task>
<Task sr="task12">
<cdate>1381113015963</cdate>
<edate>1381116866174</edate>
<edate>1383030888271</edate>
<id>12</id>
<nme>Start Screen</nme>
<pri>10</pri>
Expand All @@ -338,6 +367,9 @@
<code>49</code>
<Str sr="arg0" ve="3">Home Assistant Start</Str>
</Action>
<Img sr="icn" ve="2">
<nme>hd_aaa_ext_tiles_small</nme>
</Img>
</Task>
<Task sr="task13">
<cdate>1381114398467</cdate>
Expand All @@ -354,16 +386,15 @@
</Task>
<Task sr="task14">
<cdate>1381114829583</cdate>
<edate>1381115098684</edate>
<edate>1383030731979</edate>
<id>14</id>
<nme>API Fire Event</nme>
<pri>10</pri>
<Action sr="act0" ve="3">
<code>116</code>
<Str sr="arg0" ve="3">%HA_HOST:%HA_PORT</Str>
<Str sr="arg1" ve="3">/api/event/fire</Str>
<Str sr="arg2" ve="3">api_password=%HA_API_PASSWORD
event_name=%par1</Str>
<Str sr="arg1" ve="3">/api/events/%par1</Str>
<Str sr="arg2" ve="3">api_password=%HA_API_PASSWORD</Str>
<Str sr="arg3" ve="3"/>
<Int sr="arg4" val="10"/>
<Str sr="arg5" ve="3"/>
Expand All @@ -372,7 +403,7 @@ event_name=%par1</Str>
</Task>
<Task sr="task15">
<cdate>1380262442154</cdate>
<edate>1381115642332</edate>
<edate>1383030894445</edate>
<id>15</id>
<nme>Light On</nme>
<pri>10</pri>
Expand All @@ -391,7 +422,7 @@ event_name=%par1</Str>
</Task>
<Task sr="task16">
<cdate>1380262442154</cdate>
<edate>1381115613658</edate>
<edate>1383030896170</edate>
<id>16</id>
<nme>Start Epic Sax</nme>
<pri>10</pri>
Expand All @@ -408,9 +439,29 @@ event_name=%par1</Str>
<nme>hd_aaa_ext_guitar</nme>
</Img>
</Task>
<Task sr="task19">
<cdate>1380262442154</cdate>
<edate>1383030903842</edate>
<id>19</id>
<nme>Update Battery</nme>
<pri>10</pri>
<Action sr="act0" ve="3">
<code>116</code>
<Str sr="arg0" ve="3">%HA_HOST:%HA_PORT</Str>
<Str sr="arg1" ve="3">/api/state/change</Str>
<Str sr="arg2" ve="3">api_password=%HA_API_PASSWORD
category=%HA_DEVICE_NAME.charging
new_state=%HA_CHARGING
attributes={"battery":%BATT}</Str>
<Str sr="arg3" ve="3"/>
<Int sr="arg4" val="10"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
</Action>
</Task>
<Task sr="task20">
<cdate>1380613530339</cdate>
<edate>1381116102459</edate>
<edate>1383030848142</edate>
<id>20</id>
<nme>Charging None</nme>
<Action sr="act0" ve="3">
Expand All @@ -425,7 +476,7 @@ event_name=%par1</Str>
</Task>
<Task sr="task22">
<cdate>1380613530339</cdate>
<edate>1381116000403</edate>
<edate>1383030909347</edate>
<id>22</id>
<nme>Charging Wireless</nme>
<Action sr="act0" ve="3">
Expand All @@ -440,7 +491,7 @@ event_name=%par1</Str>
</Task>
<Task sr="task23">
<cdate>1380613530339</cdate>
<edate>1381115997137</edate>
<edate>1383030849758</edate>
<id>23</id>
<nme>Charging USB</nme>
<Action sr="act0" ve="3">
Expand All @@ -455,7 +506,7 @@ event_name=%par1</Str>
</Task>
<Task sr="task4">
<cdate>1380262442154</cdate>
<edate>1381115633261</edate>
<edate>1383030892718</edate>
<id>4</id>
<nme>Light Off</nme>
<pri>10</pri>
Expand All @@ -474,7 +525,7 @@ event_name=%par1</Str>
</Task>
<Task sr="task6">
<cdate>1380522560890</cdate>
<edate>1381117976853</edate>
<edate>1383030900554</edate>
<id>6</id>
<nme>Setup</nme>
<pri>10</pri>
Expand Down Expand Up @@ -580,28 +631,9 @@ event_name=%par1</Str>
<nme>hd_ab_action_settings</nme>
</Img>
</Task>
<Task sr="task7">
<cdate>1380262442154</cdate>
<edate>1381111978825</edate>
<id>7</id>
<nme>Update Battery</nme>
<pri>10</pri>
<Action sr="act0" ve="3">
<code>116</code>
<Str sr="arg0" ve="3">%HA_HOST:%HA_PORT</Str>
<Str sr="arg1" ve="3">/api/state/change</Str>
<Str sr="arg2" ve="3">api_password=%HA_API_PASSWORD
category=%HA_DEVICE_NAME.battery
new_state=%BATT</Str>
<Str sr="arg3" ve="3"/>
<Int sr="arg4" val="10"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
</Action>
</Task>
<Task sr="task8">
<cdate>1380262442154</cdate>
<edate>1381115955507</edate>
<edate>1383030906782</edate>
<id>8</id>
<nme>Update Charging</nme>
<pri>10</pri>
Expand All @@ -613,23 +645,18 @@ new_state=%BATT</Str>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act1" ve="3">
<code>116</code>
<Str sr="arg0" ve="3">%HA_HOST:%HA_PORT</Str>
<Str sr="arg1" ve="3">/api/state/change</Str>
<Str sr="arg2" ve="3">api_password=%HA_API_PASSWORD
category=%HA_DEVICE_NAME.charging
new_state=%HA_CHARGING
category=%HA_DEVICE_NAME.battery
new_state=%BATT</Str>
<code>130</code>
<Str sr="arg0" ve="3">Update Battery</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="5"/>
<Str sr="arg3" ve="3"/>
<Int sr="arg4" val="10"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<Str sr="arg6" ve="3"/>
</Action>
</Task>
<Task sr="task9">
<cdate>1380262442154</cdate>
<edate>1381115659673</edate>
<edate>1383030890674</edate>
<id>9</id>
<nme>Start Fireplace</nme>
<pri>10</pri>
Expand Down
Binary file modified docs/screenshot-debug-interface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f9d712d

Please sign in to comment.