Custom Component: here_travel_time

ok: this works:

- unique_id: yvonnes_way_to_work
  attributes:
     route: "{{ state_attr('sensor.yvonnes_arbeitsweg','route') }}"
     unit_of_measurement: min
     destination_name: "Klaus-Bungert-Straße"
     friendly_name: "Yvonnes Weg zur Arbeit"
     duration_in_traffic: "{{ state_attr('sensor.yvonnes_arbeitsweg','duration_in_traffic') }}"
     duration: "{{ state_attr('sensor.yvonnes_arbeitsweg','duration') }}"
   state: "{{ states('sensor.yvonnes_arbeitsweg') }}"
````
After the update, replace the sources :-)

Thanks for the idea, works great, I had to use states and not state_attr though as the HERE integration doesn’t use attributes any more, they are all separate sensors

Yes, I’m still on the former version 2022.7.x and simply preparing the update :wink:

It’s something funny, we have to think about deeper:
A sensor has been splitted into different entities which we have to combine again in a template sensor in order to work with it as before. :crazy_face:

I think I read it was something to do with an issue of the route being over 255 chars sometimes so had to be split out. It’s only a hack for the travel-time-card until it is updated (if at all)

which brings me back to my issue, that I wanted to filter out of the route only the highways.
So let’s look for a solution to filter the state. A new project…

Solution if the number, order and total of highways is known:

{% set route = state_attr('sensor.jorg_arbeitsweg','route') %}
{% set hlist = ('A44', 'A57', 'A52', 'A3', 'A42') %}
{% set i = 0 %}
{% for i in range(0,5) %}
  {%- if hlist[i] in route -%}
    {{ hlist[i] }},
  {%- endif -%}
{%- endfor %}

If sombody have an idea how to make this mor flexible (the order of highways could change), the solution would be highly appreciated

Just remove the N route ( or any number patern you want really)

{{states('sensor.here_travel_time_alarm_route')|regex_replace(find='N[0-9]{2,3}[^;]+;', replace='', ignorecase=False)}

regex explanation:
N[0-9]{2,3} matches anything starting with N and then 2 or 3 digits
[^;]+ matches anything except a ; of any length
; finaly matches the ; that seperates entries.

Hi, thanks for this hint.
But that code lists simply evrything:

{{state_attr('sensor.jorg_arbeitsweg','route')|regex_replace(find='A[0-9]{2,3}[^;]+;', replace='', ignorecase=False)}}

‘A57; A42; B223 - Konrad-Adenauer-Allee; B223; A516; A3; B58 - Schermbecker Landstraße; L1 - Postweg; L896 - Borkener Straße’
Expected result A57,A42,A516,A3

Ok, read some docs and now I have the solution:

{% set list = state_attr('sensor.jorg_arbeitsweg','route')|regex_findall('A[0-9]{1,3}', ignorecase=True)%}
{{list}}

yeah in your case the code should have been:

{{state_attr('sensor.jorg_arbeitsweg','route')|regex_replace(find='B[0-9]{2,3}[^;]+;', replace='', ignorecase=False)}

removing all the B routes

and in case of your method which is even more elegant I suppose :wink: I would include a | join(',') to turn it from a list to a comma seperated string.

1 Like

Good idea. I check how to do it.
THX

Hi, before I open a ticket and the devs decide to depricate the route entity I start discussion here:
I already updated to 8.6 and directly recieve these errors:

Logger: homeassistant
Source: core.py:1099
First occurred: 15:36:59 (4 occurrences)
Last logged: 15:51:59

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 151, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 110, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 348, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 532, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 646, in _async_write_ha_state
    self.hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1438, in async_set
    state = State(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1099, in __init__
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.jorg_arbeitsweg_route. State max length is 255 characters.

I have a longer distance to my workplace. So it is possible that the route seem to provide some characters more.
Isn’t it possible to simply cut the characters on the max length point?
May I can configure that, what I did in the template sensor shown above.

I already opened a PR for that 2 weeks ago to avoid removing the route altogether. Haven’t got any feedback https://github.com/home-assistant/core/pull/76553

1 Like

looks good. Thanks. Then let’s wait…:slight_smile:

Hi, how can I increase the debug level? Core.py seems not to be the right component
The route entity floods my system log

Can you give me some ideas how I can handle this?

The way I see it is that Frenck is punishing me and every user of the integration because I was “modernizing” it. I am really close to giving up maintaining my integrations =(

My recommendation:
Skip the integration and make a component out of this.

1 Like

@Pirol62 @Mariusthvdb the route needs to be removed so the integration is allowed to be part of core.

Do you see any reason why one would choose HERE over Waze? I am thinking to completely remove it and maybe supply it as a custom component.

1 Like

I noticed yes, and I have added my hope in a comment HA wont simply cut essential information (because we can open another app), but instead start a dialogue how we can keep that info.

Given the stance the devs take, I have not much confidence it will be changed anytime soon, so I would certainly +1 the Here travel time Custom component, with the full route as attribute! (dont truncate it as standalone sensor.)
The way this attribute is used in a dynamic setup, there would hardly be any issue in recorder, especially since we dont record it at all… nor auto refresh (enable polling)
for that reason alone I fail to comprehend Frencks decision, or Balloobs remark on the app.

That way we would keep the best of both worlds.

As I tested Waze before, I ended up preferring Here. Have to lookup why that was, Could it have to do with Google being an owner?

Waze did never work that accurate for me. So it is no choice for me. I always would use Here.
And thats what I meant above: make a custom component out of this and store your integration work as experience :slight_smile:
It is useless to struggle with the devs and your’re much more flexible in case of bugfixing or improvements.