How do i use this?

Hi,

I cant understand how I can use a script like this. There are no instructions :wink:

Can anyone explain how I can use it?

##################################################
## Customize
##################################################

homeassistant:
  customize:
    input_select.tv_station:
      icon: mdi:television-classic
#    tv_script:
#      friendly_name: Starta
#      icon: mdi:play-pause

##################################################
## Input
##################################################

input_select:
  tv_station:
    name: TV Kanaler
    options:
     - Barnkanalen
     - 'SVT 1'
     - 'SVT 2'
    initial: Barnkanalen
  chromecast_tv:
    name: 'Välj tv:'
    options:
     - 'Kök'
     - Vardagsrum
    initial: 'Kök'

input_number:
  volume_tv:
    name: Volym
    icon: mdi:volume-high
    initial: 0.3
    min: 0
    max: 1
    step: 0.05

##################################################
## Script
##################################################

script:
  tv_script:
    alias: 'Byt TV-Kanal'
    sequence:
    - service: media_player.volume_set
      data_template:
        entity_id: media_player.screen_kitchen
        volume_level: '{{  states.input_slider.volume_tv.state  }}'
    - service: media_player.play_media
      data_template:
        entity_id: >
         {% if is_state("input_select.chromecast_tv", "Kök") %} media_player.screen_kitchen
         {% elif is_state("input_select.chromecast_tv", "Vardagsrum") %} media_player.chromecast
         {% endif %}
        media_content_id: >
         {% if is_state("input_select.tv_station", "Barnkanalen") %}
            https://svtb-b.akamaized.net/se/svtb/master.m3u8
         {% elif is_state("input_select.tv_station", "SVT 1") %}
            https://svt1-b.akamaized.net/se/svt1/master.m3u8
         {% elif is_state("input_select.tv_station", "SVT 2") %}
            https://svt2-b.akamaized.net/se/svt2/master.m3u8
         {% endif %}
        media_content_type: 'video/mp4'

##################################################
## Group
##################################################

group:
  tv_card:
    name: TV
    control: hidden
    entities:
      - input_select.tv_station
      - input_select.chromecast_tv
      - input_number.volume_tv
      - script.tv_script
      - media_player.screen_kitchen

##################################################
## Automation
##################################################

automation:
  alias: 'Set TV Volume'
  hide_entity: true
  trigger:
    platform: state
    entity_id: input_number.volume_tv
  action:
    service: media_player.volume_set
    data_template:
      entity_id: >
        media_player.screen_kitchen

Where did you get that config from?

If i understand correctly you want to add the code to your config?

Easiest way to use this is to add it to your config as a new package.

Add a folder named packages inside your config dir, create a file named whatever.yaml and paste the whole thing in there.
Then to enable packages add something like this into your configuration.yaml, under the homeassistant: part.

homeassistant:
  packages: !include_dir_named packages/

Alternatively you need to get every part of the code and paste it under the equivalent existing header of your config.
ie: this must go under an input_select: part of your existing configuration.yaml

  tv_station:
    name: TV Kanaler
    options:
     - Barnkanalen
     - 'SVT 1'
     - 'SVT 2'
    initial: Barnkanalen

This goes under group:

  tv_card:
    name: TV
    control: hidden
    entities:
      - input_select.tv_station
      - input_select.chromecast_tv
      - input_number.volume_tv
      - script.tv_script
      - media_player.screen_kitchen

and so on…

After a restart (or reload of the equivalent parts) the new toys you created will be available to add to your lovelace ui

1 Like

Hi,

I found it here

//Per

My problem is that i don’t understand how to add it to lovelace.

Add what to loveleace?

A card that allows me to choose player channel etc.
Im still a newbie

input_select:
tv_station:
name: TV Kanaler
options:
- Barnkanalen
- ‘SVT 1’
- ‘SVT 2’
initial: Barnkanalen
chromecast_tv:
name: ‘Välj tv:’
options:
- ‘Kök’
- Vardagsrum
initial: ‘Kök’

Add a new card in lovelace, select type: entities, and search for the names of your input_select in the dropdown.