Doing something useful with a smart Monoprice power strip

A while back I obtained one a STITCH by Monoprice Wireless Smart Power Strip for my smart home endeavours. I’m an avid HomeAssistant user, and the expectations I had were to be able to connect it up to my HASS instance and control it from there. So imagine my surprise when I learned that tha Tuya-based Monoprice STITCH ecosystem is actually custom and closed off for integrators. They say that it only supports Google Assistant, Alexa, and their own App. I asked them in Twitter if they had plans to open it up – to no response.

I’m not having that. So I fixed it.

I recently discovered the wonders of ESPhome, and wondered if it would be possible to reflash the micro on this power strip so I can use my own LAN-based home automation system instead of Monoprice’s closed-off developer-unfriendly cloud. Turns out the power strip is running a basic EPS8266 board, and documented heavily on Tuya’s own website. The module in use is a TYWE3S, and is installed in a very inconvenient way.

TYWE3S module placement

I had to remove a capacitor in order to get a soldering iron in to temporarily solder some wires to the module to get it programmed with the initial ESPhome firmware. The pin-out of said module is shown below;

TYWE3S - Tasmota
TYWE3S module pinout

There are 5 connections necessary in order to complete this task;

  • VCC & GND – obviously
  • TXD0 – RX on your serial programmer
  • RXD0 – TX on your serial programmer
  • GPIO0 to GND to enable programming mode

The TXD0 and RXD0 pins are very close to a couple of capacitors on the power supply side. Maybe your soldering skills will be better than mine, but I had to remove one of them in order to get my soldering iron in close enough to tack on some wires. I eventually got the task done.

TYWE3S all wired up for programming

Now it’s programming time. Knowing that this module is a standard ESP8266 module, I added a basic device to ESPhome and flashed the firmware. First time flashed but didn’t connect, flashed a second time and the device came online. I suspect the failure was due to a bad solder joint/connection. It works though, that’s the main thing.

Now it’s configuration time. I’ll cut to the chase and provide the exact configuration for the power strip with full out-of-the-box functionality.

status_led:
  pin:
    number: GPIO0
    inverted: true

switch:
  - platform: gpio
    id: port1
    name: "Port 1"
    pin: GPIO4
    restore_mode: ALWAYS_ON
  
  - platform: gpio
    id: port2
    name: "Port 2"
    pin: GPIO13
    restore_mode: ALWAYS_ON
  
  - platform: gpio
    id: port3
    name: "Port 3"
    pin: GPIO12
    restore_mode: ALWAYS_ON
  
  - platform: gpio
    id: port4
    name: "Port 4"
    pin: GPIO14
    restore_mode: ALWAYS_ON

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
      mode: INPUT_PULLUP
    name: "Button"
    on_press:
      - switch.toggle: port1
      - switch.toggle: port2
      - switch.toggle: port3
      - switch.toggle: port4

  - platform: status
    name: "Device Status"

Add the config above to the base configuration that ESPhome creates for the device. The status LED is used for ESPhome’s standard status light. The button toggles all 4 relays (not just turning them on/off, but actually toggling them, which I don’t think is quite out-of-the-box functionality, but it works and I think that’d be kind cool). Port 1 through 4 is actually labelled from the inside, meaning that “Port 1” is the furthest away from the incoming power cord (far right, closest to the USB sockets).

Upload the config OTA and let the device reboot. Hopefully your power strip connects up to your WiFi and can be added to/controlled by HomeAssistant.

Happy flashing!

Triggering ECS RunTask from AWS CloudFormation

Inevitably there will come a time where you’re deploying an application on Amazon ECS and you’ll need to fire a single-run command on deployment. This could be something like a database migration or something else that sets up your environment post-deployment that can’t, or shouldn’t be run within your container’s startup sequence (by using entrypoints/bootstrap scripts). You’ll be using CloudFormation (as you should) and you’ll stumble across a bit of an issue..

Continue reading “Triggering ECS RunTask from AWS CloudFormation” »

Creating users in PostgreSQL

This one has thrown me one too many times, and short of a better place to note this sequence of commands down, I’m posting it here.

postgres=> CREATE USER new_user WITH PASSWORD 'SuperSecurePassword';
CREATE ROLE
postgres=> GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO new_user;
GRANT
postgres=> GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO new_user;
GRANT
postgres=> GRANT USAGE ON SCHEMA public TO new_user;
GRANT
postgres=> \q

Configuring pfSense to work with BT Infinity native IPv6

A quick post this one. I’ve been scouring the internet trying to find the right settings in order to connect up my pfSense to use BT Infinity’s native IPv6 implementation. Finally found the magic combination, which I’m sharing here for future reference, and hopefully help anyone else that might find this post.

Continue reading “Configuring pfSense to work with BT Infinity native IPv6” »

Sending Django’s WSGIRequest to a celery task

There may end up being an instance or 2 where you need access to the initial request object inside a celery task, for want of forming an absolute URL for an email template that you’re generating asynchronously, amongst many other reasons. However you’ll find that the WSGIRequest object can’t be pickled because of bound methods and lambda’s that exist on the object itself. So when you try to send the task, it’ll fall over raising an Exception stating that the WSGIRequest object can’t be pickled.

Continue reading “Sending Django’s WSGIRequest to a celery task” »

n/a