TheSpaghettiDetective / obico-server

Obico is a community-built, open-source smart 3D printing platform used by makers, enthusiasts, and tinkerers around the world.
https://obico.io
GNU Affero General Public License v3.0
1.47k stars 297 forks source link

[Feature] Running Obico server as a Home Assistant add-on #759

Open iamkarlson opened 1 year ago

iamkarlson commented 1 year ago

Is your feature request related to a problem? Please describe. Home Assistant is a powerful platform to integrate all sorts of hardware and software at once. Many people use it to run auxiliary software such as DNS servers, or grocery shopping lists. Since the format of the addon is very well-defined and based on docker images, it would be nice if you can distribute one.

Describe the solution you'd like Obico-supported HA addon

Describe alternatives you've considered Creating my own hacked addon.

Additional context https://developers.home-assistant.io/docs/add-ons

MallocArray commented 1 year ago

The obico-server isn't supported on Raspberry Pi hardware, as it needs more resources than a Pi can offer for doing the detection, and many HomeAssistant installs are done on a Pi.

The obico plugins for Octoprint or Moonraker/Klipper run on whatever device you are running those on typically and wouldn't be applicable to HA as far as I can tell.

nobodyguy commented 1 year ago

A lot of people run HA on x86 hardware like Intel NUC or older server/thin client PC.

However, by briefly looking into the dependencies I can see it wouldn't be as easy as wrapping the obico-server docker image in HA addon. Obico-server contains ml_api, web and redis services. These need to be either merged into a single Docker container or wrapped in an HA addon per every service (and there is no dependency management between HA addons). Both solutions are hacky and would require some effort. I can try the first solution, some work has been done here - https://github.com/fredrikbaberg/hassio-addons/blob/master/tsd/Dockerfile but I can't promise anything.

nobodyguy commented 1 year ago

So by looking more into it, I will go with the cleanest way - HA addon with REST ML API and HA integration implementing camera feed scanning service and providing camera entity with detected failures and maybe some additional sensors with info about detected failures. This way you can create your own HA automation like calling failure scanning service only when your printer is actually printing (info from PrusaLink or Octoprint integration) and sending standard HA notifications in case of detected failure.

ForceConstant commented 7 months ago

Any updates on this? I would like this as an option.

kennethjiang commented 7 months ago

We haven't been able to get around to it. Hope someone in the community can pitch in to implement it using our API, or even send a PR to our main repo.

ForceConstant commented 6 months ago

@kennethjiang Ok assuming one has a self-hosted obico server already running. Can someone give me the high level primer on which API's would be used to send data to obico? As a start, I would assume you would create a dummy printer in obico web-app, and then HASS-plugin would send print/image data periodically, and also receive data.

The API's listed at https://www.obico.io/docs/api/ seem to only be a way to receive data from obico and not send data.

kennethjiang commented 6 months ago

@ForceConstant Our API follows the RESTful convention. We don't allow printer creation using APIs for security reason. But other mutating operations are supported.

ForceConstant commented 6 months ago

@kennethjiang can you specifically tell me how to tell obico server there is a new image url to process?

ForceConstant commented 6 months ago

@kennethjiang So looking more at this, it seems that this addon would be in the same mold as the current octoprint/klipper addons. Which seem to all talk to obico-server using undocumented API's. Such as '/api/v1/octo/pic/', etc. Or do I have that wrong?

kennethjiang commented 6 months ago

@kennethjiang So looking more at this, it seems that this addon would be in the same mold as the current octoprint/klipper addons. Which seem to all talk to obico-server using undocumented API's. Such as '/api/v1/octo/pic/', etc. Or do I have that wrong?

Ah yes we haven't got a chance to document the agent side's of the APIs. You will need to reverse-engine them but hopefuly they are not difficult to understand.

tannisroot commented 5 months ago

A lot of people run HA on x86 hardware like Intel NUC or older server/thin client PC.

However, by briefly looking into the dependencies I can see it wouldn't be as easy as wrapping the obico-server docker image in HA addon. Obico-server contains ml_api, web and redis services. These need to be either merged into a single Docker container or wrapped in an HA addon per every service (and there is no dependency management between HA addons). Both solutions are hacky and would require some effort. I can try the first solution, some work has been done here - https://github.com/fredrikbaberg/hassio-addons/blob/master/tsd/Dockerfile but I can't promise anything.

That sounds like something suitable for Kubernetes

nobodyguy commented 3 weeks ago

So by looking more into it, I will go with the cleanest way - HA addon with REST ML API and HA integration implementing camera feed scanning service and providing camera entity with detected failures and maybe some additional sensors with info about detected failures. This way you can create your own HA automation like calling failure scanning service only when your printer is actually printing (info from PrusaLink or Octoprint integration) and sending standard HA notifications in case of detected failure.

Got some initial work done image

kennethjiang commented 3 weeks ago

So by looking more into it, I will go with the cleanest way - HA addon with REST ML API and HA integration implementing camera feed scanning service and providing camera entity with detected failures and maybe some additional sensors with info about detected failures. This way you can create your own HA automation like calling failure scanning service only when your printer is actually printing (info from PrusaLink or Octoprint integration) and sending standard HA notifications in case of detected failure.

Got some initial work done image

So cool. Is your code available on github? If so, can you post the link here so that other community members can use it too?

nobodyguy commented 3 weeks ago

So cool. Is your code available on github? If so, can you post the link here so that other community members can use it too?

Not yet, I'll publish a basic integration within a few days (right now it's just a PoC with a lot of hardcoded stuff that works only in my setup), but the HA addon would require a lot more work since HA addons are Docker images based on the specific base layer with S6 process supervisor and other additional stuff. But you can run it either on the different HW as a regular Docker container or on the same HW, but with some limitations.

ForceConstant commented 3 weeks ago

So cool. Is your code available on github? If so, can you post the link here so that other community members can use it too?

HA addon would require a lot more work since HA addons are Docker images based on the specific base layer with S6 process supervisor and other additional stuff.

Can you explain what this means? There are plenty of integrations in the main HA branch, but also stuff in HACS https://hacs.xyz/ , and I don't think any of them require docker at all. What do you mean? I understand for Obico we would most likely need to run obico server separately from HA, but the integration itself would not need to be a container.

nobodyguy commented 3 weeks ago

Can you explain what this means? There are plenty of integrations in the main HA branch, but also stuff in HACS https://hacs.xyz/ , and I don't think any of them require docker at all. What do you mean? I understand for Obico we would most likely need to run obico server separately from HA, but the integration itself would not need to be a container.

HA integration = Python code that implements HA entities and handles communication with Obico ML REST API. This is not a part of the Docker container.

HA addon = Basically a Docker container. In this context it's a Docker container with Obico ML REST API server. Based on the official stats, majority of HA instances are running HA OS (complete configured and restricted system), so you can't run regular Docker containers there and you have to convert them into HA addons.

nobodyguy commented 3 weeks ago

So PoC of the addon is here: https://github.com/nobodyguy/obico_ml_ha_addon

Some minor things and HA integration should be published over the weekend.

nobodyguy commented 1 week ago

So the integration is here - https://github.com/nobodyguy/obico_ml_ha_integration Currently it doesn't support the vanilla ML REST API server (I removed the token auth and added another URL endpoint to speed up the PoC development), so use it with the mentioned HA Addon. Basic notifications with the printing failures are working as expected. Feel free to discuss any features or fixes there.