Skip to content

Commit

Permalink
Add home-assistant template
Browse files Browse the repository at this point in the history
  • Loading branch information
nebuto committed Apr 11, 2018
1 parent d726fce commit ba2f989
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/template-homeassistant.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Home Assistant template

# Template placeholders
- `%%action_code_python%%` : the python code for the action

# File names
- Files with no placeholder in their name are to be present only once in the final folder
- Files with placeholders in their name are to be present once per value of the place holder, this value is then used for when the place holder is used in the file

# Hass actions
Templates located in `homeassistant` folder, they are in python3.

Actions expected to happen when installing the final folder (on device)
- move python code in the Hass `python_scripts` folder
- add Snips component to Hass configuration, see https://www.home-assistant.io/components/snips/
- edit Hass' `configuration.yaml` to point to the scripts that were added.

For instance, if you use Snips' lights bundle, this is what your `configuration.yaml` will look like:

```
snips:
intents:
lightsTurnOnSet:
action:
- service: python_script.action-lightsturnonset-lights
data_template:
house_room: "{{ house_room }}"
number: "{{number}}"
unit: "{{unit}}"
lightsTurnOff:
action:
- service: python_script.action-lightsturnoff-lights
data_template:
house_room: "{{house_room}}"
```
37 changes: 37 additions & 0 deletions templates/homeassistant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Generated Snips skill

This is a genrated Home Assistant python script using the `snips-template` tool.
You can use the hass object to call hass services, check https://www.home-assistant.io/components/python_script/

## Setup

Once generated, those python scripts are meant to be copied in the `python_scripts` folder in Hass' configuration.
Hass `configuration.yaml` needs to be updated to reflect this new scripts. Also the Snips component needs to be added to Hass. https://www.home-assistant.io/components/snips/

For instance, if you use Snips' Lights bundle, this is what your `configuration.yaml` will look like:

```
snips:
intents:
lightsTurnOnSet:
action:
- service: python_script.action-lightsturnonset-lights
data_template:
house_room: "{{ house_room }}"
number: "{{number}}"
unit: "{{unit}}"
lightsTurnOff:
action:
- service: python_script.action-lightsturnoff-lights
data_template:
house_room: "{{house_room}}"
```
The `data_template` section is here to expose Snips' intents `slot_value` to the python script. Therefore you'll be able to write this in the python script:
`house_room = data.get('house_room')`

## Executables

This dir contains a number of python executables named `action-*.py`.
One such file is generated per intent supported. These are standalone
executables and will be run by Hass when an intent is triggered.
2 changes: 2 additions & 0 deletions templates/homeassistant/action-{{action_name}}.py.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{#each action_code as |a|}}{{a}}
{{/each}}
6 changes: 6 additions & 0 deletions templates/homeassistant/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name":"homeassistant",
"language":"PYTHON",
"prelude": "\"\"\"\nsnips_skill_slot_value = data.get('snips_skill_slot_value')\nservice_data = {'entity_id': 'snips_skill_slot_value' }\nhass.services.call('hass_component', 'hass_component_method', service_data, False)\"\"\"",
"postlude": ""
}

0 comments on commit ba2f989

Please sign in to comment.