I need help/advice for a first component development


#1

Hello,

As I wanted to learn python and, if it goes well, contribute to home assistant, I decided to try a first project linked to HA :slight_smile:

The end goal is to display some lovelace card with the x trains around a given time/dest/arrival. This would allow to display in red any train canceled/delayed and use it as trigger for an automation.

I have a working python file with this kind of config needed :

CONF_URL = 'http://api.irail.be/connections/'
CONF_FROM_STATION = 'namur'
CONF_TO_STATION = 'bruxelles nord'
CONF_DATE = 'today'
CONF_TIME = 'now'
CONF_TIMESEL = 'departure'
CONF_LANG = 'fr' 

And this output (time, stations, platfomrs, delay, cancel and duration) :

14:20:00 - Namur - 9 - 22.0 - 0 - Bruxelles-Nord - 9 - 13.0 - 0 - Bruxelles-Midi - 57.0
14:46:00 - Namur - ? - 0.0 - 1 - Bruxelles-Nord - ? - 0.0 - 1 - Tournai - 61.0
15:20:00 - Namur - 9 - 0.0 - 0 - Bruxelles-Nord - 9 - 0.0 - 0 - Bruxelles-Midi - 56.0
15:46:00 - Namur - 11 - 0.0 - 0 - Bruxelles-Nord - 11 - 0.0 - 0 - Tournai - 61.0
16:20:00 - Namur - 9 - 0.0 - 0 - Bruxelles-Nord - 9 - 0.0 - 0 - Bruxelles-Midi - 56.0
16:46:00 - Namur - 11 - 0.0 - 0 - Bruxelles-Nord - 11 - 0.0 - 0 - Bruxelles-Midi - 61.0
17:20:00 - Namur - 9 - 0.0 - 0 - Bruxelles-Nord - 9 - 0.0 - 0 - Bruxelles-Midi - 57.0

Now, the questions :slight_smile:

Is it correct that my component will need to be a sensor ? If not what should I use ?
If we take 3 next trains for examples, will they be 3 different sensors ?
For the Lovelace card, I guess I will need to make custom one to display that info with colors etc.

Thank you for reading my request :slight_smile:

Regards,

Tibuski


#2
  1. I am not a dev, this is from observation.

  2. Components and the lovelace frontend are separate, don’t confuse them.

  3. A component should have a separate python script which accesses an api or external resource. So you should write both the python module and a component.

  4. Look at the other transport components https://www.home-assistant.io/components/#transport - generally they seem to be sensors.


#3

Thank you for your reply nickrout.

I think I now find out everything about how to format the component code but I still need to find out the best way to return 3 to 6 time 10-12 values.

The Lovelace card will come after that :slight_smile:

I had a look at the two other rail sensor available but it seems they only returned one or two sensor value.
I didn’t noticed the ‘Transport’ category, thank you for this tip, I will continue digging, I just asked here in // to be sure I don’t do anything wrong :slight_smile: