Sequr's Avatar

Sequr

@sequr.be.web.brid.gy

Writeups and random stuff about infosec and life

1
Followers
0
Following
75
Posts
01.01.0001
Joined
Posts Following

Latest posts by Sequr @sequr.be.web.brid.gy

Preview
Automatically generate cover for blog post # Intro A cover image is a nice way to draw attention to your blog post when sharing a link via social media. However, coming up with and designing a catching cover image can be difficult. It can also distract from the actual content creation. That’s why I was looking for – and found – a way to automatically generate cover images for blog posts. These covers contain some basic information for the blog post and displays it in a nice and concise way. Data included in the cover image are the title, author, last update or publish date, tags, and blog post series (if applicable) or category. This blog post’s cover image # Generating the cover To generate the cover I’m using tcardgen, which I forked to add some custom features. This tool, written in Go, will generate a cover image with the background, font, and colours of your choosing. Give the following directory structure assets/ ├── img/ | └── card-template.png ├── font/ | ├── KintoSans-Bold.ttf | ├── KintoSans-Medium.ttf | └── KintoSans-Regular.ttf content/ ├── blog/ | └── blog-post | | └── index.md you would run the following command to generate a cover image using the default settings. tcardgen -f assets/font \ -t assets/img/card-template.png \ -o content/blog/blog-post/cover.png \ content/blog/blog-post/index.md To override the default settings, you can use a config file, like this one: # tcardgen.config.yaml template: assets/img/card-template.png title: start: px: 123 py: 165 fgHexColor: "#8B26AF" # Default: "#000000" fontSize: 68 fontStyle: Bold maxWidth: 946 lineSpacing: 10 category: enabled: false # Default: true start: px: 126 py: 110 fgHexColor: "#8D8D8D" fontSize: 42 fontStyle: Regular info: enabled: true start: px: 240 py: 440 fgHexColor: "#E58003" # Default: "#8D8D8D" fontSize: 32 fontStyle: Italic separator: " ∙ " timeFormat: "Jan 2 '06" tags: enabled: true start: px: 1025 py: 500 # 451 fgHexColor: "#FFFFFF" bgHexColor: "#E58003" # Default: "#7F7776" fontSize: 18 fontStyle: BoldItalic boxAlign: Right boxSpacing: 6 boxPadding: top: 6 right: 10 bottom: 6 left: 10 series: # Added in my custom fork enabled: true # Default: false start: px: 126 py: 110 fgHexColor: "#8D8D8D" fontSize: 42 fontStyle: Regular In the config file you can change the colours (text and background) and font style of the different elements on the card. You can also move the location of fields or completely disable them. In my fork I added the option to disable fields, which got upstreamed, and also added the series taxonomy which I used in my blog. Use the `-c` parameter to pass a config file: tcardgen -c tcardgen.config.yaml \ -f assets/font \ -o content/blog/blog-post/cover.png \ content/blog/blog-post/index.md # Hugo config By default, Hugo’s built-in templates will use the `*cover*` located with the blog-post as featured image, unless this is overridden in the frontmatter. If you name the cover image differently (not `feature*`, `*cover*` or `*thumbnail*`) Hugo will look in the frontmatters `.Params.images` or your site’s `site.Params.images` configuration for an image. For example, you could name the generated cover image after the name of your blog post and then add the following section to the fronmatter: --- # ... params: images: - blog-post.png --- # Automated cover generation Now we can manually create a cover for our blogpost by running the `tcardgen` command and passing the correct parameters. But it would even be better if we could automate this part. For this, I set up the following GitHub workflow: # .github/workflows/create-cover.yml --- name: Create cover concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true on: push: branches: - main - staging pull_request: branches: - main - staging # Allow manual trigger workflow_dispatch: {} jobs: changed-files: name: Check for new posts runs-on: ubuntu-latest outputs: matrix: ${{ steps.changed-files.outputs.added_files }} added_files_count: ${{ steps.changed-files.outputs.added_files_count }} steps: - name: Checkout uses: actions/checkout@v4 - name: Get new posts id: changed-files uses: ./.github/actions/changes with: files: | ./content/**.md matrix: true matrix-create: name: Create covers runs-on: ubuntu-latest needs: [changed-files] if: needs.changed-files.outputs.added_files_count > 0 strategy: matrix: files: ${{ fromJSON(needs.changed-files.outputs.matrix) }} max-parallel: 4 fail-fast: false continue-on-error: true steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Go uses: actions/setup-go@v5 with: go-version-file: './go.mod' # this will use go.mod to install the correct package(s) - name: Create cover run: | tcardgen -c tcardgen.config.yaml -f assets/fonts -o $(dirname "${{ matrix.files }}")/cover.png ${{ matrix.files }} # .github/actions/changes/action.yml name: Changes description: Check changed files inputs: files: description: Files or folders to monitor required: false default: null files_ignore: description: Files or folders to ignore required: false default: "" matrix: description: Output changed files in a matrix-ready format required: false default: false outputs: any_changed: description: Returns true when any of the filenames provided using the files or files_ignore inputs have changed. This defaults to true when no patterns are specified. i.e. includes a combination of all added, copied, modified and renamed files value: ${{ steps.changed-files.outputs.any_changed }} all_changed_files: description: Returns all changed files i.e. a combination of all added, copied, modified and renamed files value: ${{ steps.changed-files.outputs.all_changed_files }} added_files: description: Returns only files that are added value: ${{ steps.changed-files.outputs.added_files }} added_files_count: description: Returns number of added files value: ${{ steps.changed-files.outputs.added_files_count }} runs: using: "composite" steps: - name: Get changed filed id: changed-files uses: tj-actions/changed-files@v45 with: files: ${{ inputs.files }} files_ignore: ${{ inputs.files_ignore }} matrix: ${{ inputs.matrix }} - name: List all changed files shell: bash env: ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} run: | echo "Files changed:" for file in ${ALL_CHANGED_FILES}; do echo "- $file" done # go.mod module github.com/TheGroundZero/tcardgen go 1.23 This workflow will check at every push or PR whether a new blog post was added and – if so – will create a cover image for it. And we’re done 🚀 Now every blog post will always have a cover image attached. And if I want to use something custom, I can still use the post’s frontmatter to pick it instead of the generator cover.
03.03.2025 23:00 👍 0 🔁 0 💬 0 📌 0
Flashing the Sonoff POWR3 with Tasmota # The Sonoff POWR3 I love being able to control power on a circuit using a smart relais. I already have some Shelly Pro devices in my home. But they are limited to 16A per channel. And while that is sufficient for lighting circuits, which are protected with a 16A breaker here in Belgium, it doesn’t suffice for 20A socket circuits. I want to automate a circuit going from my house to some sockets outside so that I can either “lock” them to prevent people stealing energy or use them for e.g. automated Christmas lights. So I needed a smart relais capable of at least 20A. Another option would’ve been something like a Shelly Pro EM and a contactor, but that would’ve been a bit too clunky and more expensive. Luckily, Sonoff have a device that can do power metering and has a relais capable of handling 25A (5,500W): the Sonoff POWR3. Sonoff POWR3 # Flashing with Tasmota The Sonoff POWR3 comes with the default Sonoff firmware. This includes support for Google Assistant, Alexa and even Home Assistant. I just prefer to use open source firmware which works locally, doesn’t need or attempt to call a cloud, and won’t be bricked remotely. That’s why I’ll flash the device with Tasmota. Luckily, Sonoff have made it extremely easy to wire up the POWR3 to your flasher 🚀 Sonoff POWR3 exposing GPIO All you will need are: * The Sonoff POWR3 (duh!) * A simple screwdriver (cross or “electricians flathead”) * An FTDI serial adapter * Some female-to-female Dupont wires ## Connecting the POWR3 First of all: **make sure the POWR3 is NOT connected to mains** or you’ll blow your FTDI up. Hook your FTDI up to the POWR3 as follows: POWR3| FTDI ---|--- 3V3| VCC GND| GND ETX| RX ERX| TX GPIO on the POWR3GPIO on the FTDI Note that black and brown are interchanged between these 2 pictures ;) ## Flashing the POWR3 Now plugin the FTDI in your computer whilst holding the `FLASH` button to boot up the ESP in flash mode. Then start tasmotizer and select the correct port (e.g. ttyUSBx on Linux or COMx on Windows). It’s best to take a backup of the current flash, in case you’d ever want to return to it’s stock configuration. We’ll wipe the flash before flashing, so there’re won’t be a return path afterwards. The `tasmota-4M` binary will fit on the POWR3 because it has 4MB of flash, but the regular `tasmota.bin` suffices for this installation. Tasmotizer settings If everthing is configured correctly, you can go ahead and press **Tasmotize!**. # Setting up Tasmota ## Connecting the POWR3 to your WiFi network Once you power cycle the –now flashed– Sonoff POWR3, it should start broadcasting a WiFi network with the SSID `tasmota_XXXXXX-####` (where XXXXXX is a string derived from the device’s MAC address and #### is a number). Connect with your computer or smartphone to this network. You’ll likely receive a pop-up stating you need to login onto the network, or your browser will automatically open. If not, open your browser and go to `http://192.168.4.1` to open the Tasmota Web Config. Select your WiFi network from the list, or type the SSID manually, along with the password in its respective textbox. Pressing `Save` will restart the device and have it connect to your network. If successful, the Tasmota WiFi network will dissappear and the device will appear on your network. The Tasmota Web UI should now also display the IP address of the device and will likely redirect you to it. If not, and the device is still connected over Serial to your computer, you can press the `Get IP` button in Tasmotizer to retrieve the device’s IP address. Otherwise, you’ll have to look in your routers DHCP Lease table ## Configuring Tasmota Now we need to tell Tasmota how to read the power metering data and how to control the relais. The easiest way to do this is using a pre-configured template. Go to `Configuration` > `Configure Other` and past the following template in the text box: `{"NAME":"Sonoff POWR3","GPIO":[32,3072,0,3104,0,0,0,0,256,320,0,1,1,1],"FLAG":0,"BASE":43}` Check the `Activate` box and press `Save`. The device will reboot and on the “home page” you’ll now see the power metering information as well as a On/Off toggle button for the relais. # Power calibration I have yet to confirm the accuracy of the measurements right after flashing. If you notice incorrect readings or just want to be sure your device is properly calibrated, you can follow this Tamosta guide on Power Monitoring Calibration. To do this, you’ll need something with a consistent load (e.g. a decent incandescent light bulb) and preferably something that can accurately measure the power draw (like a multimeter or a power metering socket). # Connecting with Home Assistant ## MQTT broker To connect Tasmota device to your Home Assistant instance, you first need to setup a MQTT broker. This is outside the scope of this blog post, but I covered this already in my HA Container series as well as a Getting started with Shelly article. ## Tasmota MQTT config Go back to `Configuration` > `Configure Other` and check `MQTT Enable`. Then fill in the MQTT broker information. Host, User and Password should be the only fields you need to update. Only change the other fields if you know what you’re doing. See the Home Assistant documentation for more infomation. ## Add device to Home Assistant Saving this config, your POWR3 should no send updates to your MQTT broker which will cause Home Assistant to auto-detect it. Go the the `Settings` > `Devices & services`, find the detected Tasmota config and click `Add`. Add the device to the correct Area and press Finish. And you’re all set! Now you can control the Sonoff POWR3 from Home Assistant. Use it in automations, e.g. to turn on Christmas lights in the evening and off again at night, or use it to turn on a heater when you have sufficient solar production. Plenty of stuff you can do now. Enjoy!
11.02.2025 23:00 👍 0 🔁 0 💬 0 📌 0
Preview
Bridging this blog with the Fediverse Adding microformats (h-entry) to my blog to optimise fediverse adoption
01.01.2025 23:00 👍 0 🔁 0 💬 0 📌 0
Preview
New year, new theme for the site I’m switching to a new theme for this site, and I got some plans for it as well.
31.12.2024 23:00 👍 0 🔁 0 💬 0 📌 0
Flashing the IKEA Vindriktning with Tasmota and ESPHome to connect it to Home Assistant We’ll be flashing two IKEA Vindriktning air quality sensors to connect them to Home Assistant. One will be flashed using Tasmota and the other with ESPHome.
04.09.2024 00:00 👍 0 🔁 0 💬 0 📌 0
Flashing the IKEA Vindriktning with Tasmota and ESPHome We’ll be flashing two IKEA Vindriktning air quality sensors to connect them to Home Assistant. One will be flashed using Tasmota and the other with ESPHome.
03.09.2024 22:00 👍 0 🔁 0 💬 0 📌 0
Home Assistant Container Part 13: VS Code code-server Installing VS Code code-server and link it to Home Assistant for auto-complete
12.02.2024 00:00 👍 0 🔁 0 💬 0 📌 0
Preview
Home Assistant Container Part 13: VS Code code-server Installing VS Code code-server and link it to Home Assistant for auto-complete
11.02.2024 23:00 👍 0 🔁 0 💬 0 📌 0
Preview
Flash Xiaomi LYWSD03MMC BLE sensor with Zigbee firmware We’re flashing the popular Xiaomi LYWSD03MMC temperature/humidity sensor with Zigbee firmware
09.02.2024 00:00 👍 0 🔁 0 💬 0 📌 0
Preview
Flash Xiaomi LYWSD03MMC BLE sensor with Zigbee firmware We’re flashing the popular Xiaomi LYWSD03MMC temperature/humidity sensor with Zigbee firmware
08.02.2024 23:00 👍 0 🔁 0 💬 0 📌 0
Preview
Remotely opening and closing my gate Remotely opening my garage door using a Shelly Plus 1 Mini and Home Assistant. Useful for coming-home automations.
14.12.2023 00:00 👍 0 🔁 0 💬 0 📌 0
Preview
Remotely opening and closing my gate Remotely opening my garage door using a Shelly Plus 1 Mini and Home Assistant. Useful for coming-home automations.
13.12.2023 23:00 👍 0 🔁 0 💬 0 📌 0
2 months in It’s been about 2 months since my diagnosis. How am I doing?
16.10.2023 00:00 👍 0 🔁 0 💬 0 📌 0
2 months in It’s been about 2 months since my diagnosis. How am I doing?
15.10.2023 22:00 👍 0 🔁 0 💬 0 📌 0
Preview
Belgian ESPHome config for Slimmelezer(+) by Marcel Zuidwijk This config includes the Belgian peak tariff DSMR sensors added in ESPHome 2023.7
18.08.2023 00:00 👍 0 🔁 0 💬 0 📌 0
Preview
Belgian ESPHome config for Slimmelezer(+) by Marcel Zuidwijk This config includes the Belgian peak tariff DSMR sensors added in ESPHome 2023.7
17.08.2023 22:00 👍 0 🔁 0 💬 0 📌 0
Preview
I've been chipped and am getting training I’ve been chipped. I now wear a nice glucose monitoring chip on my arm. I’m also getting trained in how to manage my blood sugar levels.
31.07.2023 00:00 👍 0 🔁 0 💬 0 📌 0
Preview
I've been chipped and am getting training I’ve been chipped. I now wear a nice glucose monitoring chip on my arm. I’m also getting trained in how to manage my blood sugar levels.
30.07.2023 22:00 👍 0 🔁 0 💬 0 📌 0
Preview
So I'm diabetic ... I just got diagnosed with Type 1 Diabetes…
30.07.2023 00:00 👍 0 🔁 0 💬 0 📌 0
Preview
So I'm diabetic ... I just got diagnosed with Type 1 Diabetes…
29.07.2023 22:00 👍 0 🔁 0 💬 0 📌 0
Preview
Darebee daily challenge on Home Assistant dashboard A short blog post showing you how to display Darebee’s daily challenge on your Home Assistant dashboard
18.07.2023 00:00 👍 0 🔁 0 💬 0 📌 0
Preview
Ulanzi TC001 Desktop Clock - Awtrix Taking a look at the Ulanzi Desktop Clock and flashing it with Awtrix. Playing a doorbell notification, including sound.
30.03.2023 00:00 👍 0 🔁 0 💬 0 📌 0