Wjtje's Blog

I like having physical switches and buttons to control lights inside a home, because they are faster, more reliable, and easier to use than other “modern” ways to control “smart” lights.

  • Mobile app: You need to take out your phone, open the app, than find the lights you want to control.
  • Wireless remote: Way faster to use than a phone, but batteries will run out and the remote can become lost. (Good luck finding it then)
  • Voice: I don't like shouting into a machine and hoping it will turn on the lights.

But sometimes I wish a good old light switch could do a bit more, like triggering automation's inside Home Assistant to quickly turn off all the lights.

Using a Smart Switch

WARNING: Installing these kind of devices requires you to work with mains voltage, which can be dangerous if you don't know what you're doing.

An image of two smart switches next to each other, the left one in a Shelly I4, and the right one is a Sonoff MINI R2

These smart switches ticked all the boxes I was looking for:

  • Local control (The Sonoff was flashed with ESPHome)
  • Allows using the existing switches
  • Low power usage
  • Able to directly connect with Home Assistant.

Sonoff

The Sonoff come by default with terrible firmware, it lost connection, didn't work well with Home Assistant, didn't allow for a lot of customization. But the device is quick to open and uses an ESP8285. So I quickly created an ESPHome firmware for the device. Which can be found here. This solved all of my issues I had with the device, I have multiple of these devices deployed for over two year and never had any problem with them.

Shelly

A few months ago I found out that a hardware store nearby was selling Shelly devices, after looking at the features set of the device I was interested. Shelly devices allows the user to write scripts on them to alter the function of the device.

One API call caught my interest Shelly.emitEvent(). By the sound of it, it allows the script to send events to other clients that are connected to the device. But after some testing I couldn't get the events to show up inside Home Assistant, so I created a pull request home-assistant/core#135979 which adds event entities for each script the user creates.

After that I could finally re-implement the functionality I had created for the Sonoff inside of a Shelly script. Which can be found here.

What do I use this for

With both the ESPHome firmware and Shelly script, it allows you to add an automation that gets triggered when a switch is quickly turned on and than off (within 250ms). I've personally use it for the following stuff:

  • Turn off all the lights on a specific floor.
  • Turn off the lights 10 minutes after the last personal leaves.
  • Allows you to control the fan inside the room.

Which device is Better

Both devices work absolutely fine, and both have the advantages and disadvantages.

Sonoff:

  • + It's a bit cheaper to buy
  • - In some sockets it's quite difficult to install the device due to it's size

Shelly:

  • + It doesn't need to be physically opened up
  • + It a bit smaller than a Sonoff, so easier to install

Running Folding@Home can be a geat way to help scientists around the world. The program can use spear CPU and GPU power to do scientific research. When I switched to NixOS it took some tinkering to get OpenCL working on my AND GPU so Folding@Home can use it in the background while my CPU is busy comping code and doing other stuff.

Installing ROCM and Folding@Home

The can be easly done by adding the folling values to your configuration.nix file and rebooting.

hardware.graphics = {
  enable = true;
  enable32Bit = lib.mkForce false;
  extraPackages = with pkgs; [
    rocmPackages.clr.icd
    rocmPackages.clr
    rocmPackages.rocminfo
    rocmPackages.rocm-runtime
  ];
};

systemd.tmpfiles.rules = [
  "L+    /opt/rocm/hip   -    -    -     -    ${pkgs.rocmPackages.clr}"
];

environment.systemPackages = with pkgs; [
  fahclient
];

If you now try to run the fah-client and go to https://beta.foldingathome.org/ you can start folding on your CPU, but your GPU isn't showing up.

Running fah-client

If you start fah-client from the command line with the following command, it can find the OpenCL binaries and use them.

OCL_ICD_VENDORS=$(nix-build '<nixpkgs>' --no-out-link -A rocmPackages.clr.icd)/etc/OpenCL/vendors/ fah-client

If you go to the setting of your machine, there you can enable your GPU and start using it for scientific research.

A partial screenshot of folding at home where you can enable your GPU