Custom icon for text devices

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.
Post Reply
dhanjel
Posts: 132
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

Custom icon for text devices

Post by dhanjel » Friday 15 July 2016 11:55

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?

Image

User avatar
gizmocuz
Posts: 8721
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: Custom icon for text devices

Post by gizmocuz » Friday 15 July 2016 13:41

That is quite bit bit outside the idea for this application....
Quality outlives Quantity!

dhanjel
Posts: 132
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

Re: Custom icon for text devices

Post by dhanjel » Friday 15 July 2016 17:27

Ah ok, would be nice though :)
But at least be able to have custom icons on all types of devices would be nice.

geezerrr
Posts: 126
Joined: Tuesday 02 December 2014 23:16
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Custom icon for text devices

Post by geezerrr » Wednesday 07 December 2016 18:26

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?

Image
Can you share how you get the Sonos text in your text dummy sensor? Or share your script? Image I'm looking for this one.

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Custom icon for text devices

Post by G3rard » Monday 12 December 2016 17:09

geezerrr wrote: Can you share how you get the Sonos text in your text dummy sensor? Or share your script? Image I'm looking for this one.
I am using the new HTTP poller in Domoticz to get song/artist from the Sonos and show it in a text sensor.
This checks the status every 30 seconds and works independent from the normal LUA scripts.

I call a PHP script in the poller, this uses the information from the Sonos Wrapper https://github.com/gerard33/sonos.
So you need that to get this working, but maybe you can use some of the code.
http_poller.jpg
http_poller.jpg (39.7 KiB) Viewed 1910 times
text.jpg
text.jpg (14.6 KiB) Viewed 1910 times
PHP script (called from URL field in HTTP poller)

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;
}
?>
sonos.lua

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)
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

geezerrr
Posts: 126
Joined: Tuesday 02 December 2014 23:16
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Custom icon for text devices

Post by geezerrr » Monday 12 December 2016 22:46

Thnx G3rard,
I Will give it a try

dhanjel
Posts: 132
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

Re: Custom icon for text devices

Post by dhanjel » Friday 06 January 2017 11:11

I use the node-sonos-http api in a dzVents to get the information, still would like at least are more representative icon though :)

ben53252642
Posts: 538
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Custom icon for text devices

Post by ben53252642 » Wednesday 11 July 2018 13:34

+1 for this feature.

I'd like to be able to set a text sensors icon to pull from a url using json (also Sonos, same as everyone else it would seem). :)

viewtopic.php?f=63&t=24140

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests