Custom Badge Icons

While the template sensor icon_template lets you dynamically set an icon, this icon does not display when the sensor is displayed as a badge (the text is displayed). How can I have a badge with a custom icon? I’d like to create a room activity badge that will change to a wii icon, apple icon, tv icon, etc based on what’s happening in the room.

Thanks

Hi, right, it seems that icon doesn’t change dinamically (not even in phyton script), but I saw that entity_picture works, so we can do the job :smiley:
I have a input_select with the main activities (like tv, pc, cooking, sleeing…) and for each item a png that I set it in a python script called by an automation (input_select change). The actual automation (monitoring the real world) to actually change the input_select is a WIP.


Main files:


2 Likes

Hello, thank you “mviezzer” for this awsome feature.

I would love to use it for my harmony hub current activity sensor but unfortunatly it’s not working. I just have a white blank badge with the text “ACT” int the red little bubble.

Maybe if you have the time to check my code you will find the error i have made:

sensor:
  - platform: template
    sensors:
      harmony_hub_sensor:
        value_template: '{{ states.remote.harmony_hub.attributes.current_activity }}'
        friendly_name: 'harmony hub sensor'  

input_select:
  harmony_hub:
    name: Harmony Hub
    options:
      - Power Off
      - TV
      - PC TV      
      - SMART TV
      - MOVIES TV
      - SWITCH TV
      - PS4 TV
      - ONE TV
      - WiiU TV
      - PS3 TV
      - 360 TV          
      - PC      
      - MOVIES
      - SWITCH
      - PS4
      - ONE
      - WiiU
      - PS3
      - 360
      - Chromecast audio
    initial: Power Off
    icon: mdi:monitor   

group:
  activity:
    name: Main activity
    entities:
      - input_select.harmony_hub
      - sensor.harmony_hub_sensor   

automations:
 - alias: 'Activity change'
   hide_entity: True
   initial_state: 'on'
   trigger:
     - platform: state
       entity_id: input_select.harmony_hub
   action:
     - service: python_script.activity
       data_template:
         event: "{{ trigger.event }}"
     - service: python_script.summary
       data_template:
         event: "{{ trigger.event }}"   
 - alias: 'Call Script Event'
   hide_entity: True
   initial_state: 'on'
   trigger:
     - platform: event
       event_type: call_service
       event_data:
         domain: script
   action:
     - delay: 00:00:02
     - service: python_script.last_cmd
       data_template: 
         event: "{{ trigger.event }}" 

activity.py:
# Get params
event = data.get('event')

# Get the state object from the name
state_value = hass.states.get('input_select.harmony_hub').state

# Get info
dt = datetime.datetime.now() #state.attributes.get('last_triggered')
time = "%02d:%02d" % (dt.hour, dt.minute)

# Sensor update
hass.states.set('sensor.harmony_hub_sensor', state_value, {
    'friendly_name': ' ',
    'entity_picture': '/local/activities/{}.png'.format(state_value.lower()),
    'unit_of_measurement': 'Act'
})

I have added the “python_script:” line in the config.
I have renamed all the .png files to match the name of the inputs and placed them in the “activities” folder(for exemple the activity PC TV=pc tv.png).
Do i have to edit the “python_script.summary” and “python_script.last_cmd” to get it working?
I’m receiving errors now in the log file.:

2018-02-03 22:51:50 ERROR (SyncWorker_0) [homeassistant.components.python_script.last_cmd.py] Error executing script: 'NoneType' object is not callable
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/python_script.py", line 166, in execute
    exec(compiled.code, restricted_globals, local)
  File "last_cmd.py", line 22, in <module>
TypeError: 'NoneType' object is not callable
2018-02-03 22:51:50 ERROR (SyncWorker_8) [homeassistant.components.python_script.last_cmd.py] Error executing script: 'NoneType' object is not callable
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/python_script.py", line 166, in execute
    exec(compiled.code, restricted_globals, local)
  File "last_cmd.py", line 22, in <module>
TypeError: 'NoneType' object is not callable
2018-02-03 22:51:50 ERROR (SyncWorker_12) [homeassistant.components.python_script.last_cmd.py] Error executing script: 'NoneType' object is not callable
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/python_script.py", line 166, in execute
    exec(compiled.code, restricted_globals, local)
  File "last_cmd.py", line 22, in <module>
TypeError: 'NoneType' object is not callable
2018-02-03 22:51:50 ERROR (SyncWorker_4) [homeassistant.components.python_script.last_cmd.py] Error executing script: 'NoneType' object is not callable
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/python_script.py", line 166, in execute
    exec(compiled.code, restricted_globals, local)
  File "last_cmd.py", line 22, in <module>
TypeError: 'NoneType' object is not callable
2018-02-03 22:52:03 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

Thank you.

Deleting this line in your last_cmd.py file resolve the error in log, But still no pictures displayed in the badge.

# Ignore some names
if (msg == 'None' or msg.startswith('Set ') or msg.find('HDMI')>0):
    msg = ''