forked from snipsco/snips-actions-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{#each action_code as |a|}}{{a}} | ||
{{/each}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "" | ||
} |