norien
(Norien)
October 28, 2017, 5:38pm
1
I have started using groups inside groups to clean up my UI and to shorten some of my larger groups such as device status. I would really love to be able to set the icon based off status of whats inside that group!
for example:
group:
device_status:
control: hidden
name: Device Status
entities:
- automation.notify_if_device_goes_offline
- group.device_status_cameras
- sensor.roomba
- sensor.echo_dot
- sensor.google_home
- sensor.wemo_link
- sensor.philips_hue_hub
- sensor.chromecast_backyard
- sensor.chromecast_kitchen
- sensor.raspberry_pi
- sensor.raspberry_pi_zero
- sensor.tracker_doorbell
- sensor.bedroom_led_strip
- sensor.room_masterbed
- sensor.room_laundry_room_sensor
device_status_cameras:
control: hidden
name: Cameras
icon_template: "{% if states.group.device_status_cameras.state == 'online' %} mdi:camera {% else %} mdi:alert-outline {% endif %}"
entities:
- sensor.dlink_camera
- sensor.driveway_camera
lpt2007
(lpt2007)
March 23, 2018, 4:43pm
3
Can I use icon template inside group? How?
+1 for this! Would be great for a weather view having a dynamic icon based on current conditions…
RonJ103
(Jeremy Scuteri)
June 4, 2018, 1:32am
5
I would also like to be able to do this.
Yup, need this too as i have light groups inside groups and right now the icon stays desperately off!
use this:
homeassistant:
customize:
group.personal:
templates:
icon: >
if (entities['sensor.home_badge'].state === '0') return 'mdi:account-off';
if (entities['sensor.home_badge'].state > '1') return 'mdi:account-multiple-check';
return 'mdi:account';
of course this is based on another entities state, but you could use any entity.
btw this is a view: true group, so even the tab icons are changing.
Thanks for that Marius. Do you know if this can be used with group entities for conditionals as follows:
homeassistant:
customize:
group.garden_light:
templates:
icon: >
if (entities['group.garden_light'].state === 'off') return 'mdi:lightbulb';
if (entities['group.garden_light'].state === 'on') return 'mdi:lightbulb-outline';
If yes, this would solve my issue! Unable to test this as we speak unfortunately!
must be yes.
this works in my setting dev-tools:
{% if is_state('group.family', 'off') %} 'mdi:lightbulb'
{% else %} 'mdi:lightbulb-outline'
{% endif %}
if you’d want to prevent it from failing in case of unknown, add another safeguard:
{% if is_state('group.family', 'off') %} 'mdi:lightbulb'
{% elif is_state('group.family', 'on') %} 'mdi:lightbulb-outline'
{% else %} 'mdi:help'
{% endif %}
or in the other syntax:
templates:
icon: >
if (entities['group.garden_light'].state === 'off') return 'mdi:lightbulb';
if (entities['group.garden_light'].state === 'on') return 'mdi:lightbulb-outline';
return 'mdi:help';
1 Like
Thanks a lot. Great on you.
I was weirded out by the syntax you wrote. Is that an old version/pre-jinja2?
?not sure what you mean?
the {% %} variant is jinja which you can try in the dev-tools in Hassio, and is computed server side. The other syntax is used in the custom-ui and tiles custom cards for example, javascript, which is computed in browser, client side.
again see the link to @andrey 's templating documentation .
Wow, thanks for that. I did not realise you could use special templating for the custom_ui. Just getting the hang of Jinja. I’ll stick to that for a litte while!
Ok, the custom-ui templating works well as follows:
group.light:
templates:
icon: >
if (entities['group.light'].state === 'off') return 'mdi:lightbulb';
if (entities['group.light'].state === 'on') return 'mdi:lightbulb-on';
return 'mdi:help';
Could not get the regular templating to work and no icon would be displayed.
Thanks Marius!
1 Like
This does throw errors when entities are not created on startup, for example due to lack of connection. Tried to use on door/window sensors but Hass would fail to load!
I know this is old but I voted on this one too. Unless I’m missing something, none of the replies are a solution to the OP request.
I seem to only be able to specify an icon (I choose lightbulb for each group) but no way to change it to an “lightbulb-on” for each group icon when the state of that group is on. See below for a visual and an example of group code.
group:
daily_outside_lights:
name: "Daily Outside Lights"
icon: mdi:lightbulb
entities:
- light.somelight1
- light.somelight2
- light.somelight3
- light.somelight4
- light.somelight5
christmas_lights:
name: "Christmas Lights"
icon: mdi:lightbulb
entities:
- light.somelight6
- light.somelight7
- light.somelight8
christmas_candles:
name: "Christmas Candles"
icon: mdi:lightbulb
entities:
- light.candle1
- light.candle2
- light.candle3
- light.candle4
- light.candle5
- light.candle6
- light.candle7
- light.candle8