Page 1 of 1

Custom icon for text devices

Posted: Friday 15 July 2016 11:55
by dhanjel
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

Re: Custom icon for text devices

Posted: Friday 15 July 2016 13:41
by gizmocuz
That is quite bit bit outside the idea for this application....

Re: Custom icon for text devices

Posted: Friday 15 July 2016 17:27
by dhanjel
Ah ok, would be nice though :)
But at least be able to have custom icons on all types of devices would be nice.

Re: Custom icon for text devices

Posted: Wednesday 07 December 2016 17:26
by geezerrr
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.

Re: Custom icon for text devices

Posted: Monday 12 December 2016 16:09
by G3rard
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 4516 times
text.jpg
text.jpg (14.6 KiB) Viewed 4516 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)

Re: Custom icon for text devices

Posted: Monday 12 December 2016 21:46
by geezerrr
Thnx G3rard,
I Will give it a try

Re: Custom icon for text devices

Posted: Friday 06 January 2017 10:11
by dhanjel
I use the node-sonos-http api in a dzVents to get the information, still would like at least are more representative icon though :)

Re: Custom icon for text devices

Posted: Wednesday 11 July 2018 13:34
by ben53252642
+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

Re: Custom icon for text devices

Posted: Sunday 14 July 2019 9:09
by aBjerris
+1 On this one.
I don't use Sonos with Domoticz yet but might do it in the future.
In general I think the Domoticz UI could improve a lot if all virtual sensors/switches had customized icons just like the physical switches.

Skickat från min H8216 via Tapatalk


Re: Custom icon for text devices

Posted: Saturday 07 September 2019 8:30
by twentysevendk
I've got a friend who is an old-school developer and making up his smart-home application by his own, whilst I'm using Domoticz.
As of now, being unable to assign a desirable icons for all items in Domoticz is one of the major things why I can't get an upper hand in our competition of smart home systems.
So my bet is ++1 for this feature!

Re: Custom icon for text devices

Posted: Sunday 07 June 2020 12:36
by robhiddinga
It would be nice to be able to modify all icons on all devices.
It would enable you to be much more informative.
As it is not possible I have been struggling to solve it another way and ended up using a custom sensor.
Not as much space as on a text device, but you can (mis)use all parts of the header.
Modifying that one took me some time, so I shared my snippet on github
https://github.com/robhiddinga/domoticz-tile-mod