Autor Thema: Template für Sonos mit MQTT  (Gelesen 630 mal)

Offline australien

  • Full Member
  • ***
  • Beiträge: 329
Template für Sonos mit MQTT
« am: 25 März 2022, 08:44:31 »
Hallo zusammen,

ich betreibe meine Sonos mit MQTT https://forum.fhem.de/index.php/topic,111711.0.html und würde gerne das vorhandene Templete des sonosplayer überarbeiten oder ein neues schreiben.
Leider werde ich mit der Zuordnung der Readings nicht ganz eins.

Hat schon jemand so ein template für sich angepasst?

original sonosplayer template
{
  "name": "sonosplay",
  "author": "jemu75",
  "date": "2021-05-03",
  "expand": true,
  "status": {
    "bar": ["transportState:PLAYING:100:success", "transportState::0:success"]
  },
  "main": [
    {
      "leftBtn": ["currentTrackProvider:Radio:mdi-skip-previous:disabled","currentTrackProvider::mdi-skip-previous"],
      "leftClick": ["state::previous"],
      "midBtn": ["transportState:PLAYING:mdi-pause", "currentTrackProvider::mdi-play"],
      "text": ["state::keine Musik ausgewählt"],
      "midClick": ["transportState:PLAYING:Pause", "transportState::Play"],
      "rightBtn": ["currentTrackProvider:Radio:mdi-skip-next:disabled","currentTrackProvider::mdi-skip-next"],
      "rightClick": ["state::next"]
    },
    {
      "leftBtn": ["GroupMute:1:mdi-volume-high", "GroupMute:0:mdi-volume-mute"],
      "leftClick": ["GroupMute:1:mute 0", "GroupMute:0:Mute 1"],
      "slider": ["GroupVolume::GroupVolume %v:%n:0:40"]
    },
    {
      "text": ["currentTrackPositionSimulated::%s"],
      "text2": ["currentTrackProvider:Radio:", "tracks_app::%s"]
    }
  ],
  "info": {
    "left1": ["Mute:1::mdi-volume-off", "transportState:PLAYING::mdi-play", "transportState:::mdi-pause"],
    "left2": ["currentArtist:$:%s", "currentSource::%s"],
    "right2": ["currentTitle::%s"]
  }
}

geänderte Version, hier funktioniert zur Zeit nur play/pause und die Anzeige in der info bar.
{
  "name": "sonosplay_mqtt",
  "author": "robert",
  "date": "2022-03-24",
  "expand": true,
  "status": {
    "bar": ["state:PLAYING:100:success", "state::0:success"]
  },
  "main": [
    {
      "leftBtn": ["nextTrackHandle:.\\|:mdi-skip-previous","nextTrackHandle::mdi-skip-previous:disabled"],
      "leftClick": ["state::previous"],
      "midBtn": ["state:PLAYING:mdi-pause", "state::mdi-play"],
      "midClick": ["state:PLAYING:pause", "state::play"],
      "rightBtn": ["nextTrackHandle:\\|.:mdi-skip-next","nextTrackHandle::mdi-skip-next:disabled"],
      "rightClick": ["state::next"]
    },
    {
      "leftBtn": ["mute:flase:mdi-volume-high", "mute:true:mdi-volume-mute"],
      "leftClick": ["mute:1:mute 0", "mute:0:Mute 1"],
      "slider": ["volume::volume %v:%n:0:70"]
    },
    {
      "text": ["currentTrackPositionSimulated::%s"],
      "text2": ["nextTrackHandle:^\\|:", "tracks_app::%s"]
    }
  ],
  "info": {
    "left1": ["mute:true::mdi-volume-off", "state:PLAYING::mdi-play", "state:::mdi-pause"],
    "left2": ["currentTrack_Artist:$:%s", "currentSource::%s"],
    "right2": ["currentTrack_Title::%s"]
  }
}


die vorhandenen Readings aus meinem Sonos MQTT
coordinatorUuid RINCON_7828CAC1D85001400 24.03.2022 12:20
currentTrack_Album unerhört solide 24.03.2022 12:20
currentTrack_AlbumArtUri http://10.68.0.140:1400/getaa?s=1&u=x-sonos-spotify:spotify:track:2n13lo5NQFQC9qqtzz6oe9%3fsid%3d9%26flags%3d8224%26sn%3d2 24.03.2022 12:20
currentTrack_Artist Pizzera & Jaus 24.03.2022 12:20
currentTrack_Duration 00:04:07 24.03.2022 12:20
currentTrack_ItemId -1 24.03.2022 12:20
currentTrack_ParentId -1 24.03.2022 12:20
currentTrack_ProtocolInfo sonos.com-spotify:*:audio/x-spotify:* 24.03.2022 12:20
currentTrack_Title warm & wärmer 24.03.2022 12:20
currentTrack_TrackUri x-sonos-spotify:spotify:track:2n13lo5NQFQC9qqtzz6oe9?sid=9&flags=8224&sn=2 24.03.2022 12:20
currentTrack_UpnpClass object.item.audioItem.musicTrack 24.03.2022 12:20
enqueuedMetadata_Album unerhört solide 24.03.2022 12:20
enqueuedMetadata_AlbumArtUri https://i.scdn.co/image/ab67616d0000b273e6e047572860671c4b973fc1 24.03.2022 12:20
enqueuedMetadata_Artist Pizzera & Jaus 24.03.2022 12:20
enqueuedMetadata_ItemId 1004206cspotify%3aalbum%3a7DBxuMNcIGUUPGpy3To40o 24.03.2022 12:20
enqueuedMetadata_ParentId 10052064spotify%3aartist%3a355ClqG0dW1RFLQ2kXloTp 24.03.2022 12:20
enqueuedMetadata_Title unerhört solide 24.03.2022 12:20
enqueuedMetadata_UpnpClass object.container.album.musicAlbum 24.03.2022 12:20
error_Action Play 03.04.2021 14:17
error_Fault UPnPError 03.04.2021 14:17
error_FaultCode s:Client 03.04.2021 14:17
error_UpnpErrorCode 701 03.04.2021 14:17
error_name SonosError 03.04.2021 14:17
groupName Terrasse 24.03.2022 12:20
modelNumber S13 14.09.2020 11:02
mute false 24.03.2022 12:04
mute_LF false 24.03.2022 12:04
mute_Master false 14.09.2020 11:02
mute_RF false 24.03.2022 12:04
name Terrasse 24.03.2022 12:20
nextTrack_Album unerhört solide 24.03.2022 12:20
nextTrack_AlbumArtUri http://10.68.0.140:1400/getaa?s=1&u=x-sonos-spotify:spotify:track:3sIUqTiWB2eok1HGzokqit%3fsid%3d9%26flags%3d8224%26sn%3d2 24.03.2022 12:20
nextTrack_Artist Pizzera & Jaus 24.03.2022 12:20
nextTrack_Duration 00:02:59 24.03.2022 12:20
nextTrack_ItemId -1 24.03.2022 12:20
nextTrack_ParentId -1 24.03.2022 12:20
nextTrack_ProtocolInfo sonos.com-spotify:*:audio/x-spotify:* 24.03.2022 12:20
nextTrack_Title jedermann 24.03.2022 12:20
nextTrack_TrackUri x-sonos-spotify:spotify:track:3sIUqTiWB2eok1HGzokqit?sid=9&flags=8224&sn=2 24.03.2022 12:20
nextTrack_UpnpClass object.item.audioItem.musicTrack 24.03.2022 12:20
playmode NORMAL 24.03.2022 12:20
state PAUSED_PLAYBACK 24.03.2022 12:20
transportState STOPPED 14.09.2020 11:02
ts 1,64812E+12 24.03.2022 12:20
uuid RINCON_7828CAC1D85001400 24.03.2022 12:20
volume 11 24.03.2022 12:20
volume_LF 100 24.03.2022 12:20
volume_Master 29 14.09.2020 11:02
volume_RF 100 24.03.2022 12:20

raspberry pi3
signalduino, Shelly1, Shelly2, Sonos, Unifi
Amazon Fire Tablet 7 | Noname Android Tablet 10"

Offline jemu75

  • Moderator
  • Sr. Member
  • ***
  • Beiträge: 840
    • FHEM App
Antw:Template für Sonos mit MQTT
« Antwort #1 am: 25 März 2022, 09:55:01 »
Hallo,

in der Definition fallen mir auf Anhieb zwei Sachen auf.
      "leftBtn": ["mute:flase:mdi-volume-high", "mute:true:mdi-volume-mute"],
      "leftClick": ["mute:1:mute 0", "mute:0:Mute 1"],

1. bei leftBtn steht flase -> das sollte bestimmt false heißen
2. bei leftClick ist mute einmal groß und einmal klein geschrieben (bin mir hier nicht sicher, ob FHEM die Befehle case-sensitive behandelt

Offline australien

  • Full Member
  • ***
  • Beiträge: 329
Antw:Template für Sonos mit MQTT
« Antwort #2 am: 25 März 2022, 10:48:57 »
du hattest recht! Richtig lautet es

"leftBtn": ["mute:false:mdi-volume-high", "mute:true:mdi-volume-mute"],
 "leftClick": ["mute:false:mute true", "mute:true:mute false"],

jetzt bekomme ich nur noch keine previous und next Buttons
raspberry pi3
signalduino, Shelly1, Shelly2, Sonos, Unifi
Amazon Fire Tablet 7 | Noname Android Tablet 10"

Offline australien

  • Full Member
  • ***
  • Beiträge: 329
Antw:Template für Sonos mit MQTT
« Antwort #3 am: 25 März 2022, 11:21:08 »
und hier sind noch die next und previus buttons

      "leftBtn": ["currentTrack_ProtocolInfo:sonos.com-http:mdi-skip-previous:disabled","currentTrack_ProtocolInfo::mdi-skip-previous"],
      "leftClick": ["state::previous"],
      "midBtn": ["state:PLAYING:mdi-pause", "state::mdi-play"],
      "midClick": ["state:PLAYING:pause", "state::play"],
      "rightBtn": ["currentTrack_ProtocolInfo:sonos.com-http:mdi-skip-next:disabled","currentTrack_ProtocolInfo::mdi-skip-next"],
      "rightClick": ["state::next"]
raspberry pi3
signalduino, Shelly1, Shelly2, Sonos, Unifi
Amazon Fire Tablet 7 | Noname Android Tablet 10"

Offline australien

  • Full Member
  • ***
  • Beiträge: 329
Antw:Template für Sonos mit MQTT
« Antwort #4 am: 25 März 2022, 12:21:05 »
jetzt wäre noch ein Auswahl-, Listenfeld für die Favoriten ideal.
Gibt es schon einen Ansatz, wie man so was realisieren kann?
raspberry pi3
signalduino, Shelly1, Shelly2, Sonos, Unifi
Amazon Fire Tablet 7 | Noname Android Tablet 10"

Offline binford6000

  • Tester
  • Hero Member
  • ****
  • Beiträge: 1503
  • 🏠⚙️💡🛠📱
Antw:Template für Sonos mit MQTT
« Antwort #5 am: 25 März 2022, 14:28:55 »
Zitat
Hat schon jemand so ein template für sich angepasst?

Ja!

{
"name": "sonosmqtt",
"author": "binford6000",
  "date": "2021-05-01",
"size": "col-12 col-sm-12 col-md-6 col-lg-6 col-xl-6",
"expand": true,
"status": {
"bar": ["transportState:PLAYING:100:success","transportState:TRANSITIONING:100:warning","transportState:(STOPPED|PAUSED_PLAYBACK):100:error"],
"error": []
},
"main": [
    {
    "leftBtn": ["mute:true:mdi-volume-off","mute:false:mdi-volume-high"],
"leftClick": ["mute:false:mute true","mute:true:mute false"],
    "text": ["state::midButton"],
    "midBtn": ["transportState:PLAYING:mdi-pause","transportState::mdi-play"],
"midClick": ["transportState::toggle"],
    "rightBtn": "mdi-menu",
"rightMenu": [
        "1-FM-Chillout:playFav 1.FM.-.Chillout.Lounge.Radio",
        "Absolute-Chillout:playFav ABSOLUTE.CHILLOUT",
"Antenne-Chillout:playFav ANTENNE.BAYERN.Chillout",
"bigFM-Sunset-Lounge:playFav bigFM.Sunset.Lounge",
"BlueMarlin:playFav BLUE.MARLIN.IBIZA.RADIO",
"Chillout-Zone:playFav Chillout.Zone",
"Costa-Del-Mar:playFav Costa.Del.Mar.-.Chillout",
"Deep-One:playFav DEEP.ONE.radio",
"FFH-Loung:playFav FFH.Lounge",
"I-Love-The-Beach:playFav I.Love.The.Beach",
"Ibiza_Unique:playFav Ibiza.Unique",
"Lounge-FM:playFav Lounge.FM.Digital",
"M1-FM-Chillout:playFav M1.FM.Chillout",
"Northcoast:playFav Northcoast.Radio",
"Relax.Zone:playFav Relax.Zone",
"FFH-Soundtrack:playFav FFH.Soundtrack.(Filmmusik)",
"Best-of-Rock:playFav RADIO.BOB!.BOBs.Best.of.Rock",
"Grunge:playFav RADIO.BOB!.BOBs.Grunge",
"Hardrock:playFav RADIO.BOB!.BOBs.Hardrock",
"Kuschelrock:playFav RADIO.BOB!.BOBs.Kuschelrock",
"Metal:playFav RADIO.BOB!.BOBs.Metal",
"SWR3:playFav SWR3.Elchradio.99.6.(Adult.Contemporary)",
"hr-Info:playFav hr-iNFO",
"hr3:playFav hr3.89.3.(Hot.AC)"
]
    },
    {
    "leftBtn": "mdi-volume-minus",
    "leftClick": ["volume::volumeDown"],
    "slider": ["volume::volume %v:%n:0:40:1"],
    "rightBtn": "mdi-volume-plus",
"rightClick": ["volume::volumeUp"]
},
    {
    "leftBtn": "mdi-rewind",
    "leftClick": ["transportState::previous"],
    "midBtn": ["transportState:PLAYING:mdi-sleep","transportState::mdi-sleep-off"],
"midClick": ["transportState:PLAYING:stop","transportState:STOPPED:play"],
    "rightBtn": "mdi-fast-forward",
"rightClick": ["transportState::next"]
},
    {
    "leftBtn": "mdi-ungroup",
    "leftClick": ["transportState::leaveGroup"],
    "midBtn": ["transportState:PLAYING:mdi-stop","transportState::mdi-play"],
"midClick": ["transportState:PLAYING:stop","transportState:STOPPED:play"],
    "rightBtn": "mdi-group",
"rightMenu": ["One: joinGroup One","Play1:joinGroup Play1","Roam: joinGroup Roam","Beam:joinGroup Beam"]
}
    ],
"info": {
"left1": ["transportState:PLAYING::mdi-play","transportState:TRANSITIONING::mdi-transition-masked","transportState:PAUSED::mdi-pause:error","transportState:STOPPED::mdi-stop:error"],
"left2": ["fhemApp_currentTrack::%s"],
    "mid": [""],
"right1": [""],
"right2": ["fhemApp_enqueuedMetadata::%s"]
}
}

fhemApp_enqueuedMetadata ist dabei ein Reading welches ich mit einer Funktion generiere:
sub track_fhemApp($) {
  my ($dev) = @_;
  my $track;
  my $source;
  my $input = ReadingsVal($dev,'Input',undef);
  my $media = ReadingsVal($dev,'enqueuedMetadata_Title',undef);
  my $artist = ReadingsVal($dev,'currentTrack_Artist',undef);
  my $title = ReadingsVal($dev,'currentTrack_Title',undef);
  my $channel = ReadingsVal('vuplus','channel',undef);
  ## Track erfassen:
  if ($input eq "TV") {
    $track = ReadingsVal('vuplus','currentTitle',undef);
  }
  else {
    if ($media !~ /hr-iNFO|SWR3/) {
      if ($artist !~ /ZPSTR_BUFFERING/) {
    $track = $title." von ".$artist;
  }
  elsif ($artist =~ /ZPSTR_BUFFERING/) {
    $track = $media.": Werbung";
  }
    }
    elsif ($media eq "hr-iNFO")  {
      $track = "Nachrichten";
    }
    elsif ($media =~ /hr.3/) {
      $track = $title.": ".$artist;
    }
elsif ($media =~ /SWR3/) {
      $track = $artist;
    }
  }
  ## Quelle erfassen:
  if ($input eq "Radio") {
    $source = $input.": ".$media;
  }
  elsif ($input eq "TV") {
    $source = $input.": ".$channel;
  }
  else {
  $source = $input.": "."Streaming";
  }
  fhem("setreading $dev fhemApp_currentTrack $track");
  fhem("setreading $dev fhemApp_enqueuedMetadata $source");
}

Das Menü mit den Sendern habe ich im FHEM Device als setList mit playFav hinterlegt.
Musst natürlich beides auf deine Bedürfnisse anpassen...  ;)

VG Sebastian

PS: Mit ein paar notifys bekommen auch alle Group-Members die korrekte Station und track usw...
« Letzte Änderung: 25 März 2022, 14:30:37 von binford6000 »
Proxmox mit: nextcloud, fhem, pihole, docker, bitwarden, deconz, TasmoAdmin
fhem mit: deconz, Sonos2mqtt, alexa-fhem, Telegram, livetracking, fhemApp als Frontend
Testumgebung: docker pull fhem/fhem

Offline australien

  • Full Member
  • ***
  • Beiträge: 329
Antw:Template für Sonos mit MQTT
« Antwort #6 am: 30 März 2022, 11:40:08 »
@binford6000,

warum wird bei deiner Ausführung ein Menü angezeigt, bei meiner nicht?
Auch wenn ich deine Einträge nur ändere, kommt kein Menü bei mir?

{
  "name": "sonosplay_mqtt",
  "author": "robert",
  "date": "2022-03-24",
  "expand": true,
  "status": {
    "bar": ["transportState:PLAYING:100:success","transportState:TRANSITIONING:100:warning","transportState:(STOPPED|PAUSED_PLAYBACK):100:error"],
"error": []
  },
  "main": [
    {
      "leftBtn": ["currentTrack_ProtocolInfo:sonos.com-http:mdi-skip-previous:disabled","currentTrack_ProtocolInfo::mdi-skip-previous"],
      "leftClick": ["transportState::previous"],
      "midBtn": ["transportState:PLAYING:mdi-pause", "transportState::mdi-play"],
      "midClick": ["transportState::toggle"],
      "rightBtn": ["currentTrack_ProtocolInfo:sonos.com-http:mdi-skip-next:disabled","currentTrack_ProtocolInfo::mdi-skip-next"],
      "rightClick": ["state::next"]
    },
    {
      "leftBtn": ["mute:false:mdi-volume-high", "mute:true:mdi-volume-mute"],
      "leftClick": ["mute:false:mute true", "mute:true:mute false"],
      "slider": ["volume::volume %v:%n:0:70"],

    "rightBtn": "mdi-menu",
"rightMenu": [
"2Day.Buddha.(Chill):playFav 2Day.Buddha.(Chill)",
"Boom:play Boom",
"Gold.FM:playFav Gold.FM",
"Heart.80s:playFav Heart.80s",
"Hitradio.Ö3:playFav Hitradio.Ö3",
"ORF.Radio.Burgenland:playFav ORF.Radio.Burgenland",
"Sydneys-2CH:playFav Sydneys-2CH",
"Triple.M.Greatest.Hits.(Classic.Rock):playFav Triple.M.Greatest.Hits.(Classic.Rock)",
"ooe.Radio.Oberösterreich:playFav ooe.Radio.Oberösterreich",
"smooth.fm.Brisbane:playFav smooth.fm.Brisbane"
]
    },
{
      "text": ["nextTrack_Artist::%s"],
      "text2": ["nextTrack_Title::%s"]
    }
  ],
  "info": {
    "left1": ["mute:true::mdi-volume-off", "transportState:PLAYING::mdi-play", "transportState:::mdi-pause"],
    "left2": ["currentTrack_Artist:$:%s"],
    "right2": ["currentTrack_Title::%s"]
  }
}
raspberry pi3
signalduino, Shelly1, Shelly2, Sonos, Unifi
Amazon Fire Tablet 7 | Noname Android Tablet 10"

Offline binford6000

  • Tester
  • Hero Member
  • ****
  • Beiträge: 1503
  • 🏠⚙️💡🛠📱
Antw:Template für Sonos mit MQTT
« Antwort #7 am: 03 April 2022, 16:10:25 »
Probier mal das Menü nicht mit einem Slider zu kombinieren.
VG Sebastian
Proxmox mit: nextcloud, fhem, pihole, docker, bitwarden, deconz, TasmoAdmin
fhem mit: deconz, Sonos2mqtt, alexa-fhem, Telegram, livetracking, fhemApp als Frontend
Testumgebung: docker pull fhem/fhem

 

decade-submarginal