Custom sensor for dutch license plate checks (APK check)

Hi all,

I’ve written a custom sensor which can check Dutch license plate id’s in the database of the RDW (the governmental department for road traffic). It will create sensors for the APK due date, the insured flag and a flag which signals if the manufacturer of the car has issues a recall because of a serious safety problem.

Let me know if you like it!

https://github.com/eelcohn/home-assistant-rdw/

RDW1
RDW2

5 Likes

Thanks! Had to change the custom component name from rdw-1.0.1.py to rdw.py to get it to work. But now it works like a charm!

Thanks, good to hear that! I’ve renamed the rdw-1.0.1.py to rdw.py so that shouldn’t be a problem anymore in the future.

Hi, nice component! Thanks for your good work. I had to make a few changes since the RDW date syntax for my car was changed some time ago.

line 37 I to change to:
RDW_DATEFORMAT = '%Y%m%d'

And for my own convenience I changed line 204 to :
self.expdate = datetime.strptime(rdw_data['vervaldatum_apk'], RDW_DATEFORMAT).date().strftime('%d-%m-%Y')

Now the date is presented in a more natural way for me. Perhaps the last addition could be parameterised, but I lack the time and experience with custom components to figure that out myself

Thank you for your feedback, and for notifying me that the RDW changed the date format in their API :slight_smile:
I’ve updated the RDW sensor to 1.0.3 which includes your fix. I’ve also added the dateformat configuration value so that you can pick your own date format without editing the python file, e.g.:

sensor:
  - platform: rdw
    name: "Toyota Auris"
    plate: 16RSL9
    dateformat: '%d %b %Y'
    sensors:
      - expdate
      - insured
      - recall

I’ve updated the code yesterday to v2.0.0. Changelog for v2.0.0 is:

  • Added detailed recall information as attributes of the recall sensor
  • The sensor icons will change to a warning icon if the APK date has expired, if the car isn’t insured or if there’s a unresolved recall
  • Fixed custom_updater.json

Hi,

Would be great if you can add support for HACS because Custom Updater will shut down in the near future.

@Sjeff: thanks for the tip, but I’m working on an update so that the RDW sensor will be an official part of the Home Assistant repository :slight_smile: It could take a couple of weeks, but after that you won’t need the custom updater for the RDW sensor anymore.

Nice! Keep up the good work!

did you make some progress ?
The rdw website where it request the data seems to be changed/unavailable

Yes I’ve definitely made some progress. I’ve updated most of the code for the newest home assistant functions like:

  • configuration by GUI entity register
  • async calls
  • the API is now called using the sodapy library, which is the recommended by RDW themselves
  • moved from @Throttle to async_track_time_interval()
  • more efficient managing of update() calls so sensors get updated according to SCAN_INTERVAL instead of the default of every 10 seconds or so

Only thing not working right now is the old configuration.yaml style setup. I’m working on that and hope to fix that in a couple of days (don’t hold me to it; I’m doing this in my spare time as well :slight_smile: )

AFAIK the RDW hasn’t changed their website in any way. They do sometimes take the API website offline for maintenance, I’ve had 503 errors reported to me from time to time.

Hm your old component still works fine for me for a long time now. And thanks for that, I love it!

1 Like

Thank you!

1 Like

I’ve just updated the master branch on GitHub to v2.9.0. Please note that this is a breaking change to your configuration.yaml settings!

Changes in v2.9.0:

  • Rewritten all functions to async variants
  • Added configuration by GUI entity register (config_flow)
  • The API is now called using the sodapy library, which is the recommended by RDW themselves
  • Moved from @Throttle to async_track_time_interval()
  • More efficient managing of update() calls so sensors get updated according to SCAN_INTERVAL instead of the default of every 10 seconds or so

From now on you can set up your RDW component from the GUI using the Add Entity option :slight_smile:
If you prefer setting it up with configuration.yaml, you’ll have to change your existing setup:
Simple setup:

rdw:
  - plate: 16RSL9

Customized setup:

rdw:
  - plate: 16RSL9
    name: "Toyota Auris"
    dateformat: '%d %b %Y'
    binary_sensors:
      - insured
    sensors:
      - expdate
      - recall

v2.9.0 is hopefully the last release before I’ll try and get it integrated into the official Home Assistant repository.

Hi eelcohn,

I upgraded to the new RDW application. I installed v2.9.0. I used HA Integrations to define 2 license plates. Both were created successfully.

However, after rebooting HA, I get errors for one license plate:

Logboekdetails ( ERROR )
Logger: homeassistant.components.binary_sensor 
Integration: Binaire sensor (documentation, issues) 
First occured: 23:38:22 (1 occurences) 
Last logged: 23:38:22

Error while setting up rdw platform for binary_sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/rdw/binary_sensor.py", line 40, in async_setup_entry
    hass.data[DOMAIN][entry.data[CONF_PLATE]],
KeyError: '<license-plate>'
===================================================================
Logboekdetails ( ERROR )
Logger: homeassistant.components.sensor 
Integration: Sensor (documentation, issues) 
First occured: 23:38:22 (1 occurences) 
Last logged: 23:38:22

Error while setting up rdw platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/config/custom_components/rdw/sensor.py", line 44, in async_setup_entry
    hass.data[DOMAIN][entry.data[CONF_PLATE]],
KeyError: '<license-plate>'
===================================================================

Logboekdetails ( WARNING )
Logger: root 
First occured: 23:38:16 (2 occurences) 
Last logged: 23:38:16
Requests made without an app_token will be subject to strict throttling limits.

When I delete one license plate ( doesn’t matter which one ) the errors disappear and only the warning is displayed after a reboot of HA. Any idea would might go wrong?

My real license plate was changed in the error logging to: license-plate

Thanks for letting me know about this problem. I’ll try and look into it this weekend. Have you set the cars up by configuration.yaml or by using the GUI integrations?

No, both cars are NOT defined in the configuration.yaml. I used the integration functionality to define them automatically.

Thank you for your feedback. There was indeed an error when rebooting after setting up multiple RDW entities.

I’ve pushed v2.9.1 to the GitHub repository which should fix the problem you encountered. Can you try this new version? To update from old versions to the latest version please use this procedure:

  1. Remove all RDW entities from the GUI Integrations menu
  2. Move the./custom_components/rdw/ folder to a safe location
  3. Install the latest version by using git clone https://github.com/eelcohn/home-assistant-rdw/ rdw and move the rdw folder to ./custom_components/rdw
  4. Restart your home assistant

Hi eelcohn,

thank you for the quick fix. RDW v2.9.1 solves the problem. I can now define multiple RDW entities. I have one more question. What is the meaning of the warning:

Logboekdetails ( WARNING )

Logger: root
First occured: 15:39:53 (2 occurences)
Last logged: 15:39:54

Requests made without an app_token will be subject to strict throttling limits.

That warning comes from the sodapy Python library. sodapy is the recommended way by RDW and Socrata to interact with OpenData databases. I’ve decided to use the official library, and stop using my own custom code to interact with OpenData.

IMO that warning is a bit useless, but it has to be fixed in the sodapy repository because at this time I haven’t found a way to disable that warning (see issue #68 in the sodapy repository)