homeassistant.adoc 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. [#hass]
  2. = Home Assistant (REST)
  3. [NOTE]
  4. The recommended way to integrate HomeAssistant and OliveTin is via the xref:integrations/homeassistant-integration.adoc[HACS integration].
  5. Home Assistant is able to call REST API endpoints, making integration with OliveTin possible without any custom plugins or integrations in Home Assistant. This does require modifying your Home Assistant configuration.yml file though.
  6. == Give you actions an ID
  7. First, you need to give your actions an ID. This is done by adding an `id` field to your action. This ID will be used by Home Assistant to call the correct action. Here is an example of an action with an ID:
  8. [source, yaml]
  9. ----
  10. actions:
  11. - id: "server_sleep"
  12. title: "Server Sleep"
  13. icon: ping
  14. shell: ssh user@server "sudo systemctl suspend"
  15. ----
  16. You then need to know the URL to call to trigger this action. This URL is the OliveTin API URL, with the action ID appended to it. For example, if your OliveTin is running at `http://yourserver:1337`, the URL to call to trigger the action above would be `http://yourserver:1337/api/StartActionAndWait/server_sleep`.
  17. You can learn more about starting actions via the OliveTin API by reading the link xref:api/start_action.adoc[Starting Actions via the API] page, but the method "StartActionAndWait" is the one you will want to use for Home Assistant.
  18. == Add the REST API call to Home Assistant
  19. Now that you have the URL to call to trigger your action, you can add this to your Home Assistant configuration. This is done by adding a `rest_command` to your configuration.yml file.
  20. * link:https://www.home-assistant.io/docs/configuration/[Home Assistant Configuration]
  21. That page assumes you will use the Home Assistant File Editor addon to edit your configuration.yaml. Install it from the Home Assistant addon store if you have not done so already;
  22. image::hassFileEditor.png[]
  23. The addon is started and added to the sidebar;
  24. image::hassFileEditorConfig.png[]
  25. Here is an example of a `rest_command` that calls the action above:
  26. From the file editor now in your sidebar, browse the filesystem to the configuration.yaml file and add the following to the file:
  27. [source, yaml]
  28. ----
  29. rest_command:
  30. olivetin_sleep_mindstorm:
  31. url: http://olivetin.webapps.teratan.lan/api/StartActionByGetAndWait/server_sleep
  32. method: get
  33. ----
  34. You save the file, and restart Home Assistant to pick up the changes.
  35. == Add a button to your HASS Dashboard
  36. Now that you have a `rest_command` set up to call your action, you can add a button to your Home Assistant dashboard to trigger the action. This is done by adding a `button` to your dashboard configuration.
  37. image::hassButtonSetup.png[]
  38. Set the "Tap Action" to "Call Service" and select the `rest_command` you created earlier. You can also set the icon and name of the button to whatever you like.
  39. Good luck!