Flash Generic $2 Smart Plug

I’ve been on the hunt for some additonal smart plugs, and recently I’ve been seeing some extremely cheap ones from AliExpress for $2, so I bought one to see if it’s able to be reflashed with ESPHome or OpenBeken. Following the instructions in the box I’m directed to download the eWelink app, which I’m not interested in using, but I will use only briefly to ensure the device is working before I flash it.

Read More

Low-voltage power monitoring with EasyPower

When working with battery powered devices, knowing how much power they consume will tell you how long they will last on a charge or a fresh battery. This is imporant to know when replacing the stock firmware with ESPHome or Tasmota, which can drastically change the power consumption of the device. Many battery-powered IOT devices spend the majority of their time in a deep sleep state, and only wake up briefly to perform a task, then go back to sleep. This is great for battery life, but makes it difficult to measure the power consumption of the device over time. The INA219 is a great little chip that can measure both voltage and current, and when paired with a microcontroller, can be used to measure the power consumption of a device. This post will cover how to use the INA219 with ESPHome to monitor the power consumption of a device.

Read More

Flash Tuya Mini Smart Switch with ESPHome

Continuing the Tuya device hacking series, this post describes how to flash the Tuya Mini Smart Switch with ESPHome firmware. I picked up a few of these switches on sale for only a few dollars each, found that each of them are slightly different internally, despite looking almost exactly the same on the outside. This post covers the first of the three different versions I have, but I’m sure there are more out there.

Read More

Almost bricking BK7231N modules

So, I was given bad/outdated advice and I was spreading it to future me and anyone else that stumbles across these blog posts. I’m use to dealing with Amtel and ESP microcontrollers, and familiar with the tools needed for them. When I started working with the BK7231N, I had read that the hid_download_py tool was the only reliable way to flash the BK7231N in MacOS from the terminal. I was able to successfully make use of this tool to flash the OpenBeken firmware, however when I tried to flash ESPHome or esphome-kickstart, not only was I unable to get it to burn without failing CRC check, the module would no longer boot unless I flashed the OpenBeken firmware again.

I had gone on the hunt for better tooling, and found a few new options:

Read More

Flash Tuya CB3S Switches with OpenBeken

I recently picked up a couple of no-name WiFi switch from AliExpress, they are sold under a variety of names, but the ones that look like mine all use the Tuya app. I was hoping to flash it with ESPHome, but unfortunately, it doesn’t contain an ESP8266 module, instaed using a Tuya CB3S module, which is not supported by ESPHome. These switches had been using ESP-12F modules for some time, but have since transitioned to CB3S. Fortunately, I was able to find a project called OpenBeken, which is a custom firmware for the Tuya CB3S module. It’s more basic than ESPHome, but it did actually do what it said it would, with very little effort.

Read More

Flash Etekcity Plugs (ESW01) with ESPHome

I’ve been slowly amassing a collection of various smart plugs and switches around my house for the purpose of setting up a home automation system. I picked up a single Etekcity ESW01 plug to test out, and was pleasantly surprised to find that it was based on the ESP8266, a very popular and well supported microcontroller. I hadn’t played with home automation in a while, and was excited to see how far it had come. Where previously, I would have had to roll my own firmware, and then write my own integration for Home Assistant, I found that there is now a project called ESPHome which allows you to easily flash ESP8266 and ESP32 devices with a custom firmware, and then integrate them into Home Assistant.

Read More

DIY Espresso Distribution Tool

I had been wondering why my home espresso machine pucks would sometimes turn out dry and sometimes turn out looking like mud. After several YouTube videos later, I’m now convinced that my grounds lack equal distribution prior to tamping, as my current process involves scooping in a dome of grounds and pressing it down. This causes a dense part in the middle (top of the dome), and loose grounds around the edge. The YouTube experts recommend distribution, either by practiced hand methods, or by using a tool, of which there are several to choose from. I liked the “Weiss Distribution Method” or “wire-stir” method, as it seemed straightforward and didn’t require a $30 precision made tool. I found several on Amazon, but I’m feeling equally lazy as I am impatient, so rather than spend $10 and wait two days, I’m going to make my own with items I already have.

Read More

Redis Lua benchmark and overhead

I’ve been wanting to make use of Redis Lua scripting for a long time for some projects at work. I’ve read Redis Lua scripting, and found that I can use it to solve a few common issues we’ve been dealing with, one being ensuring redis hashes have an expiry. We have a lot of services at my job which use Redis as a centralized state database, allowing services to share knowledge in a common place, without having to know if or what else may need the data. All information written to this DB requires an expiry value to be assigned. In our old data model, we had done this by using the SETEX [key] [ttl] [value] or SET [key] [value] EX [ttl] commands. This is great, as we can set the key and the expiry at the same time atomically and ensure that every key will expire. In our new data model, we are switching from keys to hashes, but unfortunately, there is not an HSETEX command built in. Instead, we have to rely on pairing HSET and EXPIRE commands manually, which of course doubles the “ops” per item being set, but also ads the possibility of something breaking and a hash lacking expiry.

I found Redis Lua scripting to be a big help here to ensure that every hash gets an expiry set while setting fields/values on the hash. I also added logic to conditionally skip setting EXPIRE. The response of HSET will tell us how many new fields have been created, which would only be 0 if the hash already existed and already had an expiry.

-- Set EXPIRE on hash after HSET if new fields added
-- OPs: usually 2, occasionally 1 (when hash and fields are reused)
local expire = table.remove(ARGV, 1)
local newCount = redis.call("HSET", KEYS[1], unpack(ARGV))
if tonumber(newCount) > 0 then
redis.call("EXPIRE", KEYS[1], expire)
return newCount

So, all of this sounds great, I can just make use of Lua scripts for anything that needs to do multiple actions, saving my code round trips to the DB. Obvious win, right? I wasn’t totally sure. When searching for Redis Lua performance, I kept finding articles where someone was mis-using Redis Lua, calling EVAL every time they want to call Redis Lua, or generating dynamically generated Lua script, both of which are entirely incorrect uses of Redis Lua.

I wanted to know was what is the actual cost was to use a Lua script compared to standard Redis commands? Literally, apples-to-(lua-scripted)-apples.

Read More

Peak Design Lens Kit RF mod

I recently purchased some used camera gear, and one of the included items was a “Lens Kit“ by Peak Design, which helps you carry up to two lenses using a strap or on the Peak Design Capture. I always find myself fumbling with a second lens when out, so this seemed like a useful addition to my kit. While I was lucky enough to receive the Canon EF/EF-S version, I have recently switched over to using a Canon EOS R, which uses the new RF mount, which is incompatible with EF.

I had previously noted that the EF and the RF mounts were very similar in dimensions, but not compatible by design. As the Lens Kit doesn’t have any electrical or optical reasons why it can’t work, I wondered if it could be slightly modified to accept EF and RF.

Read More