Skip to content

Instantly share code, notes, and snippets.

@EverythingSmartHome
Created April 6, 2022 13:13
Show Gist options
  • Select an option

  • Save EverythingSmartHome/814bc87e83dcff1c06fffa3095b95b3f to your computer and use it in GitHub Desktop.

Select an option

Save EverythingSmartHome/814bc87e83dcff1c06fffa3095b95b3f to your computer and use it in GitHub Desktop.
Home Assistant Mushroom card templates
#Showing the state of a temperature in a template card:
{{ states('sensor.your_temperature_sensor') }}
#Change the colour of the light depending on status:
{% if is_state('light.your_light', 'on') %}
orange
{% endif %}
#Welcome template:
{% set time = now().hour %}
{% if (time >= 18) %}
Good Evening, {{user}}!
{% elif (time >= 12) %}
Good Afternoon, {{user}}!
{% elif (time >= 5) %}
Good Morning, {{user}}!
{% else %}
Hello, {{user}}!
{% endif %}
@ilyassw

ilyassw commented Jul 1, 2023

Copy link
Copy Markdown

Hi guys , i came strait forward from Youtube page and i am a bit confused on setting the count . I have followed every step but when i switch the light on for a room is automatically count 2 lights ! meanwhile i have only one light in that room ! the same light inside the room been used in both Horizontal Stack configuration , how do you go about sorting this out ? I have one main light . Thanks

@dos1973

dos1973 commented Dec 4, 2023

Copy link
Copy Markdown

How would I go about adding the date after each day of my subtitle addition to the Welcome Screen template. I am not sure how to get that added in.

I added this in the secondary information field since I am always forgetting the date πŸ˜…

{% set time = now().weekday() %}
{% if (time == 0) %}
Today is Monday, {{ now().date()}}
{% elif (time == 1) %}
Today is Tuesday, {{ now().date()}}
{% elif (time == 2) %}
Today is Wednesday, {{ now().date()}}
{% elif (time == 3) %}
Today is Thursday, {{ now().date()}}
{% elif (time == 4) %}
Today is Friday, {{ now().date()}}
{% elif (time == 5) %}
Today is Saturday, {{ now().date()}}
{% elif (time == 6) %}
Today is Sunday, {{ now().date()}}
{% else %}
Today is fudged....
{% endif %}

image

hi guys, i added this and it works fine, but shows me the english format of Date
Bildschirmfoto 2023-12-04 um 01 19 54

i would need the Format 12.04.2023.
would be nice if someone have an hint for. Just 2 days with HA.

@jaymartinez723

Copy link
Copy Markdown

How do we get that chip where it shows what lights are on?

@ma-si

ma-si commented Feb 11, 2024

Copy link
Copy Markdown

How would I go about adding the date after each day of my subtitle addition to the Welcome Screen template. I am not sure how to get that added in.

I added this in the secondary information field since I am always forgetting the date πŸ˜…

{% set time = now().weekday() %}
{% if (time >= 0) %}
Today is Monday, {{ now().date()}}
{% elif (time >= 1) %}
Today is Tuesday, {{ now().date()}}
{% elif (time >= 2) %}
Today is Wednesday, {{ now().date()}}
{% elif (time >= 3) %}
Today is Thursday, {{ now().date()}}
{% elif (time >= 4) %}
Today is Friday, {{ now().date()}}
{% elif (time >= 5) %}
Today is Saturday, {{ now().date()}}
{% elif (time >= 6) %}
Today is Sunday, {{ now().date()}}
{% else %}
Today is fudged....
{% endif %}

image

THANK YOU SO MUCH!

now() is python date object so you can use formatting.

{% set current_datetime = now() -%}
Today is {{ current_datetime.strftime("%A") }}, {{ current_datetime.date()}}

@stoniwankenobii this way will be easier ;)

@dos1973 you can use formatting

now().strftime("%d.%m.%Y")

@clemonly-stoni

Copy link
Copy Markdown

YOU'RE A WIZARD HARRY

@yellowdre

Copy link
Copy Markdown

can someone please give detail instruction how to creat the light counter card

@TrialMaster

Copy link
Copy Markdown

What is required to have the dashboard format correctly on a tablet or desktop?

@Octavian1973

Copy link
Copy Markdown

Hello everybody!

I added this in the secondary information field since I am always forgetting the date πŸ˜‰

{% set time = now().weekday() %}
{% if (time == 0) %}
Today is Monday, {{ now().strftime("%d.%m.%Y")}}
{% elif (time == 1) %}
Today is Tuesday, {{ now().strftime("%d.%m.%Y")}}
{% elif (time == 2) %}
Today is Wednesday, {{ now().strftime("%d.%m.%Y")}}
{% elif (time == 3) %}
Today is Thursday, {{ now().strftime("%d.%m.%Y")}}
{% elif (time == 4) %}
Today is Friday, {{ now().strftime("%d.%m.%Y")}}
{% elif (time == 5) %}
Today is Saturday, {{ now().strftime("%d.%m.%Y")}}
{% elif (time == 6) %}
Today is Sunday, {{ now().strftime("%d.%m.%Y")}}
{% else %}
Today is the lucky day...
{% endif %}

000

@oliverlinsenmaier

oliverlinsenmaier commented Aug 2, 2024

Copy link
Copy Markdown

I can't get the secondary information to work with the temperature. The same is true for the icon color, when the light is on... Can anybody send me their YAML for that part?

@artkrzy

artkrzy commented Nov 28, 2024

Copy link
Copy Markdown

How did you do the light count near the beginning of the main card setup?

Try this {% set domain = 'light' %} {% set lightsOnCount = states[domain] | selectattr( 'state', 'eq', 'on') | list | count %} {{lightsOnCount}}

You can do this with any kind of domain, media_player, cameras and so on.

Is there a way to use categories as domain? I have smart switches for the lights and several smart plugs (which are also in domain switch), so when I do the count against domain switch - it does add up plugs and switches.

Thanks in advance

@oliverlinsenmaier

Copy link
Copy Markdown

I use the following helper values: Powerplugs, Lights on, window shutters, window/doors, room temperature, Sonos active.

This is my configuration yaml:

- sensor:
      - name: "Steckdosen an"
        unique_id: poweroutlets_turned_on
        icon: mdi:power-socket-eu
        state: |
          {{ states.light 
            | rejectattr('attributes.entity_id', 'defined') 
            | selectattr('entity_id', 'in',  ['light.aussensteckdose', 'light.steckdose_balkon', 'light.steckdose_dachterrasse'])
            | rejectattr('attributes.is_hue_group', 'true') 
            | selectattr('state', 'eq', 'on') 
            | reject('search', 'screen')
            | reject('search', 'segment')            
            | list
            | count }}
            
  - sensor:
      - name: "Lampen an"
        unique_id: lights_turned_on
        icon: mdi:window-shutter-open
        state: |
          {{ label_entities("lamp") | select('is_state', 'on') | list | count }}
            
  - sensor:
      - name: "RolllΓ€den oben"
        unique_id: rollos_oben
        icon: mdi:window-shutter-closed
        state: | 
          {{ states.cover | selectattr('state', 'eq', 'open') | reject('search', 'motor') | reject('search', 'markise') | list | count + states.cover | selectattr('state', 'eq', 'opening') | reject('search', 'motor') | reject('search', 'markise') | list | count + states.cover | selectattr('state', 'eq', 'closing') | reject('search', 'motor') | reject('search', 'markise') | list | count }}
            
  - sensor:
      - name: "Offene Fenster/TΓΌren"
        unique_id: open_window_count
        icon: mdi:window-open-variant
        state: | 
          {{ states.binary_sensor | selectattr('attributes.device_class', 'eq', 'door') | selectattr('state', 'eq', 'on') | reject('search', 'ev6') | reject('search', 'gruppe')  | list | count +
             states.binary_sensor | selectattr('attributes.device_class', 'eq', 'window') | selectattr('state', 'eq', 'on') | reject('search', 'ev6') | reject('search', 'gruppe')  | list | count }}
             
  - sensor:
      - name: "RTR in Betrieb"
        unique_id: active_rtr_count
        icon: mdi:thermometer-lines
        state: | 
          {{ states.climate | selectattr('state', 'eq', 'heat_cool') | reject('search', 'ev6') | reject('search', 'gruppe') | list | count }}
          
  - sensor:
      - name: "BadheizkΓΆrper in Betrieb"
        unique_id: active_badheizkorper
        icon: mdi:heating-coil
        state: | 
          {{ states.light | selectattr('state', 'eq', 'on') | selectattr('entity_id', 'in',  ['light.badheizkorper_og', 'light.badheizkorper_dg']) | list | count }}
          

  - sensor:
      - name: "Sonos in Betrieb"
        unique_id: active_media_count
        icon: mdi:music
        state: | 
          {{ states.media_player | selectattr('state', 'eq', 'playing') | reject('search', 'ev6') | reject('search', 'gruppe')  | list | count }}

@danewhitfield

Copy link
Copy Markdown

Old thread, not sure if anyone is interested but if like myself you have setup your full name on HA then it might be worth using (either directly or as a helper):

{{ user.split()[0] }}

Looks cleaner with just the first name and fits better.

@domingosedu

domingosedu commented Apr 21, 2025

Copy link
Copy Markdown

I have this code below which is working fine, but I want to make the icon in orange every time that any of these 4 lights below turns on.
light.banheiro_suite_interruptor_iluminacao_interruptor_1
light.banheiro_suite_interruptor_iluminacao_interruptor_2
light.banheiro_suite_interruptor_iluminacao_interruptor_3
light.banheiro_suite_interruptor_iluminacao_interruptor_4

{% if is_state('light.banheiro_suite_interruptor_iluminacao_interruptor_1','on')
%} orange
{% endif %}

Does anybody know how to ADD the "OR" clause on this sintax?

@danewhitfield

Copy link
Copy Markdown

I have this code below which is working fine, but I want to make the icon in orange every time that any of these 4 lights below turns on. light.banheiro_suite_interruptor_iluminacao_interruptor_1 light.banheiro_suite_interruptor_iluminacao_interruptor_2 light.banheiro_suite_interruptor_iluminacao_interruptor_3 light.banheiro_suite_interruptor_iluminacao_interruptor_4

{% if is_state('light.banheiro_suite_interruptor_iluminacao_interruptor_1','on') %} orange {% endif %}

Does anybody know how to ADD the "OR" clause on this sintax?

{% if is_state('light.banheiro_suite_interruptor_iluminacao_interruptor_1','on')
   or is_state('light.light_2','on')
   or is_state('light.light_3','on')
   or is_state('light.light_4','on')
%} orange
{% endif %}

@domingosedu

domingosedu commented Apr 21, 2025

Copy link
Copy Markdown

Many thanks @danewhitfield for your assistance! You rock! :-)

@gietl

gietl commented Jul 10, 2025

Copy link
Copy Markdown

I think you can just simplify this to be:

Today is {{ now().strftime('%A %B %d, %Y %I:%M %p') }}

You can decide what format you want that date and time to be in depending on what is most ideal for you.

Hello everybody!

I added this in the secondary information field since I am always forgetting the date πŸ˜‰

{% set time = now().weekday() %} {% if (time == 0) %} Today is Monday, {{ now().strftime("%d.%m.%Y")}} {% elif (time == 1) %} Today is Tuesday, {{ now().strftime("%d.%m.%Y")}} {% elif (time == 2) %} Today is Wednesday, {{ now().strftime("%d.%m.%Y")}} {% elif (time == 3) %} Today is Thursday, {{ now().strftime("%d.%m.%Y")}} {% elif (time == 4) %} Today is Friday, {{ now().strftime("%d.%m.%Y")}} {% elif (time == 5) %} Today is Saturday, {{ now().strftime("%d.%m.%Y")}} {% elif (time == 6) %} Today is Sunday, {{ now().strftime("%d.%m.%Y")}} {% else %} Today is the lucky day... {% endif %}

000

@asid-script

Copy link
Copy Markdown

How would I go about adding the date after each day of my subtitle addition to the Welcome Screen template. I am not sure how to get that added in.

I added this in the secondary information field since I am always forgetting the date πŸ˜…

{% set time = now().weekday() %}
{% if (time == 0) %}
Today is Monday, {{ now().date()}}
{% elif (time == 1) %}
Today is Tuesday, {{ now().date()}}
{% elif (time == 2) %}
Today is Wednesday, {{ now().date()}}
{% elif (time == 3) %}
Today is Thursday, {{ now().date()}}
{% elif (time == 4) %}
Today is Friday, {{ now().date()}}
{% elif (time == 5) %}
Today is Saturday, {{ now().date()}}
{% elif (time == 6) %}
Today is Sunday, {{ now().date()}}
{% else %}
Today is fudged....
{% endif %}

image

Or you could just use this - secondary: "Today is {{ now().strftime('%A %d.%m.%Y') }}"

@asid-script

Copy link
Copy Markdown

ps thank you for that great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment