My First Snips.ai project

Hello all!

I just installed hassio for the first time last week. I don’t have any home automation devices yet. just two cameras. I started down this path to create a private smart speaker. Which let me to Snips with lead me to Home Assistant. After a few bumps and sleepless nights. I got something working. I wanted to share it here since it was difficult finding a simple solution.

I am running hassio from a Raspberry Pi B+ and Volumino on a Pi Zero with a HiBerry addon. I went to snips.ai to create a new assistant. Here are the apps I added.

The mistake I made with the snips assistant was to unzip and add it to HA. I went back an created a new assistant and just added the zip to the share.

snips core config

{
  "assistant": "snips/assistant_proj_V7a432zytBrN.zip",
  "language": "en",
  "custom_tts": {
    "active": false,
    "platform": "amazon_polly"
  }
}

I left the filename so I could change out different versions.

Then I started with the weather example.

/config/configuration.yaml

# Snips
snips:
intent_script: !include intents.yaml

/config/intents.yaml

# Weather (Weather by SNIPS)
  searchWeatherForecast:
    speech:
      type: plain
      text: >
        The weather is currently
        {{ states('sensor.dark_sky_weather_temperature') | round(0) }}
        degrees outside and {{ states('sensor.dark_sky_weather_summary') }}.
        The high today will be
        {{ states('sensor.dark_sky_weather_daily_high_temperature') | round(0)}}
        and {{ states('sensor.dark_sky_weather_hourly_summary') }}

Music Controls

# Media (Music Player by SNIPS)
  speakerInterrupt:
    speech:
      type: plain
      text: 'OK, music is paused.'
    action:
        service: media_player.media_play_pause
        data:
          entity_id: media_player.juke
          
  resumeMusic:
    speech:
      type: plain
      text: 'OK, music is started.'
    action:
        service: media_player.media_play
        data:
          entity_id: media_player.juke

  volumeUp:
    speech:
      type: plain
      text: 'OK'
    action:
        service: media_player.volume_up
        data:
          entity_id: media_player.juke

  volumeDown:
    speech:
      type: plain
      text: 'OK'
    action:
        service: media_player.volume_down
        data:
          entity_id: media_player.juke
          
  nextSong:
    speech:
      type: plain
      text: 'OK'
    action:
        service: media_player.media_next_track
        data:
          entity_id: media_player.juke

  playPlaylist:
    speech:
      type: plain
      text: 'OK.'
    action:
      - service: media_player.select_source
        data_template:
          source: "{{ playlist_name }}"
      - service: media_player.shuffle_set
        data_template:
          shuffle: 'true'

Countdown Timer

#Timers (Timers by ACIDFLOW)
  SetTimer:
    speech:
      type: plain
      text: >
        Setting a timer {{ timer_name }} for {{ timer_duration }} seconds.
    action:
        - service: timer.start
          data_template:
            entity_id: timer.countdown_timer
            duration: "{{ timer_duration }}"

Date and Time

#Check time and date (TimeDateCheck by RGHOLMES)
  getCurrentDate:
    speech:
      type: plain
      text: >
        {%- set today = now() %}
        {%- macro suffix(d) %}
        {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
        {{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
        {%- endmacro %}

        {% set day = as_timestamp(today) | timestamp_custom('%A') %}
        {% set date = as_timestamp(today) | timestamp_custom('%d')|int %}
        {% set month = as_timestamp(today) | timestamp_custom('%B') %}
        Today is {{ month }} {{ date }}{{ suffix(date) }}

  getCurrentDay:
    speech:
      type: plain
      text: >
        {%- set today = now() %}
        {%- macro suffix(d) %}
        {%- set sfx = {1:'st',2:'nd',3:'rd'} %}
        {{- 'th' if 11 <= d <= 13 else sfx.get(d%10, 'th') }}
        {%- endmacro %}

        {% set day = as_timestamp(today) | timestamp_custom('%A') %}
        {% set date = as_timestamp(today) | timestamp_custom('%d')|int %}
        {% set month = as_timestamp(today) | timestamp_custom('%B') %}
        {{ day }} the {{ date }}{{ suffix(date) }}

  getCurrentTime:
    speech:
      type: plain
      text: >
        {%- set today = now() %}
        {% set currenttime = as_timestamp(today) | timestamp_custom('%I:%M %p') %}
        It is {{ currenttime }}

I needed to create an automation for the timer.

/config/automations.yaml

  - id: coutdownfinished
    alias: coutdownfinished
    trigger:
      platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.countdown_timer
    action:
    #   - service: mqtt.publish
    #     data_template:
    #       topic: "lights/led-green/light/on"
    #       payload: 'done!'
      - service: snips.say
        data_template:
          text: "Times up!"

      - service: notify.ios_my_iphone
        data:
          title: "Countdown Timer"
          message: "Time's up!"

So far that’s what I got.

4 Likes

Thanks a lot for the share and will re-use some of your solutions for my own SNIPS system :wink: