Home Assistant custom component to retrieve bus timings in Singapore, using the Datamall API provided by LTA.
- Added
operator
andtype
attributes- Now you can tell if its SMRT or Tower Transit etc
- As well as if its single or double deck
- Fixed a bug where Home Assistant throws an error when buses tracking are not in operation
- [BREAKING CHANGE] All sensor values are now strictly integers (no more
ARR
andNA
text)- This is to make automations easier to edit
- Buses that are arriving or not in operation have values set to
0
min - To identify the timing statuses, the attribute flags
bus_arriving
andbus_unavailable
must be used - Refer to table below in Usage for explanation
Installation by HACS is recommended if you would like to stay updated with latest releases.
-
Search for
ha-lta
in the community store and click onDownload this repository with HACS
. -
Once installed, request for an API key at Datamall. This key is required for Home Assistant to interact with the bus API.
-
Restart Home Assistant and configure the component in configuration.yaml with the API key and bus stop codes.
-
Download this repository as a ZIP. Copy the folder
/custom_components/ha-lta
and paste it to the/custom_components/
folder in your Home Assistant directory. If you do not have a custom_components folder, create one. -
Request for an API key at LTA Datamall. This key is required for Home Assistant to interact with the bus API.
-
Configure the component in configuration.yaml with the API key and bus stop codes.
Add the following to your configuration.yaml
file and restart Home Assistant to load the custom component. Bus stop codes are found at all bus stops and are 5 digit numbers such as 97061
and 08138
. At least one bus stop code and one bus is required.
sensor:
- platform: lta
api_key: XXXXXXXXXX
bus_stops:
- code: 'XXXXX'
buses:
- 'XX'
- 'XXX'
- 'X'
- code: 'XXXXX'
buses:
- 'X'
- 'XX'
After you have setup the configuration with valid bus stop codes and bus numbers, multiple sensor entities will be added for each bus number. Each bus number has 3 subsequent timings. The naming convention for a lta
sensor is as follows:
lta.BUS_STOP_CODE-BUS_NUMBER-BUS_ORDER
For example, sensor lta.98051-19-1
indicates the first timing for bus 19 towards bus stop code 98051. Sensor lta.98051-19-2
will indicate the next subsequent timing for the same bus number.
Some buses only operate on certain timings. By default, all bus numbers configured will have their timings and attributes set to either 0
or ""
unless the response from the API contains the necessary data.
Most buses provide their present locations and can be viewed on the map. If no locations are provided by the API, both latitude and longitude are set to 0
respectively.
- Tell the bus timing before leaving the house through a smart speaker
- Setup a dashboard to track timings without opening phone app
- Make use of timing entities for other IOT related projects
- Have full control of what you want to do with bus timings
Version 0.3.0 introduces two new flags that can determine if a bus is either arriving or not in operation. The truth table is as follows:
bus_arriving |
bus_unavailable |
Result | Comments |
---|---|---|---|
T | T | F | Should not happen, considered invalid as bus cannot be unavailable and arriving at same time |
T | F | T | Bus is less than 1 min to arrive at bus stop |
F | T | T | Bus is not in operation at point in time or does not exist |
F | F | F | Bus is taking X min to arrive at bus stop |