Open Tuumke opened 4 years ago
It might be that the NS API is not functioning well because it is overworked. I'll look into getting better feedback. Could you share your sensor config for this one (of course without the API key and such)?
platform: nederlandse_spoorwegen
api_key: !secret ns_api
routes:
- name: Harderwijk-Amersfoort
from: Hd
to: Amf
- name: Amersfoort-Harderwijk
from: Amf
to: Hd
And my automation:
id: 'Check NS in de Middag'
alias: 'Check NS in de Middag'
trigger:
- platform: template
value_template: "{% if is_state('sensor.amersfoort_harderwijk', 'departure_delay') %}true{% endif %}"
condition:
- condition: time
after: '13:00:00'
before: '18:00:00'
action:
- service: notify.telegram
data_template:
title: "Trein naar Harderwijk heeft vertraging"
message: |
Vertrektijd {{ state_attr('sensor.amersfoort_harderwijk', 'departure_time_actual') }}
vanaf spoor {{ state_attr('sensor.amersfoort_harderwijk', 'departure_platform_actual') }}
aankomst om {{ state_attr('sensor.amersfoort_harderwijk', 'arrival_time_actual') }}
Volgende trein vertrekt om {{ state_attr('sensor.amersfoort_harderwijk', 'next') }}
Going {{ state_attr('sensor.amersfoort_harderwijk', 'going') }}
departure_delay {{ state_attr('sensor.amersfoort_harderwijk', 'departure_delay') }}
departure_time_planned {{ state_attr('sensor.amersfoort_harderwijk', 'departure_time_planned') }}
departure_time_actual {{ state_attr('sensor.amersfoort_harderwijk', 'departure_time_actual') }}
status {{ state_attr('sensor.amersfoort_harderwijk', 'status') }}"
Not sure which of the 2 makes the checks to the NS api? I guess the sensor? Is there a reason why we have 2 API keys in the portal? Maybe there is an API limit? -edit-
Het gebruik van de NS API’s is gratis, maar er zit wel een limiet op het aantal calls dat uitgevoerd mag worden. Het limiet verschilt per product. NS bepaald dit limiet en dit kan aangepast worden indien dit door NS gewenst is.
Oy, the typo in 'bepaald' is a nice cringe. As far as I understand HA, the sensor does the actual calls/checking, as it is responsible for setting its boolean to true or false according to whatever you are measuring. Your automation then uses that state to trigger the Telegram notification (or not). I'm curious to how often HA runs the sensor check; if it is run multiple times every minute, you might run out of your API quotum. Maybe you can see it in your history?
Oh, the API portal has an overview too: https://apiportal.ns.nl/Developer/Analytics
I've been getting the same issue lately and it's not related to quotas (have lived without HA for a few days, so usage is sub-any-quota). Shall we set up a custom exception to handle this one?
I'm currently taking a new look at the library, also because of #34 so I'll implement this exception handler there too.
Thanks for your patience, ns-api hasn't been a real focus for me lately 😅
Was requested to create an issue here about the NoneType error i had in HomeAssistant.
The error is starting to shop up more and more. Will look into if we can turn on extra logging