←back to thread

174 points nicosalm | 2 comments | | HN request time: 0.407s | source
Show context
fullstackchris ◴[] No.41907914[source]
Love the motivation! Reminds me of the first stuff I built back in my university days.

One thing from and old cranky dev that I notice: it would seem the yml you post has redundancies: either have 4 endpoints, no payload or 4 different payloads, one endpoint (the endpoint itself can tell you what you need to do) However, from the express script it looks like you arrived at this in the final solution anyway. Not sure if I missed something though, is there a reason the API needs such a shape? Cheers!

replies(1): >>41907958 #
amosesdev ◴[] No.41907958[source]
Hi! Author here. The yml is from a configuration in Home Assistant. Whenever it received an event from the sensors, it would fire the corresponding POST request (which you have to specify ahead of time, hence the configuration being a little redundant). The main reason for switching to the Express setup is that I was having a few random people look at the code & send their own requests to fudge what the status appeared as. I could have added some security/authentication to the endpoints, but I liked the idea of having the frontends simply querying the site (or my proxy) instead of having to cache a POST request.
replies(1): >>41910921 #
1. grahamj ◴[] No.41910921[source]
You can read and write HA entities via HTTP API so I think you could have done this with nothing but HA, but either way it's a fun project :)

One of my more fun HA project was scraping my snow removal service's tractor tracking API and passing the result for the closest tractor into HA so I can be notified (by voice with Alexa and/or push notification) when there's one nearby in case I need to move the car.

replies(1): >>41911531 #
2. amosesdev ◴[] No.41911531[source]
Do you mean outside of the API that I talk about in the article? If I exposed the HA API via the frontend, users would be able to just take the bearer token and do whatever they wanted with it (even deleting the entities used for the doors). That's why the express server is sitting in the middle to only expose the relevant information (proxying w/ the bearer token, which the end users have no access to)