andarotajo
How do I build a WebSocket client library?
Hello, I’m very new to Elixir and looking to get started on a little project I’m interested in. Inspired by this blog post I’d like to build a “simple” client library giving users a simpler way to use Home Assistant’s WebSocket API.
I think a library like this give users the most flexibility in how they write automations and keeps the project scope limited for my own sanity ![]()
But since Elixir and writing libraries in general are very new to me, I’d love to get some pointers on how to go about that. Things I’ve been wondering:
- I thought about building the library around callbacks, e.g. a callback for Home Assistant’s state changes, allowing the user to pattern match what they need. How do I build a WebSocket client around this concept
- Is using a GenServer the way to go? I’d need to keep a state
- Besides the URL there’s also a token I’d need to connect to Home Assistant. Is there a “best practice” on how to configure stuff like this?
Some good libraries I can use as guidance for code quality and stuff would probably help if you’ve got some suggestions.
For reference, this is Home Assistant’s WebSocket API
Thank you very much for helping!
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 4 of 4 Posts
jstimps
I like to use gun for client-side ws work. A while ago I wrote a little Livebook example to remind my future self of the function calls involved.
bbangert
I recently extracted a websocket lib for HA that I published on hex: Hassock — hassock v0.1.3
This uses the newer HA command that uses diff’s for efficiency with an optional ETS cache for faster queries without sending everything over the websocket connection.
andarotajo
Thanks for the heads up! To be honest I didn’t touch Elixir much after experimenting around a bit but this project is still on my list for when I finally learn Elixir.
Looks great on first glance. Have you tried writing an automation with it or plan to?
bbangert
Currently I use this library on a bit of a test project to control a LoupeDeck Live device ( GitHub - bbangert/loupey: Elixir library for Loupedeck devices · GitHub ). I’ll eventually bake this into a Nerves project and add Elgato StreamDeck support, so that its easy to have stand-alone physical Home Assistant controls and displays with a bit more powerful software backing it than what ESPHome can do.
My Loupedeck mainly acts as a display and control for HA, so I can turn the volume knob to change the volume of my audio deck, tap a touch slider to change the light levels that HA controls via Phillips Hue, and I have some buttons that just display sensor states.