Home Assistant Actions


As a reminder, Actions are the expected behaviors to be triggered on device once the Intent has be caught by the app.

You have four different options to set your apps’ actions:

  • None: if there is no action, nothing will be happen after the intent is detected.

  • Code Snippets: you can write Python code snippets, directly from the console. It is meant for quick testing, or simple interactions.

  • Your own action code, published on Github: to build rich interactions, you can take full control of the action code. See this section to get the basics on how to connect to MQTT directly, or how to use our helpers: the Snips apps server and Hermes Python. If you publish your code on Github, you can point to it from the app, on the console, so anyone using your app can easily leverage your work.

  • Home Assistant: there are numerous components available on Home Assistant. You can use this option to link your app to one of them. You will need to write code snippets that will call Home Assistant components with Snips' intents and slot values.

Here, we are going to present how to build actions by using Home Assistant components, starting from the ‘Smart Lights’ app that you can find on the app store. Add it to your assistant, fork it, and open the app editor.

Home Assistant

Open the ‘Smart lights’ app editor, click on ‘Actions' and select the ‘Home Assistant’ option.

​In this example, we'll search ‘Ikea’ and select ‘Ikea Tradfri lights’ in the search component field that appears below.

Now you’ll need to write code to bind the Home Assistant slot to your Intents’ slots. Let's see a simple example with the ‘lightsSet’ and ‘lightsTurnOff’ Intents. This code will enable you to switch the lights on and off.

Fill the following code snippet in these intents:


house_room = data.get('house_room')
if house_room is not None:
entity_id = 'light.{}'.format(house_room)
service_data = {'entity_id': entity_id }
hass.services.call('light', 'turn_on', service_data, False)


house_room = data.get('house_room')
if house_room is not None && len(house_room) > 0:
entity_id = 'light.{}'.format(house_room)
service_data = {'entity_id': entity_id }
hass.services.call('light', 'turn_off', service_data, False)
hass.services.call('light', 'turn_off')

You’re all set! Just like with the code snippets option, you can now deploy the assistant on your Raspberry Pi! This can be done manually or using the Sam command line tool.

If it's the first time you're testing Snips on your Raspberry Pi, follow our Getting Started tutorial.