[New Add-on] Api Consumer

Hi fellow HA enthusiasts,

I’d like to share a small add-on I made, called API Consumer.

This add-on doesn’t do much on its own but is more of a reusable template that demonstrates how to consume any (web-)API with a custom Node.js script and post the data this API provides to the Home Assistant state machine using the internal Home Assistant API.

It’s useful when you’re trying to achieve something that hits the limits of the Home Assistant built in rest sensor platform or when an existing component/integration is not providing you all the data that you would like even though the underlying service is able to provide it. I’m for instance using it to:

  • expose some Grocy add-on api endpoints that aren’t yet available in the existing custom component
  • put iRail (Belgian train info) data in a sensor in a format I prefer to the existing component’s format
  • consume a calDav service that isn’t compatible with the built in calDav integration

Essentially the pattern used in this add-on is another way to write a custom component. I made it because I’m more comfortable writing JavaScript than Python and because I came to the conclusion that it’s better to stuff data in the state machine than making custom cards.

2 Likes

Maybe not a question about this Addon but I see you are using grocy. Can I create a chore thru api?

Yes, that should be possible. In Grocy, click the wrench menu icon and look for the api documentation link. That will open the Swagger api documentation. I see that the
POST /objects​/{entity} endpoint supports creating chores too.
For the data model of the chore object that you’ll need to post have a look at the chore endpoints further down in those docs.

I found out the API call, now I just need to format it right so I can run it with shell command.

In general if you want to work with or learn working with api’s it’s a good idea to download Postman and familiarize yourself with it. Whenever you have a functioning api-call in Postman it can then generate code snippets like a curl command you can just copy paste to use as shell command.