jono
(Jono)
July 5, 2017, 10:13am
1
Is it possible to change the entity picture if I turn on a switch, run a script, scene etc?
I’ve seen people doing it with icons for battery states (charging, not charging, charge percentage), and I’m just wondering if it’s possible to adapt something like that to my use case?
For example with this switch that turns on different scenes:
- platform: template
switches:
office_light_custom:
value_template: "{{ is_state('office_light_custom', 'on') }}"
turn_on:
- service: scene.turn_on
entity_id: scene.office_light_100
turn_off:
- service: scene.turn_on
entity_id: scene.office_light_off
Is it possible when the switch is on to use:
entity_picture: /local/[email protected]
And when switched off to use (or just have this as the default icon):
entity_picture: /local/[email protected]
cgtobi
(Tobi)
July 5, 2017, 10:56am
2
You can use icon_template
for that.
icon_template
(Optional): Defines a template for the icon of the sensor.
Example:
sensor:
- platform: template
sensors:
day_night:
friendly_name: 'Day/Night'
value_template: '{% if is_state("sun.sun", "above_horizon") %}Day{% else %}Night{% endif %}'
icon_template: '{% if is_state("sun.sun", "above_horizon") %}mdi:weather-sunny{% else %}mdi:weather-night{% endif %}'
For more info look here:
1 Like
jono
(Jono)
July 5, 2017, 11:03am
3
Ah, so this works with ‘entity_picture’ as well, not just ‘mdi-icon-whatever’ ?
Thanks, I’ll look at this.
jono
(Jono)
July 5, 2017, 11:20am
4
OK, I tried the code below and it didn’t work
(With and without quotes around ‘entity_picture: /local/[email protected] ’ .)
- platform: template
sensors:
jays_desk_lamp_icon:
value_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on")) %}On{% else %}Off{% endif %}'
icon_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on") %}"entity_picture: /local/[email protected] "{% else %}"entity_picture: /local/[email protected] "{% endif %}'
Any ideas on how to get it working?
Skip the “entity_picture” part.
jono
(Jono)
July 5, 2017, 1:23pm
6
I tried this below. It didn’t show any errors, but didn’t show any of the images either
- platform: template
sensors:
jays_desk_lamp_icon:
value_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on") %}On{% else %}Off{% endif %}'
icon_template: '{% if is_state("switch.hs100_5_jays_desk_lamp", "on") %}/local/[email protected] {% else %}/local/[email protected] {% endif %}'
keithh666
(Keith Hull)
July 5, 2017, 2:48pm
7
If you use the mdi icons it will work, I believe.
I use automation to turn on/off visibility of a group with one entity in it. The picture of the group is set but I think there is probably a way to have a on group and different off group for each entity. Its not the solution you were looking for but its a complicated alternative.
1 Like
jono
(Jono)
July 5, 2017, 3:38pm
9
Yeah, I realise that. But I’m wanting to change ‘entity_picture’ not mdi icons, hence the title
jono
(Jono)
July 5, 2017, 7:56pm
10
Yeah, thanks but that’s not what I’m after.
keithh666
(Keith Hull)
July 5, 2017, 8:27pm
11
I think you cannot do what you want atm hence my reply, maybe put a change request in and let people vote on it? I would probably vote for it
1 Like
jono
(Jono)
July 5, 2017, 8:44pm
12
Yeah, I agree. I don’t think it would be possible at the moment.
I might put it in as a feature request
mudasar8k
(Mudassar Ahmad)
August 4, 2017, 5:43pm
13
@RobDYI can you please let me know how to show time history as it showing under Outside Motion Alert “1 second ago”?
Thanks
This is exactly what I am trying to accomplish did anyone get it done?
jono
(Jono)
November 16, 2017, 10:27am
16
No, I never managed to do it.
jono
(Jono)
November 22, 2017, 1:41pm
17
…actually, I’ve just found out how to do this
If you look at this info on Template Switches (bottom of the page) you can use ‘entity_picture_template’ to change the images.
This is what I have but does not seem to change the icon to entity
sensor.moon:
friendly_name: Moon
entity_picture_template: >-
{% if is_state('sensor.moon', 'New moon') %}
/local/images/new-moon.png
{% if is_state('sensor.moon', 'Waning crescent') %}
/local/images/waning-crescent-moon.png
{% if is_state('sensor.moon', 'Waxing crescent') %}
/local/images/waxing-crescent-moon.png
{% endif %}
keithh666
(Keith Hull)
November 22, 2017, 11:04pm
19
That looks wrong to me, it should look like this…
sensor:
- platform: template
sensors:
moons:
friendly_name: "Moon Type"
entity_picture_template: >-
{% if is_state('sensor.moon', 'New moon') %}
/local/images/new-moon.png
{% elif is_state('sensor.moon', 'Waning crescent') %}
/local/images/waning-crescent-moon.png
{% elif is_state('sensor.moon', 'Waxing crescent') %}
/local/images/waxing-crescent-moon.png
{% endif %}
Remember you can check these in the template editor
keithh666
(Keith Hull)
November 23, 2017, 12:46am
20
keithh666:
platform: template
sensors:
moons:
friendly_name: “Moon Type”
entity_picture_template: >-
- platform: template
sensors:
moon_phase:
friendly_name: "Moon Phase"
value_template: >
{% if is_state('sensor.moon', 'New moon') %}
'New Moon'
{% elif is_state('sensor.moon', 'Waning crescent') %}
'Waning Moon'
{%elif is_state('sensor.moon', 'Waxing crescent') %}
'Waxing Moon'
{% endif %}
entity_picture_template: >
{% if is_state('sensor.moon', 'New moon') %}
/local/moon_new.png
{% elif is_state('sensor.moon', 'Waning crescent') %}
/local/moonwane.png
{%elif is_state('sensor.moon', 'Waxing crescent') %}
/local/moonwax.png
{% endif %}
1 Like