UTA Trax Public Transportation Sensor

Hey Everyone!
So I recently started beginning my journey with Home Assistant. I have some programming skills but not enough to create a full integration or card, but I wanted to get UTA Public Transportation to notify me where the bus/train is, and how long it takes to get to my location.

Using the provided RESTFUL SIRI API provided by UTA [https://developer.rideuta.com/DataInstructions.aspx], I was able to pull information from the XML document using Node-Red and send that information over to Home Assistant. While I know that there’s possibly other easier ways to do this using either a feed parser, or easier Node-Red components, this is how I decided to do it.

Here is the Flow for Node Red in its entirety.

I first created a time stamp that only runs HTTP requests on Thursday’s between 3PM and 5PM.
These are the times when I know that I should be on the train to get to my local University.

This then parses the HTTP request and goes through the XML component to be readable with functions. I then declared variables that should be outputted, this includes the stop information.

Since this stop is used by other trains, I created a statement that if the RouteID is red (LineRef 703) then continue running the program, if it’s anything else it will end. If the value is correct, then I pull the page one more time and get the vehicle and stop information. I send this using MQTT to home assistant.
If there is no RouteID or no information at all, Node-Red will throw an error that I catch and reset the state.

I create a sensor using Home assistant titled “Vehicle” with this config

- platform: mqtt
  name: Vehicle
  state_topic: "home/Vehicle"

This then updates the state with the LineID and using Googles TTS, I am able to say that the train is 30 minutes away, and I need to leave the house.

Here is the Node-Red Flow if anyone is interested.

[{"id":"840eeee6.791c3","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"95419c8e.795be","type":"http request","z":"840eeee6.791c3","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://api.rideuta.com/SIRI/SIRI.svc/StopMonitor?stopid=TX136034&minutesout=2&onwardcalls=true&filterroute=&usertoken=UUJBT0N0OPF","tls":"","persist":false,"proxy":"","authType":"","x":150,"y":220,"wires":[["c2f82587.7fcba8","92050eb5.fa351"]]},{"id":"7c76532e.0a68ac","type":"change","z":"840eeee6.791c3","name":"","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"Accept\":\"application/json\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":339.00001525878906,"y":120.9999885559082,"wires":[["95419c8e.795be"]]},{"id":"3e759d6.9dde862","type":"inject","z":"840eeee6.791c3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"*/1 15-16 * * 4","once":true,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":145.00000762939453,"y":120.99999046325684,"wires":[["7c76532e.0a68ac"]]},{"id":"1b37f9a1.397d46","type":"function","z":"840eeee6.791c3","name":"Get Route ID","func":"var newMsg = { payload: msg.payload.Siri.StopMonitoringDelivery[0].MonitoredStopVisit[0].MonitoredVehicleJourney[0].LineRef[0] };\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":350,"y":280,"wires":[["cdfe3ddb.a1ad2"]]},{"id":"c2f82587.7fcba8","type":"debug","z":"840eeee6.791c3","name":"","active":false,"console":"false","complete":"false","x":130,"y":300,"wires":[]},{"id":"92050eb5.fa351","type":"xml","z":"840eeee6.791c3","name":"","property":"payload","attr":"","chr":"","x":130,"y":260,"wires":[["1b37f9a1.397d46"]]},{"id":"cdfe3ddb.a1ad2","type":"function","z":"840eeee6.791c3","name":"If/Then","func":"if (msg.payload === \"703\") {\n   return [ null, msg ];\n} else {\n   return [ msg, null ];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":350,"y":340,"wires":[[],["7f0a6852.a9e4b8"]]},{"id":"7f0a6852.a9e4b8","type":"http request","z":"840eeee6.791c3","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://api.rideuta.com/SIRI/SIRI.svc/StopMonitor?stopid=TX136034&minutesout=2&onwardcalls=true&filterroute=&usertoken=UUJBT0N0OPF","tls":"","persist":false,"proxy":"","authType":"","x":370,"y":400,"wires":[["5ff47426.9b234c"]]},{"id":"5ff47426.9b234c","type":"xml","z":"840eeee6.791c3","name":"","property":"payload","attr":"","chr":"","x":350,"y":460,"wires":[["e13d9a0a.f359e8"]]},{"id":"e13d9a0a.f359e8","type":"function","z":"840eeee6.791c3","name":"Get Vehicle","func":"var newMsg = { payload: msg.payload.Siri.StopMonitoringDelivery[0].MonitoredStopVisit[0].MonitoredVehicleJourney[0].VehicleRef[0] };\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":460,"wires":[["512dff1f.9644","20344c2f.25b534"]]},{"id":"512dff1f.9644","type":"debug","z":"840eeee6.791c3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":500,"wires":[]},{"id":"20344c2f.25b534","type":"mqtt out","z":"840eeee6.791c3","name":"","topic":"home/Vehicle","qos":"","retain":"","broker":"db4cb1fd.0b1fe","x":810,"y":460,"wires":[]},{"id":"261da307.980d6c","type":"function","z":"840eeee6.791c3","name":"RESET","func":"var newMsg = { payload: msg.payload.Siri.$.version };\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":220,"wires":[["a0ea7faf.432c6","20344c2f.25b534"]]},{"id":"a0ea7faf.432c6","type":"debug","z":"840eeee6.791c3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":280,"wires":[]},{"id":"300b7fe9.0314d","type":"catch","z":"840eeee6.791c3","name":"","scope":["1b37f9a1.397d46"],"uncaught":false,"x":390,"y":220,"wires":[["261da307.980d6c"]]},{"id":"db4cb1fd.0b1fe","type":"mqtt-broker","z":"","name":"","broker":"192.168.0.101","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

This has many uses, you can also use this to get Longitude and Latitude of vehicles and display their location. This program can be used with any XML based API to get information.

1 Like