Custom Header template showcase and discussion

@kr_noob Continuing conversation from your comment here, this is the thread for such things.

If you can do it with a jinja template then you can add it to Custom Header, I am no Jinja expert and I just don’t have the time to write Jinja for anyone that requests it. This is why I often mention that this feature (complex html, css, and other fancy templates) is unsupported and isn’t really a feature at all. It’s more of a side effect of how things are rendered in CH.

All that being said, you would need to parse the JSON from the sensor you are using and the template section of the developer tools in HA is a great place to start. It even has an example of JSON parsing in the default template it shows. I can give you a bit of a head start, but making this work in the template that you are using would be up to you.

Go to developer tools >> templates and paste in the following example to see how to pull just the titles from the JSON in your feedparser sensor.

This will show the first 3 titles pulled from the sensor:

{{ state_attr('sensor.npr', 'entries')[0].title }}
{{ state_attr('sensor.npr', 'entries')[1].title }}
{{ state_attr('sensor.npr', 'entries')[2].title }}
1 Like

This works perfectly - I was able to put this into the header and flip the headlines vertically.

I had seen the JSON example (I know zilch about JSON) but overlooked it bc I thought the example was all about assigning variable vice extracting - but I see what you’re talking about. Thanks again!

Hi everyone. I am completely noob on this so my appologies if my question is stupid.
I have the following code in the raw editor. However it only display the time in compact mode.
What I should do in order to have the rest info in the header?

custom_header:
  button_text:
    options: '{{ hours12 }}:{{ minutesLZ }}'
  header_text: >-
    <style> #flipper {color:#999;} #flip {height:24px;overflow:hidden;} #flip >
    div > div {color:#fff;height:24px;margin-bottom:24px;display:inline-block;}
    #flip div:first-child {animation: show 10s linear infinite;} @keyframes show
    { 0% {margin-top:-144px;} 5% {margin-top:-96px;} 33% {margin-top:-96px;} 38%
    {margin-top:-48px;} 66% {margin-top:-48px;} 76% {margin-top:0px;} 100%
    {margin-top:0px;}} #flipper p {position:fixed;color:#999; } </style> <div
    id=flipper><div id=flip><div><div>
    {{states('sensor.outdoor_temperature')}}</div></div><div><div>
    {{states('switch.sonoff_100082f95b')}}</div></div><div><div>
    {{states('sensor.dark_sky_precip_probability')}}</div></div><div><div>
    {{states('sensor.outdoor_temperature')}}</div></div><div><div>  
  compact_mode: true
panel: false

Header text is removed in compact mode, it’s what makes it compact. You might want to try split mode. You can also flip split mode by setting footer mode to true.

It worked! thanks.
may I ask how (if) I could add a stable text for example in the below template

{{states('sensor.outdoor_temperature')}

in order to get Outdoor Temperature: 18 and not only 18 as it now.?

  header_text: >-
    <style> #flipper {color:#999;} #flip {height:24px;overflow:hidden;} #flip >
    div > div {color:#fff;height:24px;margin-bottom:24px;display:inline-block;}
    #flip div:first-child {animation: show 10s linear infinite;} @keyframes show
    { 0% {margin-top:-144px;} 5% {margin-top:-96px;} 33% {margin-top:-96px;} 38%
    {margin-top:-48px;} 66% {margin-top:-48px;} 76% {margin-top:0px;} 100%
    {margin-top:0px;}} #flipper p {position:fixed;color:#999; } </style> <div
    id=flipper><div id=flip><div><div>
    Outdoor Temperature: {{states('sensor.outdoor_temperature')}}</div></div><div><div>
    {{states('switch.sonoff_100082f95b')}}</div></div><div><div>
    {{states('sensor.dark_sky_precip_probability')}}</div></div><div><div>
    {{states('sensor.outdoor_temperature')}}</div></div><div><div>
1 Like

Works amazing. So pumped as this delivers everything I need. One question though - using sensor data in the header / footer causes the marquee to restart every time the data updates, so it rarely makes it all the way through given that I have motion sensors and temp data from several rooms here. Any way to disable updating until it’s all the way through all the frames?

Put Outdoor Temperature or any static text in brackets and quotes, like:

{{"Outdoor Temperature: "}}{{states('sensor.outdoor_temperature')}}

The brackets aren’t nessisary for static text as it’s just rendering as HTML.

No. CH needs to update on any change to templates.

You could get creative by making a time/date sensor and then a template sensor that will only update its value based on that sensor. So, for example, the template sensor’s value_template would be the state of the sensor you’re interested in and the entity would be sensor.date.

This would make it so that the sensor would only update once a day. You would then make an automation that used the homeassistant.update_entity service to update the template sensor with whatever interval you’d like.

Haven’t tried any of this myself, but it should do what you want.

2 Likes

This is so cool…
I can just copy that and adjust?

Instead of the sensors for weather i would love to have a greeting depending on time

  • notifications for ex when machine is on.

Can someone point me how to do this?
I have this already but not sure how to integrate this into this header text

EDIT: ok meanwhile i found it, it rocks ! thx guys

sensor:
  - platform: time_date
    display_options:
      - time
      - date
      - date_time
  - platform: template
    sensors:
      greeting:
        value_template: >
          {% set state = states('sensor.time') %}
          {% if '00:00' <= state  < '06:00' %}
            Goeienacht !
          {% elif '06:00' <= state  < '12:00' %}
            Goeiemorgen !
          {% elif '12:00' <= state  < '18:00' %}
            Goeiemiddag !
          {% else %}
            Goeieavond !
          {% endif %}    

I’ve created another sensor which gives me the temperature outside from weather.hom

- platform: template
    sensors: 
      temperature: 
        unit_of_measurement: °C
        value_template: "{{ state_attr('weather.thuis', 'temperature') }}"

I want this to show in the vertical scroller. But i want it to say:

Temperature outside is … (then the state)

How do i do this?

A few posts up I explained how to add the text "Outdoor Temperature: " to it.

Cool works thx
It even shows the °C after the state
Cool!

Thx mate

Any idea when the title problem will be fixed?

I don’t really give estimated times for anything like this anymore. Currently working 2 jobs, trying to finish up a large project due for my coding bootcamp, and, most importantly, keep the family happy.

When I give time frames for fixes or feature implementations it just adds to the pile of stress I’m trying to manage, so I need to stop doing it. Explaining it here so that I can just link to this post when someone else asks a similar question :slight_smile:

2 Likes

Thx for the insight !
No problem mate!

Can somebody help me with my custom header? I want my text to be aligned to the left (as opposed to the icons to the right). And at the same time change the style options (font-family and font-weight).

This is what I have now:
Screenshot 2020-04-14 at 19.35.25

I use the following code (that I have copied and mixed from this thread :slight_smile: )

custom_header:
  header_text: >-
    <div>
    <div style='display:inline-block'>
    {% if is_state('binary_sensor.middag', 'on')%} Goedemiddag {{user}} {% elif is_state('binary_sensor.ochtend', 'on')%} Goedemorgen {{user}} {% elif is_state('binary_sensor.nacht', 'on')%} Goedenacht {{user}}  {% elif is_state('binary_sensor.avond', 'on')%} Goedenavond {{user}} {% endif %}    
    <div style='display:inline-block'>
    <ha-icon icon='{% if is_state("binary_sensor.presence_10", "on") %}mdi:motion-sensor{% else %}mdi:walk{% endif %}'
    style='color:{% if is_state("binary_sensor.presence_10", "on") %}orange{% else %}{% endif %}'</ha-icon>
    </div>
    <div style='display:inline-block'>
    <ha-icon icon='{% if is_state("binary_sensor.presence_20", "on") %}mdi:motion-sensor{% else %}mdi:walk{% endif %}'
    style='color:{% if is_state("binary_sensor.presence_20", "on") %}orange{% else %}{% endif %}'</ha-icon>
    </div>    
    <div style='display:inline-block'>
    <ha-icon icon='{% if is_state("binary_sensor.vibration_12", "on") %}mdi:vibrate{% else %}mdi:vibrate-off{% endif %}'
    style='color:{% if is_state("binary_sensor.vibration_12", "on") %}orange{% else %}{% endif %}'</ha-icon>
    </div>      
    <div style='display:inline-block'>
    <ha-icon icon='{% if is_state("binary_sensor.vibration_13", "on") %}mdi:fridge-alert{% else %}mdi:fridge{% endif %}'
    style='color:{% if is_state("binary_sensor.vibration_13", "on") %}orange{% else %}{% endif %}'</ha-icon>
    </div>  

Any help is greatly appreciated! I have tried different stuff, but couldn’t get it to work.

Ok, sorry for this, it was indeed both an obvious AND newb issue.
Should have removed compact mode: true.

A possibly total newb or obvious question:
I 'm getting a Your configuration contains comment(s), these will not be saved. Do you want to continue? message when trying to use the vertical scroller in the raw configuration editor.
Do I have to be using yaml mode for lovelace, or is there something else that I’m missing?

custom_header:
  compact_mode: true
  default_tab: >-
    {% if is_state("media_player.playerkatana", "playing") %}1{% else %}0{%
    endif %}
  button_text:
    options: >-
      {{ hours24 }}:{{ minutesLZ }} <br><div style='display:inline-block;
      height:22px; width:22px; vertical-align:bottom;'><ha-icon
      icon='mdi:weather-{% if is_state("weather.home", "partlycloudy")
      -%}partly-cloudy{%- else -%}{{ states('weather.home')}}{%- endif
      %}'></ha-icon></div> {{ states('sensor.temperature_38') }}°
  header_text: >-
    <style>
    #flipper {color:#999;}
    #flip {height:24px;overflow:hidden;}
    #flip > div > div {color:#fff;height:24px;margin-bottom:24px;display:inline-block;}
    #flip div:first-child {animation: show 10s linear infinite;}
    @keyframes show {
    0% {margin-top:-144px;}
    5% {margin-top:-96px;}
    33% {margin-top:-96px;}
    38% {margin-top:-48px;}
    66% {margin-top:-48px;}
    76% {margin-top:0px;}
    100% {margin-top:0px;}}
    #flipper p {position:fixed;color:#999; }
    </style>
    <div id=flipper><div id=flip><div><div>
    {{states('counter.count_espresso')}} coffees today</div></div><div><div>
    {{states('sensor.total_48h_precipitation')}}mm precipitation during the last 48 hours</div></div><div><div>
    Sonoff 2 was on for {{states('sensor.sonoff_2_on')}} minutes today</div></div><div><div>
    {{states('counter.count_espresso')}} coffees today</div></div><div><div> 
swipe_nav:
  animate: swipe
  prevent_default: true
  skip_tabs: 5
  swipe_amount: 10
  wrap: true
title: ''
views:

Sorry, late reply. You had a couple of unclosed divs, didn’t break anything, but you want to make sure that each div has and opening and closing tag. Also, it looks like you’re using reverse_button_direction: true so that’s what I based the changes below on.

Essentially all I did was remove the unneeded first <div> tag, made sure the text element’s div had a closing tag </div>, and gave it a style to push it to the right float:right; and a font font-family: Comic Sans MS, cursive, sans-serif; (fogot to add a font-weight, but just add that to the same style in the first div)

custom_header:
  header_text: >-
    <div style='display:inline-block; float:right; font-family: Comic Sans MS,
    cursive, sans-serif;'> {% if is_state('binary_sensor.middag', 'on')%}
    Goedemiddag {{user}} {% elif is_state('binary_sensor.ochtend', 'on')%}
    Goedemorgen {{user}} {% elif is_state('binary_sensor.nacht', 'on')%}
    Goedenacht {{user}}  {% elif is_state('binary_sensor.avond', 'on')%}
    Goedenavond {{user}} {% endif %} </div> <div style='display:inline-block'>
    <ha-icon icon='{% if is_state("binary_sensor.presence_10", "on")
    %}mdi:motion-sensor{% else %}mdi:walk{% endif %}' style='color:{% if
    is_state("binary_sensor.presence_10", "on") %}orange{% else %}{% endif
    %}'</ha-icon></div><div style='display:inline-block'> <ha-icon icon='{% if
    is_state("binary_sensor.presence_20", "on") %}mdi:motion-sensor{% else
    %}mdi:walk{% endif %}' style='color:{% if
    is_state("binary_sensor.presence_20", "on") %}orange{% else %}{% endif
    %}'</ha-icon></div><div style='display:inline-block'> <ha-icon
    icon='{% if is_state("binary_sensor.vibration_12", "on") %}mdi:vibrate{%
    else %}mdi:vibrate-off{% endif %}' style='color:{% if
    is_state("binary_sensor.vibration_12", "on") %}orange{% else %}{% endif
    %}'</ha-icon></div><div style='display:inline-block'> <ha-icon
    icon='{% if is_state("binary_sensor.vibration_13", "on")
    %}mdi:fridge-alert{% else %}mdi:fridge{% endif %}' style='color:{% if
    is_state("binary_sensor.vibration_13", "on") %}orange{% else %}{% endif
    %}'</ha-icon></div>
1 Like

Thanks alot for your response! I’ll try it and get back to you.