Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about transit card display #42

Open
JamieP83 opened this issue May 31, 2019 · 1 comment
Open

Question about transit card display #42

JamieP83 opened this issue May 31, 2019 · 1 comment

Comments

@JamieP83
Copy link

Hey,
this is all awesome, thanks for sharing!

I have managed to get all my local train info, however how do i display it like you have sorry?
eg: https://github.com/renemarc/home-assistant-config/blob/master/www/screenshots/group-transit.png

i cant seem to work out what custom card you have to do this part?

@renemarc
Copy link
Owner

renemarc commented Jun 3, 2019

Hey @JamiePryer ,

That Custom UI card was built using:

Custom UI Elements, applied to all cards using this in customize_glob.yaml:

"*.*":
  custom_ui_state_card: state-card-custom-ui

Extra sensor templates to get the hours and dynamic countdowns:

- platform: template
  sensors:
    home_to_market_countdown:
      friendly_name: Bus to Market
      icon_template: mdi:bus
      value_template: >-
        {% set countdown = states('sensor.home_to_market') | int(-1) %}
        {% if countdown > 60 %}
          {% set hours = (countdown / 60) | int %}
          {% set minutes = countdown % 60 %}
          {% if minutes < 10 %}
            {% set minutes = '0' ~ minutes %}
          {% endif %}
          {{hours}}:{{minutes}}
        {% elif countdown >= 0 %}
          {{countdown}}
        {% else %}
          unknown
        {% endif %}

    home_to_market_hour:
      friendly_name: Bus to Market
      icon_template: mdi:bus
      value_template: >-
        {% set departure = state_attr('sensor.home_to_market', 'Origin Stop Departure Time') %}
        {% if departure != None %}
          {% set departure = departure.split(' ') %}
          {% set hms = departure[1].split(':') %}
          {{hms[0]}}:{{hms[1]}}
        {% else %}
          unknown
        {% endif %}

Card-level themes for 10-minutes and 5-minutes until departure highlights, applied through javascript processing inside the customize.yaml:

sensor.home_to_market_hour:
  icon: mdi:cart
  extra_badge:
    entity_id: sensor.home_to_market
  templates:
    theme: >-
      var e = 'sensor.home_to_market';
      if (entities[e] === undefined || entities[e].state === 'unknown') return null;
      var v = parseInt(entities[e].state);
      return v <= 5 ? 'card-critical'
      : v <= 10 ? 'card-warning'
      : null;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants