Minimal custom push-based sensor

I have a raspberry pi zero connected to an ultrasonic proximity sensor. I’d like to get this data into home assistant, but I’m getting lost in the docs and forums. So far I have a new sensor with a static value because I copied the code from example-custom-config/custom_components/example_sensor · GitHub. I was thinking it would be simple to program the pi to periodically send a POST via curl to update the value, but I can’t figure out how to authenticate, or what I’d change the update() method to. I also can’t figure out how/where to set Entity.should_poll as mentioned in Fetching Data | Home Assistant Developer Docs.

It’s been pretty rough trying to get do custom things with Home Assistant in general, but especially with this attempt at a custom sensor. I feel like I’m missing something vital yet obvious, like when you’re poring over source code trying to make sense of it without realizing there’s a README.I went for a while down the scaffolded integration, but it just feels like there’s way too much there that isn’t relevant. Am I even going about this the right way? Somebody point me in the right direction

I don’t think that you need a custom component for your task. You could look into these 3 methods for a starting point:

If you go one step back, maybe you also could replace the Pi Zero by an ESP2866 or ESP32 and use esphome. These devices are integrated “directly” into HA.

May I suggest “Reading the documentation rather than taking some code and hope it will be self-explanatory” ? :wink:

Thanks, I still feel like REST is the best way to go here. Setting up MQTT feels like a lot of overhead just for one sensor with one reading. Same with webhooks and automations. I tried again today and the long-lived token worked, maybe it was just a copy/paste error.
I’ll definitely look into the ESPHome stuff, it looks like a much more supported path.

@koying
I have gone through hours and hours of docs (notice how I linked to docs I’d been reading in my original post, and how I mentioned I’m getting lost in them?), the “Reading the documentation” suggestion was particularly unhelpful… I hope it was just a joke, even if a bad one

Not a joke. You seem so lost that I assumed you didn’t read it.

If you really want to follow the custom component route, I’d suggest to look at actual code of existing integrations.

That’s how I got most of the knowledge I have on the topic, not really in the doc which doesn’t go beyond the most basic concepts, actually.

That’s also the way I would use in your case.