5 MUST Have Scripts in Home Assistant


Scripts are a collection of actions that are very similar to those actions in automations.

Why use Scripts? They wrap around a series of actions and simplify your home assistant automations and allow you to do so many cool things

Feel free to copy & paste this in your automations.yaml

Notify All / Broadcast All

Send a specific notification to all of your devices at the same time

Replace the mobile app with your own device, I have 3 devices in this section, feel free to add/remove as many as you want.

description: Notify all of devices
fields:
  title:
    description: The Title of the notification
    example: Example text
  message:
    description: The content
    example: Example text
sequence:
  - service: notify.mobile_app_giordano_s_iphone_12
    data:
      title: '{{ title }}'
      message: '{{ message }}'
  - service: notify.mobile_app_giordanos_ipad
    data:
      title: '{{ title }}'
      message: '{{ message }}'
  - service: notify.mobile_app_smarts_imac
    data:
      title: '{{ title }}'
      message: '{{ message }}'
mode: single
alias: Notify All
description: Broadcast all of devices
fields:
  title:
    description: The Title of the notification
    example: Example text
  message:
    description: The content
    example: Example text
sequence:
  - service: tts.cloud_say
    data:
      entity_id: media_player.kitchen_speaker
      message: '{{ message }}'
      language: en-GB
mode: single

Flashing Lights

Flashing lights in case of an emergency, while my alarm panel is triggered or I have repeated the loop 500 times (this is for emergency exit of out the loop). That turns on my lights then toogle, delay and repeat.

sequence:
  - repeat:
      while:
        - condition: state
          entity_id: alarm_control_panel.home_alarm
          state: triggered
        - condition: template
          value_template: '{{ repeat.index <= 500 }}'
      sequence:
        - service: switch.turn_on
          entity_id: switch.inspiration_light_switch
        - service: light.turn_on
          target:
            entity_id: light.coloured_lights
          data:
            color_name: red
            brightness: 255
        - service: light.toggle
          data:
            color_name: red
          target:
            entity_id:
              - light.living_sofa_led_level_light_color_on_off
        - delay:
            seconds: 2
mode: single

Alarm Broadcast

While my alarm is triggered this script is going to call my broadcast all script with some text to speech to repeat a message every 10 seconds.

sequence:
  - repeat:
      while:
        - condition: state
          entity_id: alarm_control_panel.home_alarm
          state: triggered
        - condition: template
          value_template: '{{ repeat.index <= 50 }}'
      sequence:
        - service: script.broadcast_all
          data:
            message: >-
              SMILE you are on camera, the home owners and the police have been
              notified of your presence, please leave the building as soon as
              possible
        - delay:
            seconds: 10
mode: single

Party Mode

I just organised a gender reveal party, our first since the pandemic!

I wanted to loop all our coloured bulbs and light strips between pink and blue.

I created this input boolean called gender reveal, when this boolean is on then the script will work, as soon as the input boolean is turned off then it will quit the script after the last action.

If you want to change the colours change the inputs in the rgb_color

alias: Pink Blue Loop
sequence:
  - repeat:
      while:
        - condition: state
          entity_id: input_boolean.gender_reveal
          state: 'on'
      sequence:
        - service: light.turn_on
          target:
            entity_id:
              - light.under_cupboard_lightstrip
              - light.dining_lightstrip
              - light.kitchen_piano
          data:
            brightness_pct: 100
            rgb_color:
              - 255
              - 109
              - 255
        - service: switch.turn_off
          target:
            entity_id: switch.kitchen_under_cupboard_lights
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
        - service: light.turn_on
          target:
            entity_id:
              - light.under_cupboard_lightstrip
              - light.dining_lightstrip
              - light.kitchen_piano
          data:
            brightness_pct: 100
            rgb_color:
              - 188
              - 212
              - 230
        - delay:
            hours: 0
            minutes: 1
            seconds: 0
            milliseconds: 0
mode: single
icon: mdi:baby

Fading Lights

I’m using a input number to store the brightness level and decrease that each second!

#Fade Lights, input is Light to fade

fade_lights:
  alias: Fading Lights
  fields:
    light:
      description: Light to fade
      example: imac_lamp
  sequence:
    - variables:
        light_entity: light.{{ light }}
    # setting our input number to 255
    - service: input_number.set_value
      entity_id: input_number.brightness_level
      data:
        value: 255
    - repeat:
        while:
          - condition: numeric_state
            entity_id: input_number.brightness_level
            above: 0
        sequence:
          - service: light.turn_on
            target:
              entity_id: "{{ light_entity }}"
            data:
              brightness: "{{ states('input_number.brightness_level')|int }}"
          - delay:
              hours: 0
              minutes: 0
              seconds: 1
              milliseconds: 0
          - service: input_number.decrement
            entity_id: input_number.brightness_level

Gio

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts