How long switch has been on for?

If you want to combine Coffee On Time into the secondary info line, you can use a mushroom-template-card (mushroom card).

Off:
image

On:
image

In the GUI configuration, paste the following into the secondary information section:

{% if is_state("switch.coffee_machine", "on") %}
{{ relative_time(states.switch.coffee_machine.last_changed)}} 
{% else %}
{% endif %}

This will display the time since switched on, or nothing if the switch is off.

If you want the usual icon_color response, use this complete yaml definition:

type: custom:mushroom-template-card
primary: Coffee Machine
secondary: >-
  {% if is_state("switch.coffee_machine", "on") %}
  {{relative_time(states.switch.coffee_machine.last_changed)}}
  {% else %}
  {% endif %}
icon: mdi:coffee
entity: switch.coffee_machine
icon_color: >-
  {% set entity_state=states(entity) %}
  {% if entity_state=='on'%}
  accent
  {% else %}
  grey
  {% endif %}
tap_action:
  action: toggle
3 Likes

hey thanks so much for that, going to give it a try!!