How to Control your TV with Home Assistant


Our TVs are the centre of our home, we spend a lot of time in front of them, how can we get them to be more useful by integrating them into our smart home, my smart home system of choice is Home Assistant which is open source and very powerful.

In this post I’m going to show you how I integrated my two TVs and some automation ideas that you can follow along me to implement in your own home.

Which TV Brands?

To get the latest link to got the home assistant integration page, I have a Samsung Smart TV from 4/5 years ago (UE49KU6670) and a more recent LG C2 which I purchased at the end of 2022.

Adding TV to Home Assistant

Go to settings, devices and services, click on the plus button and search for your specific brand.

Follow the instructions on screen! If you get prompted with an IP address do this first

  • Go to your router and give your device a fixed IP address, you can also do this from your TV if you don’t know how to access your router admin page.

At this stage you are now able to see what is playing on your TV, change media sources, change volumes, mute and turn the TV off. Most likely there will be one feature missing turning the TV on!

How to turn the TV on from Home Assistant

We are going to use an integration called WOL (wake on Lan) to achieve this we are going to need a few things!

First we need to connect our TV to an ethernet cable not using WIFI

Then, look in your menu on your TV to allow third party devices to turn on the device. It could be obvious or require a bit of googling with your specific TV model.

You are going to need two things at this stage, the MAC address and the entity ID in home assistant. The MAC address you can find it from your TV network setting or from your router settings. The entity ID of the media player from developer tools or the integration page itself.

Now go to home assistant under configuration.yaml

switch:
  - platform: wake_on_lan
    mac: ac:5a:f0:36:75:3e
    name: "Living TV switch"
    turn_off:
      service: media_player.turn_off
      target:
        entity_id: media_player.living_tv
  - platform: wake_on_lan
    mac: 5c:49:7d:b0:73:93
    name: "Kitchen TV switch"
    turn_off:
      service: media_player.turn_off
      target:
        entity_id: media_player.samsung_6_series_49   

In the code above I’m creating two WOL switches, one for my Kitchen TV and the other for the living room.

The turn_off service will allow you to turn off your TV from the same switch.

Exploring what you can DO

From the integration page this is how the media player looks:

Dashboard Tile

You can create cool dashboard tiles with Logos that turn certain channels on.

First create an image that is 500 by 500 pixel, you can use a tool like canva.com for free.

Then upload the image in the www folder in home assistant, rename the file if you haven’t already.

Now you can reference that file and a script like in the code below:

Add a manual card in a dashboard and paste this in!

type: picture
image: /local/netflix.png
tap_action:
  action: call-service
  service: script.kitchen_netflix
  target: {}
  data: {}
hold_action:
  action: call-service
  service: switch.turn_off
  target:
    entity_id: switch.kitchen_tv_switch
  data: {}

Script

A script is a sequence of actions that you want home assistant to take. In this context we would ask it, to turn the TV on, select a specific media source etc.

Here is an example from my code base:

alias: Kitchen TV (Apple TV)
sequence:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
        - switch.wake_on_lan
  - alias: Wait 5s
    delay: 5
  - service: media_player.select_source
    data:
      source: HDMI2
    target:
      entity_id: media_player.samsung_6_series_49
mode: single
icon: mdi:apple

Gio

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

Recent Posts