Beyond Playback: Mastering Media Server Integration with Home Assistant (Plex & Kodi)
- #Home_Assistant
- #Media_Server
- #Plex
- #Kodi
- #Integration
- #Automation
- #Smart_Home

Your home entertainment system is a central hub of activity. Wouldn't it be great if your smart home could react intelligently to what you're watching or listening to? Integrating your media servers like Plex or Kodi with Home Assistant allows you to move beyond simple playback control and create dynamic, responsive automations that enhance your viewing and listening experience.
Why Integrate Media Servers with Home Assistant?
The benefits of connecting your media server to your smart home platform are numerous:
- Unified Control: Control playback (play, pause, stop, seek) directly from Home Assistant dashboards or companion apps.
- Contextual Automations: Trigger actions based on media state (e.g., dim lights when a movie starts, pause HVAC when playback is paused).
- Ambient Experiences: Create lighting scenes that sync with your media consumption (e.g., movie mode, music listening scene).
- Status Monitoring: See what's playing, who's watching (Plex), and the playback progress.
- Advanced Logic: Incorporate media state into complex automation sequences involving multiple devices.
Getting Started: Integrating Plex
Plex is a popular media server for organizing and streaming your personal media library. Home Assistant offers a robust official integration.
Prerequisites:
- A running Plex Media Server.
- Access to your Home Assistant instance.
- (Optional but Recommended) A Plex account for remote access setup, though local network access is sufficient for basic integration.
Setup Steps:
- In Home Assistant, navigate to Settings > Devices & Services.
- Click the + Add Integration button.
- Search for Plex and select it.
- Home Assistant will attempt to auto-discover local Plex servers. If yours appears, select it. Otherwise, you'll need to manually enter the server address (IP and port, e.g.,
192.168.1.100:32400
). - You may be prompted to log in to your Plex account or provide a Plex token. Using a token is often preferred for stability, especially if your server isn't linked to a Plex account or you want to avoid storing credentials directly. To get a token:
- Open a browser and navigate to
YOUR_PLEX_SERVER_IP:32400/web
. Log in if prompted. - Open a new tab and go to
YOUR_PLEX_SERVER_IP:32400/identity
. Your token will be displayed next toauthToken=
. Copy this value. - Paste the token into the Home Assistant configuration flow when requested.
- Select the clients/players you want Home Assistant to recognize (e.g., your smart TV app, mobile apps, web players).
- Click Finish.
Entities Created:
The Plex integration creates several entities:
- Media Player Entities: One for each selected client/player (e.g.,
media_player.living_room_tv
,media_player.plex_web_chrome
). These allow control (play, pause, stop, volume, seek) and show current media state (playing, paused, idle), title, artwork, etc. - Sensor Entities: Sensors showing server status, user activity (who is watching what), and playback sessions (
sensor.plex_server
,sensor.plex_account
,sensor.plex_sessions
).
Getting Started: Integrating Kodi
Kodi is a free and open-source media player software, often used on HTPCs, Raspberry Pis, or dedicated media boxes. Home Assistant also has an official integration for Kodi.
Prerequisites:
- A device running Kodi.
- Access to your Home Assistant instance.
- The Web server must be enabled in Kodi. In Kodi, go to Settings > Service > Control and enable Allow remote control via HTTP. Note the port (usually 8080) and optionally set a username and password.
Setup Steps:
- In Home Assistant, navigate to Settings > Devices & Services.
- Click the + Add Integration button.
- Search for Kodi and select it.
- Enter the IP address of the device running Kodi, the port (default 8080), and the username/password if you set one in Kodi's web server settings.
- Click Submit.
- If the connection is successful, you'll be able to name the device.
- Click Finish.
Entities Created:
The Kodi integration primarily creates:
- Media Player Entity: One for the Kodi instance (e.g.,
media_player.kodi_living_room
). This provides control over playback, volume, and displays current media information.
The Kodi integration is generally simpler than Plex, focusing more on direct control of the player instance.
Creative Automation Examples
Now that your media server is integrated, let's explore some powerful automations:
Automation 1: Dim Lights for Movie Night
Trigger: Media player starts playing (and maybe state changes from 'idle' to 'playing' and media type is 'movie').
Condition: Check if the light is currently on.
Action: Turn off or dim relevant lights (e.g., living room lights) to a low level or specific scene.
automation:
- alias: Dim lights on movie start
description: Dim lights when a movie starts playing on the living room Plex player
trigger:
- platform: state
entity_id: media_player.living_room_tv
to: 'playing'
condition:
- condition: template
value_template: "{{ state_attr('media_player.living_room_tv', 'media_content_type') == 'movie' }}"
- condition: state
entity_id: light.living_room_main_light
state: 'on'
action:
- service: light.turn_on
target:
entity_id: light.living_room_main_light
data:
brightness_pct: 10
transition: 5
mode: single
Automation 2: Pause Lights on Pause/Stop
Trigger: Media player state changes to 'paused' or 'idle'.
Condition: Check if the lights were previously dimmed by the movie start automation (this requires more advanced state tracking or helper entities, or simply reverse the dimming).
Action: Turn lights back on to a comfortable level or the state they were in before dimming.
automation:
- alias: Restore lights on movie pause/stop
description: Turn lights back on when movie is paused or stopped
trigger:
- platform: state
entity_id: media_player.living_room_tv
to: 'paused'
- platform: state
entity_id: media_player.living_room_tv
to: 'idle'
condition:
# Optional: Check if the lights are currently dimmed low, assuming only the movie automation does this
- condition: template
value_template: "{{ state_attr('light.living_room_main_light', 'brightness') | int(0) < 50 }}"
action:
- service: light.turn_on
target:
entity_id: light.living_room_main_light
data:
brightness_pct: 80 # Or restore to previous state if tracked
transition: 5
mode: single
Automation 3: Announce Who Started Watching (Plex)
Trigger: Sensor showing Plex sessions changes.
Condition: New session appears.
Action: Send a notification or use a text-to-speech service to announce which user started watching something on which player.
automation:
- alias: Announce new Plex session
description: Announce when a user starts watching something on Plex
trigger:
- platform: state
entity_id: sensor.plex_sessions
condition:
- condition: template
# Trigger fires on any state change; check if the number of sessions increased (a new one started)
value_template: "{{ trigger.to_state is not none and trigger.from_state is not none and trigger.to_state.state | int(0) > trigger.from_state.state | int(0) }}"
action:
# This is simplified. A more robust automation would parse sensor.plex_sessions attributes
# to get specific user/title info and avoid multiple announcements for the same session.
# Example parsing data from attributes:
# {% set sessions = state_attr('sensor.plex_sessions', 'sessions') %}
# {% if sessions %}
# {% set latest_session = sessions[-1] %}
# {% set user = latest_session['user'] %}
# {% set title = latest_session['title'] %}
# {% set player = latest_session['player'] %}
# service: tts.google_say
# data:
# entity_id: media_player.kitchen_speaker
# message: "{{ user }} started watching {{ title }} on the {{ player }}"
# {% endif %}
- service: notification.push
data:
message: "New Plex session detected!"
mode: single # Or queued if many sessions might start simultaneously
Automation 4: Control Kodi Volume with a Button Press
Trigger: Physical button press (e.g., Flic button, Z-Wave scene controller).
Action: Call the media_player.volume_up
or media_player.volume_down
service targeting your Kodi entity.
automation:
- alias: Increase Kodi volume via button
description: Increase volume of Kodi when a specific button is pressed
trigger:
- platform: state
entity_id: binary_sensor.flic_button_1_button
to: 'on'
condition: [] # Optional: Check if Kodi is currently playing or on
action:
- service: media_player.volume_up
target:
entity_id: media_player.kodi_living_room
mode: single
Best Practices for Media Server Integration
- Static IPs: Assign static IP addresses to your media server and Kodi devices to prevent integration breakage due to IP changes.
- Network Stability: Ensure your network is stable and reliable, especially for Wi-Fi devices running Kodi or Plex clients.
- Resource Usage: Be mindful that frequent polling for media state updates (though integrations are optimized) adds a small load to both your media server and Home Assistant.
- Token Security (Plex): If using tokens, treat them like passwords. Avoid exposing your Home Assistant instance unnecessarily if you use token authentication.
- Password Protect Kodi Web Server: Always set a username and password for the Kodi web server for security.
- Keep Software Updated: Ensure your Home Assistant, Plex Media Server, Plex clients, and Kodi instances are kept up-to-date for the latest features and bug fixes.
- Consider Multiple Players: If you have multiple clients (e.g., Plex on TV, Plex on tablet), integrate the ones you want to control or monitor for automation purposes.
Conclusion
Integrating Plex and Kodi with Home Assistant transforms your passive media consumption into an active part of your smart home ecosystem. From automating lighting based on playback to getting notified about who's watching what, the possibilities are vast. By following these setup steps and considering the best practices, you can build a more immersive and responsive entertainment experience powered by Home Assistant.

NGC 224
Author bio: