Max volume script / automation for media players

After getting Alexa hooked up to my Sonos of course my kid told it set the volume to 100.

Does anyone have a max volume script / automation that will reset/adjust the volume to a level if it is set over a specific level. I think I could write one that handled a single Sonos but not sure how to loop through all players. Just seeing if someone had one already written.

I have tried something similar to what you say but some media player components like mpd or onkyo seems ignore media player generated events :cry: A possible workaround is set the scan period to one second to compensate this.

High volumen detection:

  - alias: Volume too high
    trigger:
      platform: numeric_state
      entity_id: media_player.onkyo
      value_template: '{{ state.attributes.volume_level }}'
      above: 0.25
    action:
      - service: notify.to_file
        data:
          message: Volumen too high

Anyway to do this for all media players of type sonos vs writing it for each one?