Before I start showing some template examples, I have to say that I use the Nova Launcher on my Android - it allows me to ‘layer’ multiple widgets on top of each other.
So, I normally use a ‘Service Button’ widget that I use to call e.g. a switch.toggle service in the background; I use an image for the icon, but I don’t use the ‘Label’ field.
I then overlay it with a smaller/half-size ‘Template’ widget that allows me to not only show the status, but apply some basic formatting, e.g. font color.
The Service Button is straightforward and the template widget looks like this:
{% if is_state('automation.frigate_notification_poolcam','on') -%}
<font color="green">
{% else %}
<font color="red">
{% endif %}
<b> {{ states('automation.frigate_notification_poolcam') }}</b>
This is the result on my screen:
Tapping on the camera symbol turns the automation on and off.
I don’t think it’s straightforward to dynamically change the icon/symbol itself, but I’m good with the 2-layer setup.
To display info from multiple sensors I also use the template widget, e.g.
WS {{ ((states("sensor.temp") | float(0) - 32)*5/9) | round(1) }}C<br>Pt {{ ((states("sensor.temp_1") | float(0) - 32)*5/9) | round(1) }}C<br>Pl {{ ((states("sensor.temp_2") | float(0) - 32)*5/9) | round(1) }}C
This widget converts and shows temperature values in Celsius, which are in Fahrenheit in my Home Assistant installation, without having to create these sensors in the Home Assistant installation itself:
The only way I’ve so far been able to drive multiple actions with one button is to use the setup from above and trigger an actionable notification.
Example:
I have two outdoor fans that are each switched on and off remotely.
I use the ‘Service Button’ widget to execute a script:
service: notify.mobile_app_pixel
data:
message: "Choose the Fan to toggle:"
title: Outdoor Fan Action
data:
ttl: 0
priority: high
tag: outdoor_fan_action
actions:
- action: toggle_outdoor_fan_both
title: Both
- action: toggle_outdoor_fan_patio
title: Patio
- action: toggle_outdoor_fan_terrace
title: Terrace
channel: Alert
importance: high
I am then presented the three options:
I select the option I want and the widget on my screen changes e.g. from
to
And this is the code for the widget that changes the text color, the text itself comes from a separate helper:
{% if is_state('sensor.outdoor_fan_status','On') -%}
<font color="red">
{% elif is_state('sensor.outdoor_fan_status','Off') -%}
<font color="green">
{% else %}
<font color="yellow">
{% endif %}
<b>{{ states('sensor.outdoor_fan_status') }}</b>