Basic Scripts in Home Assistant (HASS)
1. What are scripts?
The script allows us to set up a sequential sequence of sequential actions. It’s that simple.
2. Why do we need Scripts?
Because when we practice about Smart Home, handling many tasks is indispensable. For example. When you go home, you say ‘I am home’, all the lights are lit, the air conditioner is open, the TV is turned on, the water heater is on … We can’t Google, open the light Google, open the air conditioner … . We want all of those actions to be done after a command. That’s when Script will work.
3. Is it difficult to create Scripts in Hass?
Oh, it’s very easy, guys.
We look at the following script example:
script: i_am_home: sequence: #Call the service to turn on the light and open the air conditioner
- service: switch.turn_on entity_id: - switch.main_light_1 - switch.air_con #Call the service to turn off the alarm switch
- service: switch.turn_off entity_id: switch.alarm
In the example above, we see the structure of the scripts including:
– at first (this is a review of the code rule to understand more). – Down row is the name of the script ( ), lowercase, with hyphen if you want to distinguish words. – is a script statement, you type exactly like that. – Go to this section is we start declaring the service, how to declare yourself guided in the Service article .
That’s it, now you save and CHECK CONFIG and RELOAD SCRIPT.
After reloading the interface you’ll see the first script and have the EXECUTE or IMPLEMENTATION side. That’s the script you just created.
Click EXECUTE or IMPLEMENTATION it will execute.
The examples below are the images of the Script.
At this point, you will want to use voice to activate scripts by voice. Please review lesson 12