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.

Moderators: leecollings, remb0

Post Reply
dhanjel
Posts: 102
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 »

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: 2547
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Custom icon for text devices

Post by gizmocuz »

That is quite bit bit outside the idea for this application....
Quality outlives Quantity!
dhanjel
Posts: 102
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 »

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: 79
Joined: Tuesday 02 December 2014 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Custom icon for text devices

Post 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.
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

Re: Custom icon for text devices

Post 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 4514 times
text.jpg
text.jpg (14.6 KiB) Viewed 4514 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)
Not using Domoticz anymore
geezerrr
Posts: 79
Joined: Tuesday 02 December 2014 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Custom icon for text devices

Post by geezerrr »

Thnx G3rard,
I Will give it a try
dhanjel
Posts: 102
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 »

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: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

Re: Custom icon for text devices

Post 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
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
aBjerris
Posts: 16
Joined: Wednesday 01 May 2019 16:32
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Sweden
Contact:

Re: Custom icon for text devices

Post 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

twentysevendk
Posts: 2
Joined: Saturday 24 March 2018 14:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Custom icon for text devices

Post 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!
robhiddinga
Posts: 5
Joined: Monday 20 August 2018 22:01
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Nederland
Contact:

Re: Custom icon for text devices

Post 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
Attachments
result.png
result.png (80.21 KiB) Viewed 1568 times
Domoticz, Controlicz, z-wave, rfxcom, zigbee, p1, tuya, evohome
watermeter, dzvents
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest