NixOS Home Automation | 514 Members | |
| Declarative Home Automation and other Sidequests | https://wiki.nixos.org/wiki/Home_Assistant | 129 Servers |
| Sender | Message | Time |
|---|---|---|
| 19 Jun 2021 | ||
| automation engine = event bus? | 13:27:52 | |
In reply to @hexa:lossy.networkKinda, I guess. I think that's where existing solutions could maybe be improved. The more devices you have in your home that report data, the less feasible it is for every automation you wanna script to listen to all events, which are mostly state changes. So if I were to design such a system, I would take good care to have every automation define the events or data points it cares about. Let's say some heating automation cares about outside temperature (now and prediction for 1h, 2h, ... from now), inside temperature, people present, ... Then that automation should only be triggered when one of these states changes. | 13:34:25 | |
| right, I think at the core there needs to be an event bus, maybe something pub/sub, and everything that hooks into it needs to follow a certain interface, so there is a generic way to talk to certain device classes | 13:34:26 | |
| And also, I think defining automations could benefit from pure functional programming to avoid recomputing stuff if the changed states don't make a difference in some interim step in the computation, so some type of memoization. | 13:36:00 | |
| To sum it up, everything should be very declarative and functional :) | 13:37:16 | |
| * And also, I think defining automations could benefit from functional programming to avoid recomputing stuff if the changed states don't make a difference in some interim step in the computation, so some type of memoization. | 13:47:27 | |
| Just to clear something up - what I listed as "MVP non-features" means I won't be doing those as part of the MVP - I definitely think they add value. My end goal is for this project to be installable by an end user (though of course a NixOS end user is certainly more likely to be technically minded) and provide all that the user needs to automate IoT devices in their home, though different devices will need specific plugins. So the first thing to build, because everything else depends on it is what I called the "service" - this is the backend that actually communicates with the devices (targets) on one end, and a HTTP request on the other end. Then, once this service is working, a web interface, or app interface could be built to present things in a more friendly manner. So in the end the scope is quite large, much like HA, however for the "MVP" I just want to work on the service. By the nature of IoT, different plugins that support different targets will require different protocols - HTTP, RTSP, MQTT, etc, so we can't really choose just one. Given MQTT supports many devices, and I have used it a little in the past, it seems like a logical place to start. So the "core" would be the service, but more is definitely required for a complete solution. Though, it would be nice if someone could just install the core, and build their own frontend if desired. Regarding architecture, specifically how people have mentioned event buses, pub/sub, I suspect that pub/sub would be an ideal candidate, though am very open to all suggestions! I think pub/sub is the simplest way to describe what happens - events happen, a camera seeing motion, a light turning on, or losing connection, an IRC message mentioning the user, etc. So various pub/sub messages would be published, and some kind of logic engine in the service would subscribe to some of them, possibly generating "actions" in response, depending on the users configuration. So we could avoid the situation where an "automation" would have to process irrelevant events. This is one thing that I think redux-observable presents a really nice development experience for, which is why I have been describing "actions", which is the term they use. Finally, regarding functional programming, I agree there are potential performance gains to be had via memoization, though I suspect that would only surface for large scale systems (say, more than 30 messages per second). I'm a big fan of measuring before optimizing, so while I think we should keep memoization in mind and build a system that would be easy to memoize, we shouldn't memoize things until we actually have performance issues. With an event system such as pub/sub, it is not difficult to create crude approximations of that kind of heavy load, that will be a fun exercise :) I was tempted to write this in Haskell, but I've never worked with high performance Haskell before, and suspect Rust will be more approachable for more people to contribute. Does anyone have any comments on language choice? | 14:02:16 | |
| Rust is probably better for a project that might eventually rely on a bigger dev group to contribute 🙂 I know neither well enough (did more in haskell than in rust), but I'd be willing to do more/anything with both | 14:06:38 | |
| I suppose considering a web and app client are desirable we will end up having multiple languages and able to take contributions from many more. For the web interface, there might be a chance to use Elm, which isn't Haskell but is functional and may lend itself to staying in the functional paradigm as much as possible. | 14:09:21 | |
| I'd prefer to not use Elm for the frontend, but that's highly opinionated. Purescript might be the better alternative | 14:10:15 | |
| I've been doing some research regarding rust on mobile (iOS and Android) and apparently it is quite simple to setup a toolchain where you use rust for core functions (in our case checking configurations) and the only platform specific code is for the UI, and even then something like Flutter can be used to have the same codebase for both. | 14:11:05 | |
In reply to @schnecfk:ruhr-uni-bochum.deI've never used it, just saw the documentation and thought it looked decent. I don't have any opinion here, my frontend is limited to JS/TS, Angular/React. | 14:11:51 | |
| That's more frontend that I've done, but there was some problem where the maintainers of the elm project basically crippled the functionality of all libraries that relied on non-elm (js) bindings - except their (afaik optional) libraries. I'll try to find that blogpost again, but the general vibe I got in the armbee reminded me somewhat of that problem | 14:14:51 | |
| This covers some of the problems that I've read about elm: https://lukeplant.me.uk/blog/posts/why-im-leaving-elm/ | 14:15:52 | |
| But it's getting slightly off track here - we're far from doing anything frontend, I think. And the frontend is something that'll be probably relatively easy to swap out | 14:16:26 | |
| Thanks for the link, I'll read that :) Agreed, we are a long way off frontend, and I actually want a goal to be that the frontend is optional, and new frontends are easy to build. As long as we follow a sensible architecture for our API (whether REST or something else) then we might just get this for free :) | 14:19:39 | |
| Yes, "API first" sounds good to me 😀 | 14:20:56 | |
In reply to @instantepiphany:matrix.orgI would kind of love this to be Haskell, but core in Rust sounds reasonable. And if you use something like wasm+wasmer for "plugins", they could be built in almost any language! | 14:58:52 | |
| 17:25:52 | ||
| 17:25:59 | ||
| instantepiphany: If you want to move the discussion to a new matrix room, feel free to invite me 🙂 (Although it's likely that it will fit into this channel for some time, given that it does not seem that high traffic) | 18:13:32 | |
| yes, the traffic sounds ok, we are probably all interested parties | 18:52:25 | |
| 20 Jun 2021 | ||
| Hmm, I like the ideas here, just want to pitch in another name idea: homeix :) I'm also very interested in zwave (both lights and temperature sensor), a bit less in zigbee (I have a Hue strip but don't use the gateway), then xiaomi (robot vacuum), kodi and chromecast things | 02:51:59 | |
| I'll create a github repository soon where we can add issues as requests for support for various targets. Just to set expectations, I expect the MVP to take 2-4 weeks, and the soonest we will have a plug and play solution for just one target is likely to be 2 months. This is my only side project but I'm working full time and starting a new job in a couple weeks. | 02:55:29 | |
| My rust knowledge is limited to going through the learning rust book one and a half year ago and not touching it since. But I liked what I did back then and wouldn't mind learning more by actually doing some rust. Currently I'm a bit consumed by family though. I have a 3 weeks old human next to me :) | 02:59:57 | |
| Well, if I do a good job architecting the service and plugin architecture, you would have some examples in rust and maybe other languages to work from - in a couple months. I can't speak to the time requirements of the young human though - an essential and time consuming task on their own ❤️ | 03:03:06 | |
In reply to @instantepiphany:matrix.orgpalo also build a smarter mqtt light control with rust: https://git.ingolf-wagner.de/palo/light-control as he was not happy with home-assistant state machine | 06:09:15 | |
| RE language choices | 09:17:29 | |
| Both Rust and Haskell are great languages and have a powerful type system. Haskell is rather performant as well, though I don't think an application like this will be really performance critical. I don't know the Haskell ecosystem w.r.t. bindings and integrations libraries, but I suppose the Rust community is larger at the moment. | 09:19:35 | |
| Either way, we also need to talk about scripting. The project will need a scripting language, whatever it may be. There are a few custom languages for this purpose, but there is also Python that works great together with Rust. I have no idea how scripting looks like in the Haskell ecosystem (I think Haskell can be interpreted too?) | 09:23:18 | |