Using an ECS as core component for a Smart Home System?

Hi, in my last post

I mentioned that I want to build a (simple) Smart Home System.

While a shower I had another idea: why not use an ECS as core component?

I see some similarities. Instead of game objects I have sensors and actors. But they have components, they create events and trigger some actions. I just don't render graphics to a screen.

Is this a stupid idea or could this work? I just have a general idea how an ECS works, but I never used one in a project.

Sounds totally unnecessary. Why not use regular structs to represent objects? Use the actor model to get things talking to each other if you like.

bevy_ecs is a separate crate and is really straightforward to use - doesn't include any rendering code.

However, @ZiCog raises a good point - the reason games use ECS is because it's a transformation of data composition (array of structs -> struct of arrays) that improves cache locality and thus performance when batch processing large number of components (100+ per type).

Given that you'll likely only have ~10 types of a single device in your home, ECS introduces a lot of complexity and offers very little in return.

A couple of structs, a trait and a loop in the main would suffice for your use case. If you have a device that would block the execution for a longer period of time you can use threads or an async runtime. I think the async route with structs implementing actor-like trait would be most ergonomic to use and you're unlikely to notice <200ms delay (which is probably an overestimate).

For fun, yes. And report to me how you go. Cause I am curious as well.

I know it is overkill, but maybe it has some advantages.

I will analyze the functionality I need in detail, because the event loop is the critical part, like in a game.

I want to be able to run this on limited hardware like a Raspberry Pi zero with minimal delay. That's why ECS came to mind.

I am using bevy_ecs for a 2d visualization project I am doing, with a custom renderer. A lot of bevy_* crates were quite handy.

It is still at early stages so hard to say where it is going to be a successful endeavor, but one aspect I quite like is how the system/plugin can be external and behaviours are just plug-and-play without having to deeply nest them in-between.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.