Introduction:
In this project, I implemented a set of automations, scripts, and helpers to seamlessly manage my media player using vlc-telnet with the wyoming satellite setup on linux and raspberry pi. By integrating the voice assistant with the media player on the same playback device, I can ensure that my entertainment experience is smooth and interruption-free. Below, I share the details of my automations, which include handling media playback and saving the current media position for resuming playback later.
Automations:
- Handle Satellite and Media Player:
- Description: This automation ensures that the media player stops playback when the satellite is turned on, and resumes playback when the satellite is idle.
- Triggers:
- The automation is triggered when the satellite starts listening or responding by announce.
- Actions:
- If the media player is currently playing, it stops the playback.
- Waits for the satellite to go back to “idle.”
- After a brief delay, resumes playback on the media player.
- If the media player has a non-zero media duration, it seeks to the previously saved position.
- If the media player is not playing, it simply stops the media player.
alias: Handle satellite and media player
description: ""
triggers:
- trigger: state
entity_id:
# Use your actual satellite entity id
- assist_satellite.my_satellite
to: listening
- trigger: state
entity_id:
- assist_satellite.my_satellite
to: responding
conditions: []
actions:
- if:
- condition: device
device_id: c87c30244ab002eaed5161fe1bc34ac5
domain: media_player
entity_id: d00fe3b645714f7e8d79c576fc4812bc
type: is_playing
# Use your actual media player device and entity id
then:
- action: automation.turn_off
target:
entity_id:
- automation.save_media_player_position
data:
stop_actions: true
- action: media_player.media_stop
target:
entity_id:
- media_player.vlc_telnet
data: {}
- wait_for_trigger:
- trigger: state
entity_id:
- assist_satellite.my_satellite
to: idle
- delay:
hours: 0
minutes: 0
seconds: 10
milliseconds: 0
- action: media_player.media_play
metadata: {}
data: {}
target:
entity_id: media_player.vlc_telnet
- if:
- condition: state
entity_id: media_player.vlc_telnet
attribute: media_duration
state: "0"
then:
- action: media_player.media_seek
metadata: {}
data:
seek_position: "{{ states('input_number.bedroom_media_player_position') | int}}"
target:
entity_id: media_player.vlc_telnet
- action: automation.turn_on
target:
entity_id:
- automation.save_media_player_position
data: {}
else:
- action: media_player.media_stop
target:
entity_id:
- media_player.vlc_telnet
data: {}
mode: single
- Save Media Player Position:
- Description: This automation saves the current position of the media player when it is playing, ensuring that playback can be resumed from the same point later.
- Triggers:
- The automation is triggered when the media player starts playing or the media position changes.
- Conditions:
- The media player must have a media position above 0.
- Actions:
- After a brief delay, it saves the current media position to an input number entity.
alias: Save media player position
description: ""
triggers:
# Use your actual media player device and entity id
- device_id: c87c30244ab002eaed5161fe1bc34ac5
domain: media_player
entity_id: d00fe3b645714f7e8d79c576fc4812bc
type: playing
trigger: device
- trigger: state
entity_id:
- media_player.vlc_telnet
attribute: media_position
conditions:
- condition: numeric_state
entity_id: media_player.vlc_telnet
attribute: media_position
above: 0
actions:
- delay:
hours: 0
minutes: 0
seconds: 10
- data_template:
# Use your actual created helper entity id for media player position
entity_id: input_number.bedroom_media_player_position
value: "{{state_attr('media_player.vlc_telnet', 'media_position')}}"
action: input_number.set_value
mode: single
Conclusion:
These automations enhance the user experience by providing a seamless transition between media playback and voice assistant interactions. By stopping and resuming playback intelligently, I ensure that my media content is always in sync with my activities.
Feel free to try out these automations and share your feedback or improvements!