#local_push updates
1 messages · Page 1 of 1 (latest)
I'm trying to do the same thing - did you end up figuring it out? been trying to juggle various solutions like coordinators (per the docs), trying to figure out where to initialize the library for talking to the hardware, and making sure i know how to tell HA that there is new data.
i found the alarmdecoder integration had a simple sensor that seems to be configured for local push (based on searching the manifests), but im not quite sure where its its getting data from
So yeah Idid end up getting started on this. It was a while back so I don't remember what integrations I used as an example.
One realization I had though was that you're still probably going to want a polling implementation even if you're planning on implementing push. The reason for this is that it's entirely possible that you will miss a push event either because HA is down, internet is down, or really just any kind of connectivity problem between the "pusher" and receiver. The only difference is how often you'll be polling and you should probably poll much less often in a push implementation.
That said, let me take a look real quick at my push implementation
Ok so this may vary between push implementations, but you'll want to look into webhooks
webhook_id = webhook.async_generate_id()
webhook_callback_url = webhook.async_generate_url(hass, webhook_id)
await hass.async_add_executor_job(create_webhooks, webhook_callback_url)
webhook.async_register(
hass, DOMAIN, "Whatever", webhook_id, async_handle_webhook
)
I do this on entry setup
You generate a callback URL to pass along to whatever is going to be doing the pushing
create_webhooks here is just a util method I made to call the 3rd party to registere the webhook
async_handle_webhook is the handler for that webhook
I believe there are some decent HA docs about webhooks
But yeah basically:
- Generate webhook
- Tell 3rd party about webhook
- Register handler function using that webhook's id
I didn't get any futher than past this proof of concept, but from there it was just a matter of following through with my full implementation
How did you arrive at the conclusion of webhooks?
my usecase is essentially: i noticed my thermostat has an open port that occasionally sends data whenever the compressor speed changes, i made a Python library to interpret and read that data, now i just wanna make a custom HA integration to wire that into HA.
Well I'm not sure what other way there would be. Push requires the "pusher" to know where to push to. That's basically what a webhook is
When you say sends data, sends data how exactly?
How and where?
You can just use a plain Python callback. An example would be the knx integration.
Like it just emits bytes over the network to anyone connected to that port
Is it like a websocket connection?
Sorry, maybe this is a gap in my knowledge, but I'm not aware of a way to connect to a socket remotely?
Ok, interesting
This is all on LAN, not over the internet, i can connect and read the data and stuff with python
Could you point me to your lib?
Lantrane is the name on pypi
im mostly just lost trying to figure out the correct way to send this data to homeassistant when a new datapoint comes in
The manufacturer of this thermostat seems pretty allergic to integration with FOSS stuff
Ill check it out, thanks!
Yeah looks like you'd want to update your lib so that when it gets data, it would call some callback
So your lib would require you being able to register some callback with it
But yeah, I don't have experience just registering a raw callback in HA, so you'd have to poke around the docs for that
Ah ok, thanks!
I do still think you'd want to have polling here, right?
Like what if HA isn't connected when there's data published on that socket?
If you can not only receive, but actively read the datapoints, that's no problem. Or if they are sent frequently enough... you can just postpone entity init then.
The frequency is pretty variable, it only sends data when it changes, so if the AC is off it wont send anything
Im not too worried about missing some data, just want to start collecting it over time to get pretty graphs in HA
it looks to me like the sensor.py in this integration is doing polling (line 173 is calling this from their API lib. https://github.com/XKNX/xknx/blob/b3960de2abbb811b7a605f4bf1d6b7b4e3e2263b/docs/sensor.md?plain=1#L40)
am i misunderstanding how knx works?
This just returns the decoded value https://github.com/XKNX/xknx/blob/b3960de2abbb811b7a605f4bf1d6b7b4e3e2263b/xknx/devices/sensor.py#L97 you may just as well use an attribute or property... or pass it via your callback