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

filter on line number #12

Open
tistjendop opened this issue Jan 5, 2024 · 7 comments
Open

filter on line number #12

tistjendop opened this issue Jan 5, 2024 · 7 comments

Comments

@tistjendop
Copy link

Is there a way to filter this card so that only selected line numbers are shown?
At our stop several bus lines pass and I'm only interested in one of them.

@bollewolle
Copy link
Owner

I'm not sure anymore but I don't think so no. I'm not really planning on updating this card anymore. I'm experimenting on useing the "flex-table-card" which can be used for a lot more purposes instead of mainting a specific card here for just 1 puprose.

It's still a work in progress but so far I got the following config with the "flex-table-card" which closely simulates the existing functionality of the "delijn-card", but it also includes the fact if a tram/bus is cancelled:

type: custom:flex-table-card
title: Brugsepoort (direction Center)
entities:
  include: sensor.brugsepoort_gent
columns:
  - name: Line
    data: next_passages
    modify: >-
      '<div class= "line-number" style="padding: 1px 1px 4px 1px; height: 16px;
      color: #' + x.line_number_colourFrontHex + '; background-color: #' +
      x.line_number_colourBackHex + '; border-color: #' +
      x.line_number_colourBackBorderHex + '">&nbsp;' + x.line_number_public +
      '&nbsp;</div>'
    align: center
  - name: Type
    data: next_passages
    modify: >-
      '&nbsp;<ha-icon icon="mdi:' + x.line_transport_type.toLowerCase() + 
      '"></ha-icon>'
  - name: Towards
    data: next_passages
    modify: x.final_destination
  - name: Due in (min)
    data: next_passages
    modify: x.due_in_min
  - name: RT/C
    data: next_passages
    modify: |-
      if (x.cancelled)
        '<ha-icon icon="mdi:cancel">'
      else if (x.is_realtime)
        '<ha-icon icon="mdi:signal-variant">'
      else
        ''
    align: center
style: |
  .line-number{
    display:block;
    float:left;
    min-width:2.75em;
    text-align:center;
    font-weight:bold;
    color:#fff;
    border-radius:4px;
    border:3px solid #000;
    margin-left:0rem;
    margin-right:0.75rem;
    font-size:1rem;
    line-height:1.5em;
  }

I haven't tried filtering though, not sure if that's possible with flex tables either. It does support the auto entities, perhaps something is possible there, although it's more for listing multipe entities I believe and not for filtering records within an entity.

Anyway, hopefully you can find a solution.

@nicobresseleers
Copy link

nicobresseleers commented Jan 8, 2024

Thanks .. I tried the flex solution and it seems to work...( for a minute) .. then i got this strange error: ( not sure if the sensons should come back as "unnamed" neither? you seem to have the "haltenaam"?

image

not sure where this comes from ? i guess installation went wrong somewhere?

For the record the config:

sensor:

  • platform: delijn
    api_key: "xxx"
    next_departure:
    • stop_id: '101770'
    • stop_id: '101765'
    • stop_id: '105565'
    • stop_id: '105570'

( yes I ask data from 4 "haltesleutels")

@nicobresseleers
Copy link

nicobresseleers commented Jan 9, 2024

mhmm: a full reboot solved it (partialy)... ( strange since normally a restart is sufficient...)

sensors now have a names... but other error stays:
image

folling error found:

ERROR (MainThread) [homeassistant.components.delijn.sensor] De Lijn http error

(still : sometimes it works)

@bollewolle
Copy link
Owner

Yeah, the entity names are defined by the integration, which is not ideal as they might change in time. Ideally the integration would need to be rewritten to allow config from the UI instead of yaml and to allow renaming of the entities and such, but I haven't worked in Python in years (basically since I created that integration, which was the first thing I ever did in Python) and a complete lack of time :( It's why someone else took over the integration as well in the past years.

The "Cannot read properties of undefined" error is a typical Javascript error when the element that the function is trying to read is "undefined", meaning that there's no actual data defined in it. In this case it means that there's no data in your next_passages attribute of the sensor (that attribute should contain an array with all the passages of your stop). Did you check in the "Developer Tools", under "States" if your sensor.cogelsplein_antwerpen has data in the next_passages attribute? If not then it's either that there are no passages OR that there's an issue with the integration. It should looke something like this:
image

A general FYI, a small adjustment was needed compared to the above because the style wasn't applied. In the above I forgot to add the "card_mod" part in which the "style" belongs. Below you can find the correct one, which should also result in the Line numbers being a bit larger and bold:

type: custom:flex-table-card
title: Wittekaproenenplein, Gent
entities:
  include: sensor.brugsepoort_gent
columns:
  - name: Line
    data: next_passages
    modify: >-
      '<div class= "line-number" style="padding: 1px 1px 4px 1px; height:
      16px; color: #' + x.line_number_colourFrontHex + '; background-color: #'
      + x.line_number_colourBackHex + '; border-color: #' +
      x.line_number_colourBackBorderHex + '">&nbsp;' + x.line_number_public +
      '&nbsp;</div>'
    align: center
  - name: Type
    data: next_passages
    modify: >-
      '&nbsp;<ha-icon icon="mdi:' + x.line_transport_type.toLowerCase() + 
      '"></ha-icon>'
  - name: Towards
    data: next_passages
    modify: x.final_destination
  - name: Due in (min)
    data: next_passages
    modify: x.due_in_min
  - name: RT/C
    data: next_passages
    modify: |-
      if (x.cancelled)
        '<ha-icon icon="mdi:cancel">'
      else if (x.is_realtime)
        '<ha-icon icon="mdi:signal-variant">'
      else
        ''
    align: center
card_mod:
  style: |
    .line-number{
      display:block;
      float:left;
      min-width:2.75em;
      text-align:center;
      font-weight:700;
      color:#fff;
      border-radius:4px;
      border:3px solid #000;
      margin-left:0rem;
      margin-right:0.75rem;
      font-size:1rem;
      line-height:1.5em;
    }

And for those that want to try the "auto-entities" option, this works as well but I don't immediately see any added value to it. I thought it could work to filter out only specific lines for example, but I've not found a way (it's like I expected limited to only filtering on entities to list entities based on certain conditions). Anyway, for those that want to try you can use it like so:

type: custom:auto-entities
filter:
  include:
    - attributes:
        stopname: Brugsepoort, Gent
  exclude: []
card:
  type: custom:flex-table-card
  title: Brugsepoort, Gent
  columns:
    - name: Line
      data: next_passages
      modify: >-
        '<div class= "line-number" style="padding: 1px 1px 4px 1px; height:
        16px; color: #' + x.line_number_colourFrontHex + '; background-color: #'
        + x.line_number_colourBackHex + '; border-color: #' +
        x.line_number_colourBackBorderHex + '">&nbsp;' + x.line_number_public +
        '&nbsp;</div>'
      align: center
    - name: Type
      data: next_passages
      modify: >-
        '&nbsp;<ha-icon icon="mdi:' + x.line_transport_type.toLowerCase() + 
        '"></ha-icon>'
    - name: Towards
      data: next_passages
      modify: x.final_destination
    - name: Due in (min)
      data: next_passages
      modify: x.due_in_min
    - name: RT/C
      data: next_passages
      modify: |-
        if (x.cancelled)
          '<ha-icon icon="mdi:cancel">'
        else if (x.is_realtime)
          '<ha-icon icon="mdi:signal-variant">'
        else
          ''
      align: center
  card_mod:
    style: |
      .line-number{
        display:block;
        float:left;
        min-width:2.75em;
        text-align:center;
        font-weight:700;
        color:#fff;
        border-radius:4px;
        border:3px solid #000;
        margin-left:0rem;
        margin-right:0.75rem;
        font-size:1rem;
        line-height:1.5em;
      }

@nicobresseleers
Copy link

both have content in the atributes of the entitity:

image
image

but not in states under developer?
image
image

"Turnhoutsebaan", has data in both.... and is working fine... , it seems it's fetching the data but not ending up correctly

could it be that data.delijn is refusing call? I see some errors in the dev dashboard:
image

@nicobresseleers
Copy link

strange... all work if i use

sensor.turnhoutsebaan_antwerpen
sensor.turnhoutsebaan_antwerpen_2
sensor.unnamed_device
sensor.unnamed_device_2

Why are some changing name and others are not? don't see it.

@bollewolle
Copy link
Owner

I believe the _2 typically happens when an Integration was removed and then created again, or when there's 2 entitities being created with the same name. I have some of those for other Integrations as well.

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

3 participants