What I would like to do though is to set the icon to the current album art (I do have the url), is that possible?

Moderators: leecollings, remb0
Can you share how you get the Sonos text in your text dummy sensor? Or share your script?dhanjel wrote:I have a virtual device of type text that displays the current track in Sonos, which works nice.
What I would like to do though is to set the icon to the current album art (I do have the url), is that possible?
I am using the new HTTP poller in Domoticz to get song/artist from the Sonos and show it in a text sensor.geezerrr wrote: Can you share how you get the Sonos text in your text dummy sensor? Or share your script?I'm looking for this one.
Code: Select all
<?php
//----------fill in parameters below----------
$path='http://127.0.0.1/fp/sonos/'; //localhost, path to Sonos Wrapper
//$path='http://192.168.1.157/fp/sonos/'; //used for debugging
$status_off="Uit"; //message shown when Sonos is not playing
$sonos=array( //key and value of Sonos, key corresponds to idx in Sonos Wrapper config file
'115' => 'kantoor', //key, value
'116' => 'keuken'
);
$ar1=getSonosInformation('kantoor'); //not so nice, but call function for each sonos
$ar2=getSonosInformation('keuken');
//----------end of parameters----------
//array_walk($sonos, 'getSonosInformation'); //start function for all values from array
$output=json_encode(array_merge($ar1, $ar2));
//$output=json_encode(array_merge(array_walk($sonos, 'getSonosInformation')));
print_r($output);
function getSonosInformation($sonos_name) {
global $path,$status_off,$sonos; //load variables
$id = array_search($sonos_name, $sonos); //search sonos id from array corresponding to name
//get info from Sonos
$mediainfo=json_decode(file_get_contents($path.'index.php?zone='.$id.'&action=GetMediaInfo'),true); //media info
$positioninfo=json_decode(file_get_contents($path.'index.php?zone='.$id.'&action=GetPositionInfo'),true); //position info
$volumeinfo=file_get_contents($path.'index.php?zone='.$id.'&action=GetVolume'); //volume info
if(!empty($mediainfo['title'])) { //title not empty then radio is played, get data from GetMediaInfo
$title=$mediainfo['title']; //radio station
$streamcontent=$positioninfo['streamContent']; //what is playing
$album=''; //no album information
$artist=''; //no artist information
} else { //other source, get data from GetPositionInfo
$title=$positioninfo['title']; //title of the song
$title=substr($title, 0, 50); //show first 50 characters
$artist=$positioninfo['artist']; //artist
$album=$positioninfo['album']; //album
$album=substr($album, 0, 30); //show first 30 characters
if(!empty($positioninfo['albumTrackNumber'])) { //tracknumber can be on 2 places
$tracknumber=$positioninfo['albumTrackNumber'];
} else {
$tracknumber=$positioninfo['Track'];
}
$streamcontent= '#'.$tracknumber; //shows: #:10
}
//get status of Sonos
$status=file_get_contents($path.'index.php?zone='.$id.'&action=GetTransportInfo', 'r');
if ($status != 1) { //1=Playing, 2=Pause, 3=Stopped
$title=$status_off; //title empty if Sonos is not playing
}
//make JSON from array
$ar=array();
if ($title==$status_off) { //if Sonos is not playing
$ar[$sonos_name] = array(
"playing" => $title
);
} else {
if(!empty($mediainfo['title'])) {
$ar[$sonos_name] = array(
"playing" => $title.'<br>'.$streamcontent, //radio station and number
);
} else {
$ar[$sonos_name] = array(
"playing" => $artist.'<br>'.$title, //artist and number
//"playing" => $streamcontent_1.': '.$title_1.'<br>'.$artist_1.' | Album: '.$album_1, //other possibility
);
}
}
return $ar;
}
?>
Code: Select all
--Sonos information
--{"kantoor":{"playing":"Uit"},"keuken":{"playing":"Uit"}}
--Retrieve the request content
s = request['content'];
--Update sonos (kantoor,484 and keuken 485) with playing information
local s_1 = domoticz_applyJsonPath(s,'.kantoor.playing')
local s_2 = domoticz_applyJsonPath(s,'.keuken.playing')
domoticz_updateDevice(484,'',s_1)
domoticz_updateDevice(485,'',s_2)
Users browsing this forum: janpep and 1 guest