Home Assistant Setting Volume with Voice
Mandatory Intro
A quick update, moving the automation to home assistant has been a challenging, and rewarding journey.
Take for instance a simple task of setting volume on voice command.
Make a clear Plan
Lets just discuss the time it took to figure out how to set it up right, the thing is, when you already have some ready made automation up and running from an Echo device for example. Its difficult to focus on one item and close it.
So make a plan first, what automation is your priority, fix one then move to next, try not to get distracted :)
Think modular, build some re-usable "services" that you can leverage in automation, such as an announcement service using TTS with predefined settings. Or play an alarm or notification when something is done, or upon an event.
Home assistant allows you to play with persistent "variables" such as input_boolean that can store a value to be used in automation, lets say you dont want to clean room twice using the robo vacuum, use a toggle to indicate cleaning is done
See, what I mean by getting distracted, okay, so back to setting volume by voice command.
Lets create an automation.
(Settings > Automation & Scenes)
Step 1. setup the voice command
set volume to {volume_val}
Now, be very careful with the spacing between {}, there has to be none, and it took a lot of trial and error, and scurrying through forums to figure that one out.
Step 2. Add the action
Now we need to extract the value of volume_val from the sentence, guess what its hidden away withing trigger.slots, so we get it from trigger.slots.volume_val
This is achieved by using "" and within that {{}}, and be warned, without quotes or without the exact number of braces, it wont work, remember the scurrying part.
data:
volume_level: "{{ (trigger.slots.volume_val | float)/10 }}"
Be very careful with the spacing.
The command that we use wold be from 1 to 10, however the volume_level has to be 0.0 to 1.0 , hence the division by 10.
The whole of the code in YAML format
Enjoy the journey :)
Comments
Post a Comment