Compact Custom Header

@Mariusthvdb For the icon issue, make sure the tab you are adding an icon to already has an icon and not just a title. Will look into the array.length error. For the template, it’s just JavaScript so you can use ternarys, multiple if statements, if else, etc. In your particular case, else if is the best option so you can have that fallback else statement.

@klogg Thank you for the thorough reply rest assured I’m on the case, as I’m sure you’ve seen your not the only one with the issue. Bear with me.

@ramonvanbiljouw @jimz011 Seems to be the same issue as @klogg, looking into it.

No problem…

ok, I did take out the icon to be sure… put the icon back again, and then that icon is displayed, not the templated icon… changed entities to entity and lost the ‘return’ and went from === to ==. Don’t know what else could be wrong now in the template.

I’ ve also carefully inspected the template for spacing, (missed a dash too, according to the doc) and now use:

cards:
# https://github.com/maykar/compact-custom-header/wiki/Main-Config-Options
  - type: custom:compact-custom-header
    main_config: true
    header: true
    menu: show
    options: show
    chevrons: true
    exceptions:
      - conditions:
          user_agent: iPhone
        config:
          menu: hide
          notifications: hide
          header: true
          options: hide
    conditional_styles:
      template:
        tab:
          12:
            - icon: >
                if (entity['sensor.family_home'].state == '0') 'mdi:account-off';
                else if (entity['sensor.family_home'].state == '1') 'mdi:account';
                else if (entity['sensor.family_home'].state == '2') 'mdi:account-multiple';
                else if (entity['sensor.family_home'].state == '3') 'mdi:account-multiple-check';
                else 'mdi:account-group';

the mentioned error isnt there anymore, but still no luck. either the icon of the view is displayed, and when taken out, the view name. No template icon.

there’s another issue, and I think it started after having set the exceptions for the iPhone:

right side menu (Options)
48
left side (Home)
02

both on Chrome and Safari (Mac) not in the iOS 2 beta app.

error is back unfortunately:

Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'array.length')

Please try the latest version 1.0.3b6, multiple fixes. Thanks for your patience.

@Mariusthvdb Your example should work as you just posted with the latest fixes as well as fix your other issues. Keep me posted.

cool, thanks for all your efforts!
the overlapping menu icons left and right are gone, showing fine again. No more errors in inspector either.

unfortunately my template menu icon is still not working, and showing the fixed icon set in the view configuration.
Just to be sure I do it correctly: this template is set in the main config, not the actual view config?

maybe give me a template that is sure to work, and tested on your side? Might simply be the way the template is evaluating the entity on this side.

So far so good.

Thank you.

That fixed my problems. Thanks for all your efforts

So this is working for me perfectly (when I change the entity of course). The only difference is the hyphen in front of “template:”. This is entirely on how I’m handling the config and I just updated the readme. I may remove the need for that at some point, but give it a try.

conditional_styles:
  - template:
      tab:
        12:
          - icon: >
              if (entity['sensor.family_home'].state == '0') 'mdi:account-off';
              else if (entity['sensor.family_home'].state == '1') 'mdi:account';
              else if (entity['sensor.family_home'].state == '2') 'mdi:account-multiple';
              else if (entity['sensor.family_home'].state == '3') 'mdi:account-multiple-check';
              else 'mdi:account-group';

So I should/can delete the swipe-navigation card now?

You can delete swipe-navigation and enable swipe in CCH now, yes.

1 Like

All is back to normal now, thank you for the fixes! Go take a break my friend :stuck_out_tongue:

1 Like

So the swipe navigation isn’t working now and I don’t see an option in cch settings?

NVM I see I now need to enable it in lovelace - is that for every card or only first card?

Configure in yaml for now: swipe nav config

Only for first card?

All config in first card only

1 Like

Man, I can’t wait to get home and update CCH. Been looking forward to Swipe and Ranges. WOOHOO!!!

had already tried that yes, but unfortunately no succes.

Having copied your last post exactly in my main config, only thing left I can imagine is a setting in the view itself. I havent got a number there, so maybe that’s it?

this is my view:

title: Phones & Tablets
path: phones_tablets
icon: mdi:alert
# custom-ui JS template
#  {% set state = states('sensor.family_home') %}
#  {% set mapper = {'0': 'mdi:account-off',
#                   '1': 'mdi:account',
#                   '2': 'mdi:account-multiple',
#                   '3': 'mdi:account-multiple-check'} %}
#  {{ mapper[state] if state in mapper else 'mdi:account-group'}}

# Jinja template
#  {% if is_state('sensor.family_home','0') %} mdi:account-off
#  {% elif is_state('sensor.family_home','1') %} mdi:account
#  {% elif is_state('sensor.family_home','2') %} mdi:account-multiple
#  {% elif is_state('sensor.family_home','3') %} mdi:account-multiple-check
#  {% else %}} mdi:account-group
#  {% endif %}
badges:
  - sensor.home_badge
cards:
  - type: custom:compact-custom-header
  - !include /config/lovelace/tiles/tiles_family.yaml

and this my CCH main config:

# https://github.com/maykar/compact-custom-header/wiki/Main-Config-Options
type: custom:compact-custom-header
main_config: true
header: true
menu: show
options: show
chevrons: true
exceptions:
  - conditions:
      user_agent: iPhone
    config:
      menu: hide
      notifications: hide
      header: true
      options: hide
conditional_styles:
  - template:
      tab:
        12:
          - icon: >
              if (entity['sensor.family_home'].state == '0') 'mdi:account-off';
              else if (entity['sensor.family_home'].state == '1') 'mdi:account';
              else if (entity['sensor.family_home'].state == '2') 'mdi:account-multiple';
              else if (entity['sensor.family_home'].state == '3') 'mdi:account-multiple-check';
              else 'mdi:account-group';

Update

well, don’t know why, but all of a sudden the icon snapped into place! Hope this is here to stay, as it was one of the niceties regular HA had over Lovelace. You’ve just made my day :wink: thank you very much indeed!

I’ll leave the post as it was, for reference to other community members.

@mayker The last update is great.
Thank You very much!

@mayker, can I just suggest you have an error in the docs? (It was looking at @Mariusthvdb post that showed me why mine wasn’t working :slight_smile: )

Should this:

- type: custom:compact-custom-header
  main_config: true
  conditional_styles:
  - template:
      - background: >  # Style the header's background can use CSS colors or background images.
          if (entity["input_boolean.living_room"].state == "off") "#000";
          else if (entity["input_boolean.living_room"].state == "on") "url('/local/bg.jpg')";
      - tab:
          3:  # Number of the tab to style.
          - icon: >  # MDI icon for tab or button.
              if (entity["device_tracker.galaxys8"].state == "home") "mdi:account";
              else "mdi:account-off";
          - color: >  # MDI icon for tab or button.
              if (entity["device_tracker.galaxys8"].state == "home") "blue";
              else if (entity["device_tracker.galaxys8"].state == "not_home") "#ffffff";

be this:

- type: custom:compact-custom-header
  main_config: true
  conditional_styles:
  - template:
      background: >  # Style the header's background can use CSS colors or background images.
        if (entity["input_boolean.living_room"].state == "off") "#000";
        else if (entity["input_boolean.living_room"].state == "on") "url('/local/bg.jpg')";
      tab:
        3:  # Number of the tab to style.
        - icon: >  # MDI icon for tab or button.
            if (entity["device_tracker.galaxys8"].state == "home") "mdi:account";
            else "mdi:account-off";
        - color: >  # MDI icon for tab or button.
            if (entity["device_tracker.galaxys8"].state == "home") "blue";
            else if (entity["device_tracker.galaxys8"].state == "not_home") "#ffffff";

haha. well you never know who you help with posting a bit of a struggle…:wink:
must say I am a bit confused with the need for dashes in this config.
So used to only needing them when more than 1 item is listed, I would think (in my specific icon template) to need this:

conditional_styles:
  template:
    tab:
      12:
        icon: >
          if (entity['sensor.family_home'].state == '0') 'mdi:account-off';
          else if (entity['sensor.family_home'].state == '1') 'mdi:account';
          else if (entity['sensor.family_home'].state == '2') 'mdi:account-multiple';
          else if (entity['sensor.family_home'].state == '3') 'mdi:account-multiple-check';
          else 'mdi:account-group';

instead of:

conditional_styles:
  - template:
      tab:
        12:
          - icon: >
              if (entity['sensor.family_home'].state == '0') 'mdi:account-off';
              else if (entity['sensor.family_home'].state == '1') 'mdi:account';
              else if (entity['sensor.family_home'].state == '2') 'mdi:account-multiple';
              else if (entity['sensor.family_home'].state == '3') 'mdi:account-multiple-check';
              else 'mdi:account-group';