For those who never heard of Zanzito, it is an amazing Android app that bridge your phone (or any android devices except Android TV) to HA using MQTT. With this app, it is now possible to have voice command and have it feedback to you using any TTS engines (with any voice) that are available for Android. It also has always listening mode where it will wake up when it hears a certain keyword that set by you. That means, instead of “Alexa”, “Hey Google”, “Siri”, “Mycroft”, “Jasper” or “Cortana”, you can named it anything you like such Jarvis. In other words, you can have your own Jarvis at home.
But what good is Jarvis if it doesn’t do much? Well, here I gonna share some “skills” I have created for my Jarvis. I will keep adding new skills to this post from time to time. So bookmark this if you want to see more skills in the future.
Skill #1: Turn on/off anything in HA (method 1)
Command example: “Jarvis, turn on TV”
For this skill, you only need to create 2 activities in Zanzito and 1 automation in HA. Any smart devices that you want to control are added in the HA automation. IMHO, it is simpler and easier to manage. But the downsides are…
- Zanzito will only send the first guess as the payload. This reduce the accuracy by 5 times. However, this can be overcome by adding the similar sounding words in HA automation. A bit troublesome, but this is the best I can come up with at the moment.
- You can only say turn on this or turn on that which works exactly like Alexa emulated Hue component. If you want more natural command, such as “Jarvis, view Plex” or “Jarvis, disable light automation”, see method 2 below.
Activities in Zanzito:
Activity #1:
Name: Turn on
Topic: %devicename%/switch/turn_on
Payload: [empty]
Retained: [uncheck]
Voice cmd: Turn on
Get payload from vocal command: [check]
Activity #2:
Name: Turn off
Topic: %devicename%/switch/turn_off
Payload: [empty]
Retained: [uncheck]
Voice cmd: Turn off
Get payload from vocal command: [check]
Automation in HA:
- alias: 'MQTT Switch'
trigger:
- platform: mqtt
topic: tonystark/switch/#
- platform: mqtt
topic: office/switch/#
- platform: mqtt
topic: livingroom/switch/#
- platform: mqtt
topic: bedroom/switch/#
action:
- service_template: >
homeassistant.{{ trigger.topic.split('/')[-1] }}
data_template:
entity_id: >-
{% set payload = trigger.payload %}
{% set devicename = trigger.topic.split('/')[-3] %}
{%- if payload == "everything" -%}
{%- if devicename == "office" -%}
group.office_all_switches
{%- elif devicename == "bedroom" -%}
group.masterbedroom_all_switches
{%- else -%}
group.all_items
{%- endif -%}
{%- elif payload == "lights" -%}
{%- if devicename == "office" -%}
switch.office_downlights
{%- elif devicename == "bedroom" -%}
group.masterbedroom_all_lights
{%- else -%}
group.livingroom_lights
{%- endif -%}
{%- elif payload == "dining" -%}
group.dining_lights_fan
{%- elif payload == "kitchen lights" or payload == "kitchen light" -%}
group.kitchen_lights
{%- elif payload == "play room" or payload == "playroom" -%}
group.playroom
{%- elif payload == "living room lights" -%}
group.livingroom_lights
{%- elif payload == "staircase lights" -%}
group.staircase_1_lights
{%- elif payload == "bedroom lights" -%}
group.masterbedroom_all_lights
{%- elif payload == "bedroom" -%}
group.masterbedroom_all_switches
{%- endif %}
- service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-3] }}/notification
payload: >-
{% set payload = trigger.payload %}
{%- if
payload == "everything" or
payload == "lights" or
payload == "dining" or
payload == "kitchen lights" or
payload == "kitchen light" or
payload == "play room" or
payload == "playroom" or
payload == "living room lights"
-%}
{% set responses = [
"OK",
"Sure",
"If you insist",
"Done",
"Alright",
"No worries",
"I can do that",
"Leave it to me",
"Consider it done",
"As you wish",
"By your command",
"Affirmative",
"No Problem"
] %}
{% set rindex = (range(0, (responses | length - 1) )|random) -%}
{{responses[rindex]}}
{%- else -%}
"I'm sorry. I cannot find the device named {{payload}} in the house."
{% endif %}
Skill #2: Turn on/off anything in HA (method 2).
Command example: “Jarvis, view Plex”
With this method, you can have more natural sounding command. So, instead of “Jarvis, turn on view Plex”, you can say “Jarvis, view Plex”. However, with this method, you need to create one activity in Zanzito for each switches/lights/scripts/etc… that you want to control. In other words, if you have 50 items that you want control you need to add 50 activities in your phone. Not so easy, if you ask me. So, I only use this for items that need more natural command. The rest I use method 1 above.
Activities in Zanzito:
Activity #1:
Name: View Plex
Topic: %devicename%/switchentity/switch/view_plex
Payload: on
Retained: [uncheck]
Voice cmd: view Plex
Get payload from vocal command: [uncheck]
Automation in HA:
- alias: 'MQTT Switch Entity'
trigger:
platform: mqtt
topic: benredminote4/switchentity/#
action:
- service_template: >
homeassistant.turn_{{trigger.payload}}
data_template:
entity_id: >-
{{ trigger.topic.split('/')[-2] }}.{{ trigger.topic.split('/')[-1] }}
- service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-4] }}/notification
payload: >-
{% set responses = [
"OK",
"Sure",
"If you insist",
"Done",
"Alright",
"No worries",
"I can do that",
"Leave it to me",
"Consider it done",
"As you wish",
"By your command",
"Affirmative",
"No Problem"
] %}
{% set rindex = (range(0, (responses | length - 1) )|random) -%}
{{responses[rindex]}}
Skill #3: Get Sensor States (weather report)
Command example: “Jarvis, how is the weather”
This skill is use to get reply of any sensor states. You need to create 1 activity for each sensor states.
Activities in Zanzito:
Activity #1:
Name: Get states
Topic: %devicename%/getstates/sensor
Payload: weather_condition
Retained: [uncheck]
Voice cmd: how is the weather
Get payload from vocal command: [uncheck]
Automation in HA:
- alias: 'MQTT Get States - Sensors'
trigger:
platform: mqtt
topic: +/getstates/sensor
action:
service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-3] }}/notification
payload: >-
{{ states('sensor.' ~ trigger.payload ~ '') }}
Template sensor in HA:
- platform: template
sensors:
weather_condition:
friendly_name: 'Weather Condition'
value_template: "The weather condition is {{ states('sensor.dark_sky_summary') }} and {{ states('sensor.temp_feel_darksky') }} at {{ states('sensor.dark_sky_temperature') }}°C and the forecast is {{ states('sensor.dark_sky_hourly_summary') }} with temperature ranging from {{ states('sensor.dark_sky_daily_low_temperature') }}°C to {{ states('sensor.dark_sky_daily_high_temperature') }}°C"
entity_id:
- sensor.dark_sky_summary
- sensor.temp_feel_darksky
- sensor.dark_sky_temperature
- sensor.dark_sky_hourly_summary
- sensor.dark_sky_daily_low_temperature
- sensor.dark_sky_daily_high_temperature
temp_feel_darksky:
friendly_name: 'Dark Sky Temperature Feel'
value_template: >-
{%- if states.sensor.dark_sky_temperature.state | float < 29 %}
nice
{%- elif states.sensor.dark_sky_temperature.state | float < 31 %}
warm
{%- elif states.sensor.dark_sky_temperature.state | float < 33 %}
hot
{% else %}
baking
{%- endif %}
entity_id: sensor.dark_sky_temperature
Skill #4: Get Sensor States (time and date)
Command example: “Jarvis, what is the time”
This skill uses the same automation from Skill #3.
Activities in Zanzito:
Activity #1:
Name: Get states
Topic: %devicename%/getstates/sensor
Payload: whatisthetime
Retained: [uncheck]
Voice cmd: what is the time
Get payload from vocal command: [uncheck]
Automation in HA: Same with Skill #3.
Template sensor in HA:
- platform: template
sensors:
whatisthetime:
friendly_name: 'The time'
value_template: >-
The time is {{ states('sensor.time') }} and today is {{ states('sensor.date') }}.
entity_id:
- sensor.time
- sensor.date
Skill #5: Get Sensor States (health status)
Command example: “Jarvis, how are you”
This skill uses the same automation from Skill #3.
Activities in Zanzito:
Activity #1:
Name: Get states
Topic: %devicename%/getstates/sensor
Payload: health_status
Retained: [uncheck]
Voice cmd: how are you
Get payload from vocal command: [uncheck]
Automation in HA: Same with Skill #3.
Template sensor in HA:
- platform: template
sensors:
# System Health Status Report. Uses systemmonitor sensor platform
health_status:
friendly_name: 'System Health Status'
value_template: "{% if states('sensor.cpu_use') | float > 50 or states('sensor.ram_use') | float > 50 or states('sensor.disk_use_') | float > 50 %}I am not feeling so good. {% else %}I am fine. {% endif %}My C.P.U. usage is {{ states('sensor.cpu_use') }}%, my memory usage is {{ states('sensor.ram_use') }}% and my storage usage is {{ states('sensor.disk_use_') }}%."
entity_id:
- sensor.cpu_use
- sensor.ram_use
- sensor.disk_use_
Skill #6: Get Sensor States (who is at home)
Command example: “Jarvis, who is at home”
This skill uses the same automation from Skill #3.
Activities in Zanzito:
Activity #1:
Name: Get states
Topic: %devicename%/getstates/sensor
Payload: whoisathome
Retained: [uncheck]
Voice cmd: who is at home
Get payload from vocal command: [uncheck]
Automation in HA: Same with Skill #3.
Template sensor in HA:
- platform: template
sensors:
whoisathome:
friendly_name: 'Who is at Home?'
value_template: >-
{% for entity in states.group.occupants.attributes.entity_id if is_state(entity, 'home') %}
{%- if loop.first and loop.last %}
{{ states[entity.split('.')[0]][entity.split('.')[1]].name }} is the only one at home
{% elif loop.length == states.group.occupants.attributes.entity_id|length %}
{{ "Everyone is at home" if loop.last }}
{% else %}
{%- if loop.first %}{% elif loop.last %} & {% else %}, {% endif -%}
{{ states[entity.split('.')[0]][entity.split('.')[1]].name }}{{ " are at home" if loop.last }}
{%- endif -%}
{% else %}
No one is at home
{% endfor %}
entity_id:
- group.occupants
- device_tracker.luke
- device_tracker.obiwan
- device_tracker.leia
- device_tracker.hansolo
Group in HA:
occupants:
name: Occupants
entities:
- device_tracker.luke
- device_tracker.obiwan
- device_tracker.leia
- device_tracker.hansolo
Skill #7: Get Sensor States (who is away)
Command example: “Jarvis, who is away”
This skill uses the same automation from Skill #3.
Activities in Zanzito:
Activity #1:
Name: Get states
Topic: %devicename%/getstates/sensor
Payload: whoisaway
Retained: [uncheck]
Voice cmd: who is away
Get payload from vocal command: [uncheck]
Automation in HA: Same with Skill #3.
Template sensor in HA:
- platform: template
sensors:
whoisaway:
friendly_name: 'Who is away?'
value_template: >-
{% for entity in states.group.occupants.attributes.entity_id if not is_state(entity, 'home') %}
{%- if loop.first and loop.last %}
{{ states[entity.split('.')[0]][entity.split('.')[1]].name }} is the only one away
{% elif loop.length == states.group.occupants.attributes.entity_id|length %}
{{ "Everyone is away" if loop.last }}
{% else %}
{%- if loop.first %}{% elif loop.last %} & {% else %}, {% endif -%}
{{ states[entity.split('.')[0]][entity.split('.')[1]].name }}{{ " are away" if loop.last }}
{%- endif -%}
{% else %}
No one is away
{% endfor %}
entity_id:
- group.occupants
- device_tracker.luke
- device_tracker.obiwan
- device_tracker.leia
- device_tracker.hansolo
Group in HA: Same with Skill #6
Skill #8: Get Sensor States (where is XXX)
Command example: “Jarvis, where is Luke”
This skill uses the same automation from Skill #3.
Activities in Zanzito:
Activity #1:
Name: Get states
Topic: %devicename%/getstates/sensor
Payload: whereis_luke
Retained: [uncheck]
Voice cmd: where is Luke
Get payload from vocal command: [uncheck]
Automation in HA: Same with Skill #3.
Template sensor in HA:
- platform: template
sensors:
whereis_luke:
friendly_name: 'Where is Luke'
value_template: >-
Luke is currently {% if (is_state('device_tracker.owntrack_luke', 'not_home')) %}not at home{% else %}at {{ states('device_tracker.owntrack_luke') }}{% endif %}
entity_id:
- device_tracker.owntrack_luke
Skill #9: Chit Chat (who are you)
Command example: “Jarvis, who are you”
This is a simple skill but equally important. Ask it a simple question and it will reply back with a predefined response. It acts like Alexa’s easter eggs.
Activities in Zanzito:
Activity #1:
Name: Chit Chat
Topic: %devicename%/chitchat
Payload: whoareyou
Retained: [uncheck]
Voice cmd: who are you
Get payload from vocal command: [uncheck]
Automation in HA:
- alias: 'MQTT Chit Chat - Who Are You?'
trigger:
platform: mqtt
topic: +/chitchat
payload: "whoareyou"
action:
service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/notification
payload: "This is Jarvis, the virtual butler of this house. My purpose is to serve the occupants of my house and makes their life better. I take care of the house when no one is around, check the traffic condition, appointments, holidays, weather, air quality, control the lights and many more. I am learning new skills everyday."
Skill #10: Chit Chat (thank you)
Command example: “Thank you Jarvis”
This is a simple skill but equally important. Ask it a simple question and it will reply back with a predefined response. It acts like Alexa’s easter eggs.
Variant of random responses.
Activities in Zanzito:
Activity #1:
Name: Chit Chat
Topic: %devicename%/chitchat
Payload: thankyou
Retained: [uncheck]
Voice cmd: thank you
Get payload from vocal command: [uncheck]
Automation in HA:
- alias: 'MQTT Chit Chat - thank you'
trigger:
platform: mqtt
topic: +/chitchat
payload: "thankyou"
action:
service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/notification
payload: >-
{% set responses = [
"You're welcome",
"You got it",
"Don't mention it",
"No worries",
"Not a problem",
"It's my pleasure",
"It was nothing",
"I'm happy to help",
"Not at all",
"Sure",
"That's okay",
"That's alright",
"Anytime"
] %}
{% set rindex = (range(0, (responses | length - 1) )|random) -%}
{{responses[rindex]}}
Skill #11: Chit Chat (tell me a joke)
Command example: “Jarvis, tell me a joke”
This is a simple skill but equally important. Ask it a simple question and it will reply back with a predefined response. It acts like Alexa’s easter eggs.
Variant of random responses.
Activities in Zanzito:
Activity #1:
Name: Chit Chat
Topic: %devicename%/chitchat
Payload: joke
Retained: [uncheck]
Voice cmd: tell me a joke
Get payload from vocal command: [uncheck]
Automation in HA:
- alias: 'MQTT Chit Chat - tell me a joke'
trigger:
platform: mqtt
topic: +/chitchat
payload: "joke"
action:
service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/notification
payload: >-
{% set responses = [
"Joke 1",
"Joke 2",
"Joke 3"
] %}
{% set rindex = (range(0, (responses | length - 1) )|random) -%}
{{responses[rindex]}}
Skill #12: Chit Chat (good morning)
Command example: “Good morning Jarvis”
This is a simple skill but equally important. Ask it a simple question and it will reply back with a predefined response. It acts like Alexa’s easter eggs.
In this example, you can include sensor values in the response
Activities in Zanzito:
Activity #1:
Name: Chit Chat
Topic: %devicename%/chitchat
Payload: greeting
Retained: [uncheck]
Voice cmd: good morning
Get payload from vocal command: [uncheck]
Automation in HA:
- alias: 'MQTT Chit Chat - good morning'
trigger:
platform: mqtt
topic: +/chitchat
payload: "greeting"
action:
service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/notification
payload: >-
{% set day = now().strftime('%A') %}
{{ states('sensor.greeting') }}. Today is {{ day }}{% if states('calendar.holidays') == 'on' %} and it is {{ states.calendar.holidays.attributes.message }}{% endif %}. {{ states('sensor.weather_condition') }}.
Skill #13: Chit Chat (where is my phone)
Command example: “Jarvis, where is my phone”
This is skill will help you find your phone. It requires multiple Zanzitos. First Zanzito is of course your phone. Second Zanzito will be another Android device such as a tablet on the wall.
In your wall tablet’s Zanzito:
Activities:
Name: Chit Chat
Topic: %devicename%/chitchat
Payload: whereismyphone
Retained: [uncheck]
Voice cmd: where is my phone
Get payload from vocal command: [uncheck]
In your phone’s Zanzito:
- Take note of your Device name (e.g. myphone)
- Preference > Play alarm
Play alarm: [check]
Alarm sound: [select any sound you prefer]
Override “silent” mode: [check]
Automation in HA:
- alias: 'MQTT Chit Chat - where is my phone?'
trigger:
platform: mqtt
topic: +/chitchat
payload: "whereismyphone"
action:
- service: mqtt.publish
data:
topic: zanzito/myphone/alarm/play
- service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/notification
payload: >-
Your phone is{% if states('device_tracker.owntrack_ironman') == 'not_home' %} not at home {% else %} at {{states('device_tracker.owntrack_ironman')}} {% endif %}. I have triggered the alarm so that you can find it. Good Luck!
Skill #14: Media player control
Command examples:
- “Jarvis, play Plex”
- “Jarvis, pause Plex”
- “Jarvis, resume Plex”
- “Jarvis, stop Plex”
This skill will let you have basic controls to any media players entity in HA. I am using this to control my Plex and Spotify with my voice.
Activities in Zanzito:
Activity #1:
Name: Media mute
Topic: %devicename%/media_player/volume_mute
Payload: [empty]
Retained: [uncheck]
Voice cmd: mute
Get payload from vocal command: [check]
Activity #2:
Name: Media next rack
Topic: %devicename%/media_player/media_next_rack
Payload: [empty]
Retained: [uncheck]
Voice cmd: next rack
Get payload from vocal command: [check]
Activity #3:
Name: Media pause
Topic: %devicename%/media_player/media_pause
Payload: [empty]
Retained: [uncheck]
Voice cmd: pause
Get payload from vocal command: [check]
Activity #4:
Name: Media play
Topic: %devicename%/media_player/media_play
Payload: [empty]
Retained: [uncheck]
Voice cmd: play
Get payload from vocal command: [check]
Activity #5:
Name: Media previous track
Topic: %devicename%/media_player/media_previous_track
Payload: [empty]
Retained: [uncheck]
Voice cmd: previous track
Get payload from vocal command: [check]
Activity #6:
Name: Media resume
Topic: %devicename%/media_player/media_play
Payload: [empty]
Retained: [uncheck]
Voice cmd: resume
Get payload from vocal command: [check]
Activity #7:
Name: Media stop
Topic: %devicename%/media_player/media_stop
Payload: [empty]
Retained: [uncheck]
Voice cmd: stop
Get payload from vocal command: [check]
Activity #8:
Name: Media volume down
Topic: %devicename%/media_player/volume_down
Payload: [empty]
Retained: [uncheck]
Voice cmd: volume down
Get payload from vocal command: [check]
Activity #9:
Name: Media volume up
Topic: %devicename%/media_player/volume_up
Payload: [empty]
Retained: [uncheck]
Voice cmd: volume up
Get payload from vocal command: [check]
Automation in HA:
- alias: 'Media Player Control'
trigger:
- platform: mqtt
topic: tonystark/media_player/#
- platform: mqtt
topic: office/media_player/#
- platform: mqtt
topic: livingroom/media_player/#
- platform: mqtt
topic: bedroom/media_player/#
action:
- service_template: >
media_player.{{ trigger.topic.split('/')[-1] }}
data_template:
entity_id: >-
{% set payload = trigger.payload %}
{% set devicename = trigger.topic.split('/')[-3] %}
{%- if payload == "plex" or payload == "tv" -%}
{%- if devicename == "bedroom" -%}
media_player.plex_mi_box
{%- else -%}
media_player.plex_rasplexlr
{%- endif -%}
{%- elif payload == "living room plex" or payload == "living room tv" -%}
media_player.plex_rasplexlr
{%- elif payload == "bedroom plex" or payload == "bedroom tv" -%}
media_player.plex_mi_box
{%- elif payload == "alexa" or payload == "spotify" or payload == "bedroom alexa" or payload == "bedroom spotify" -%}
media_player.spotify_master_bedroom
{%- endif %}
- service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-3] }}/notification
payload: >-
{% set payload = trigger.payload %}
{%- if
payload == "plex" or
payload == "tv" or
payload == "living room plex" or
payload == "living room tv" or
payload == "bedroom plex" or
payload == "bedroom tv" or
payload == "alexa" or
payload == "spotify" or
payload == "bedroom alexa" or
payload == "bedroom spotify"
-%}
{% set responses = [
"OK",
"Sure",
"If you insist",
"Done",
"Alright",
"No worries",
"I can do that",
"Leave it to me",
"Consider it done",
"As you wish",
"By your command",
"Affirmative",
"No Problem"
] %}
{% set rindex = (range(0, (responses | length - 1) )|random) -%}
{{responses[rindex]}}
{%- else -%}
"I'm sorry. I cannot find the device named {{payload}} in the house."
{% endif %}
Skill #15: Volume set control
Command examples: “Jarvis, set Plex volume to 7”
This skill will let you set the volume of any media players entity in HA to any levels. So instead of saying “Jarvis, volume down Plex” for multiple times, I can simply say, “Jarvis set Plex volume to 7”. You need 1 activity for each media player.
Activities in Zanzito:
Activity #1:
Name: Volume set Plex living room
Topic: %devicename%/volume_set/plex_rasplexlr
Payload: [empty]
Retained: [uncheck]
Voice cmd: set Plex volume to
Get payload from vocal command: [check]
Automation in HA:
- alias: 'Volume set Control'
trigger:
- platform: mqtt
topic: tonystark/volume_set/#
- platform: mqtt
topic: office/volume_set/#
- platform: mqtt
topic: livingroom/volume_set/#
- platform: mqtt
topic: bedroom/volume_set/#
action:
- service_template: >
media_player.volume_set
data_template:
entity_id: media_player.{{trigger.topic.split('/')[-1]}}
volume_level: >-
{%- set payload = trigger.payload %}
{%- if payload == 'one' %}{% set payload = 1 %}
{%- elif payload == 'two' %}{% set payload = 2 %}
{%- elif payload == 'three' %}{% set payload = 3 %}
{%- elif payload == 'four' %}{% set payload = 4 %}
{%- elif payload == 'five' %}{% set payload = 5 %}
{%- elif payload == 'six' %}{% set payload = 6 %}
{%- elif payload == 'seven' %}{% set payload = 7 %}
{%- elif payload == 'eight' %}{% set payload = 8 %}
{%- elif payload == 'nine' %}{% set payload = 9 %}
{%- elif payload == 'ten' %}{% set payload = 10 %}
{%- endif %}
{%- if payload | int and payload | int > 0 and payload | int <= 10 %}{{ payload | int / 10 }}{% endif %}
- service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-3] }}/notification
payload: >-
{%- set payload = trigger.payload %}
{%- if payload == 'one' %}{% set payload = 1 %}
{%- elif payload == 'two' %}{% set payload = 2 %}
{%- elif payload == 'three' %}{% set payload = 3 %}
{%- elif payload == 'four' %}{% set payload = 4 %}
{%- elif payload == 'five' %}{% set payload = 5 %}
{%- elif payload == 'six' %}{% set payload = 6 %}
{%- elif payload == 'seven' %}{% set payload = 7 %}
{%- elif payload == 'eight' %}{% set payload = 8 %}
{%- elif payload == 'nine' %}{% set payload = 9 %}
{%- elif payload == 'ten' %}{% set payload = 10 %}
{%- endif %}
{%- if payload | int and payload | int > 0 and payload | int <= 10 %}
{% set responses = [
"OK",
"Sure",
"If you insist",
"Done",
"Alright",
"No worries",
"I can do that",
"Leave it to me",
"Consider it done",
"As you wish",
"By your command",
"Affirmative",
"No Problem"
] %}
{% set rindex = (range(0, (responses | length - 1) )|random) -%}
{{responses[rindex]}}
{%- else -%}
"I'm sorry. {{payload}} is not valid. Please use value from 1 to 10 only."
{% endif %}
Skill #16: Set timer
Command examples:
- “Jarvis, set timer for 1 hour 15 minutes and 30 seconds”
- “Jarvis, set timer for 3 minutes and 10 seconds”
- “Jarvis, set timer for 3 minutes”
This skill will analyze your command and extract the required value. In this case hours, minutes and seconds. It will pass the value to a script to be used as a script delay. Once the delay is up, it will trigger the phone alarm.
Activities in Zanzito:
Activity #1:
Name: Timer set
Topic: %devicename%/set_timer
Payload: [empty]
Retained: [uncheck]
Voice cmd: set timer for
Get payload from vocal command: [check]
Automation in HA:
- alias: 'Set Timer'
trigger:
- platform: mqtt
topic: +/set_timer
action:
- service: script.reset_timer
data_template:
delay_seconds: >-
{%- set words = trigger.payload.split(' ') -%}
{%- for word in words -%}
{%- if word == 'second' or word == 'seconds' -%}
{%- set value = words[loop.index0|int-1] | int -%}
{%- if value | int -%}{{ value }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
delay_minutes: >-
{%- set words = trigger.payload.split(' ') -%}
{%- for word in words -%}
{%- if word == 'minute' or word == 'minutes' -%}
{%- set value = words[loop.index0|int-1] | int -%}
{%- if value | int -%}{{ value }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
delay_hours: >-
{%- set words = trigger.payload.split(' ') -%}
{%- for word in words -%}
{%- if word == 'hour' or word == 'hours' -%}
{%- set value = words[loop.index0|int-1] | int -%}
{%- if value | int -%}{{ value }}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
alarmtopic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/alarm/play
- service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/notification
payload: >-
"OK. Timer set for {{trigger.payload}}"
The timer script in HA:
reset_timer:
alias: "Reset Timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.start_timer
# Set new timer
- service: script.start_timer
data_template:
delay: '{{"%0.02d" | format(delay_hours|int)}}:{{"%0.02d" | format(delay_minutes|int)}}:{{"%0.02d" | format(delay_seconds|int)}}'
alarmtopic: '{{alarmtopic}}'
start_timer:
alias: "Start Timer"
sequence:
- delay: '{{delay}}'
- service: mqtt.publish
data_template:
topic: >-
{{alarmtopic}}
Skill #17: Cancel timer
Command examples: “Jarvis, cancel timer”
If you change your mind, you can cancel timer with this skill.
Activities in Zanzito:
Activity #1:
Name: Timer cancel
Topic: %devicename%/cancel_timer
Payload: [empty]
Retained: [uncheck]
Voice cmd: cancel timer
Get payload from vocal command: [uncheck]
Automation in HA:
- alias: 'Cancel Timer'
trigger:
- platform: mqtt
topic: +/cancel_timer
action:
- service: script.turn_off
data:
entity_id: script.start_timer
- service: mqtt.publish
data_template:
topic: >-
zanzito/{{ trigger.topic.split('/')[-2] }}/notification
payload: >-
"OK. Timer cancelled."