Home Assistant custom component to retrieve bus timings in Singapore, using the Datamall API provided by LTA.
operator and type attributesARR and NA text)0 minbus_arriving and bus_unavailable must be usedInstallation by HACS is recommended if you would like to stay updated with latest releases.
Search for ha-lta in the community store and click on Download 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.
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 |
$ claude mcp add ha-lta \
-- python -m otcore.mcp_server <graph>