andystewart999 / ha_transportnsw

A Home Assistant component to provide real-time Transport NSW journey information
GNU General Public License v3.0
7 stars 1 forks source link

Transport api and parking api #4

Closed Tekno-man closed 2 months ago

Tekno-man commented 2 months ago

Is the api used for this integration similar to the parking api (https://opendata.transport.nsw.gov.au/dataset/car-park-api#:~:text=The%20Car%20Park%20API%20provides,to%20travel%20on%20public%20transport.) ? Would it be possible to pull the parking spaces as a sensor in this integration or would a whole new integration be required?

andystewart999 commented 2 months ago

It's in the same family of APIs of course but it is a different API call, and would have to be coded as a separate integration (or an extension of this one).

It's a lot more straightforward to leverage than the trip planner, all you need is an API key and the facility code and it returns a bit of JSON. I actually use this API myself already via NodeRed, although you could use Home Assistant's Rest API sensor and a bit of templating.

Example API call: https://api.transport.nsw.gov.au/v1/carpark?facility=7

Example response:

{
"spots":"213",
"occupancy":
    {"total":"212"}
}

There's a bit more in the response than that but that's what it boils down to... take occupancy:total away from spots and you've got how many free spaces there are.

Good luck!

andystewart999 commented 2 months ago

I'm going to close this issue, although @Tekno-man I'd be happy to assist if you have any issues accessing the Parking API.

Tekno-man commented 2 months ago

Thanks so much. I will reach out if I get stuck.

Cheers Vijay

On Mon, 9 Sept 2024, 07:52 Andy Stewart, @.***> wrote:

I'm going to close this issue, although @Tekno-man https://github.com/Tekno-man I'd be happy to assist if you have any issues accessing the Parking API.

— Reply to this email directly, view it on GitHub https://github.com/andystewart999/ha_transportnsw/issues/4#issuecomment-2336835812, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMYZ66TGRVVX6OXR2JJHPYDZVTBIXAVCNFSM6AAAAABNTKIIQKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZWHAZTKOBRGI . You are receiving this because you were mentioned.Message ID: @.***>

Tekno-man commented 1 week ago

Hi Andy, just hoping to get a bit of advice. I am trying to build the parking sensor in HA but keep getting "unknown" as the data. I have pulled key from the tNSW website and have the following code.

sensor: - platform: rest resource: "https://api.transport.nsw.gov.au/v1/carpark?facility=17" method: GET name: "Hills Showground Parking" scan_interval: 180 headers: accept: "application/json" Authorization: "apikey xxxxxx"

any advice would be greatly appreciated.

DW figured it out, Thought it wasn't working but it just wasn't producing the whole json text. I need to put a template filter for it to show anything. value_template: "{{ value_json.spots }}"

Cheers