Simple automation to clear a Sonos queue if the device has been paused for a specified time. This brings the media player back into “idle” state, otherwise it will always show a queued song. I have my devices set to a 6 hour timeout.
blueprint:
name: Clear Paused Sonos Queue
description: Clear a Sonos queue if the device has been paused for a specified time
domain: automation
input:
target_media_players:
name: Sonos Devices
description: The Sonos devices to clear
selector:
entity:
domain: media_player
integration: sonos
multiple: true
duration:
name: Duration
description: How long should the device be paused before clearing the queue
selector:
duration:
trigger:
- platform: state
entity_id: !input target_media_players
to: paused
for: !input duration
action:
- service: media_player.clear_playlist
target:
entity_id: '{{ trigger.entity_id }}'