Smart Refresh Schedule for Sensors in Home Assistant

Polling a sensor at a fixed interval — say, every 5 minutes — is simple to set up. But in practice, it can be wasteful or inadequate: polling too often wastes bandwidth and may hit rate limits, while polling too slowly can leave your data stale when you need it most. Ideally, we’d poll frequently when someone might be watching, and rarely (or not at all) when the house is asleep or empty. That means dynamic polling based on context. ...

May 9, 2025 · 4 min · Michael Bisbjerg

Using dmsetup to Salvage Disks with Bad Blocks

Introduction I have a disk with bad blocks. The filesystem I’m using (such as ZFS) doesn’t support marking bad blocks like ext did, and completely replacing the disk is costly and unnecessary. Instead, I’ve used dmsetup to create a virtual disk that excludes the bad sectors, allowing the filesystem to work with the remaining good areas. This guide covers the process of scanning the disk, preparing a custom partition, setting up dmsetup, and ensuring everything works across reboots. I’ve additionally included steps to ensure that the dmsetup configuration follows the disk, ensuring you don’t loose that critical piece of information. ...

April 7, 2025 · 9 min · Michael Bisbjerg

WLED Backup script

ℹ️ Info: This post was linked in the WLED discussions and the script may make it to the WLED project. Introduction WLED is a powerful open-source solution for controlling addressable LEDs over Wi-Fi, making it popular for DIY smart lighting projects. However, maintaining backups of your WLED configurations can be tedious, especially when managing multiple devices. In this post, I’ll demonstrate a simple bash-based backup solution that discovers WLED devices on your network, pulls their configurations, and saves them locally for easy restoration. The scripts are intended for Linux-based systems and can be scheduled with cron for fully automated backups. ...

March 28, 2025 · 4 min · Michael Bisbjerg

Entity Framework Core: Querying views, but manipulating tables

I had a use case for EF Core where I wanted to query a database view while still supporting classic add/update/delete methods on the base table. Specifically, I wanted to enrich entities with computed values, like a lookup or label, but allow full CRUD support. Example Problem Suppose we have two entities: Entity: (Id, DeviceId) Friendly: (DeviceId, FriendlyName) The goal is to filter Entity records by FriendlyName, even though it’s not part of the table directly. ...

June 8, 2023 · 2 min · Michael Bisbjerg

EntityFramework Core – Composite key filtering

In EF Core, you can easily filter to a list of known values using LINQ: int[] ids = { 1, 3, 7 }; myContext.Posts.Where(s => ids.Contains(s.Id)); But what if the list of values includes composite keys, like Type and Name? var filterBy = new[] { (PostTypes.Blog, "First"), (PostTypes.KnowledgeBase, "Last") }; myContext.Posts.Where(s => filterBy.Contains((s.Type, s.Name))); // But how? There’s no direct Contains() support for tuples or composite keys in EF Core. A Stack Overflow post outlines several options. Here, I’ll focus on Option 6 — building an expression tree to generate a SQL query like: ...

June 3, 2021 · 2 min · Michael Bisbjerg