Skip to content

Instantly share code, notes, and snippets.

View rosmo's full-sized avatar

Taneli Leppä rosmo

View GitHub Profile
@rosmo
rosmo / motion-activated-lights.yaml
Last active September 13, 2024 15:26
motion-activated-lights.yaml
# Adapted from: https://community.home-assistant.io/t/motion-activated-light-but-with-conditions/466228
#
# Works better with presence sensors by using a helper boolean
blueprint:
name: Motion-activated Light for Presence Sensors
description: Turn on a light when motion is detected.
domain: automation
input:
motion_entity:
blueprint:
name: ZHA - Moes Smart Knob for lights
description: 'Control lights with a Moes Smart Knob.
You can set functions for a single press. This allows you to assign, e.g., a scene
or anything else.
Rotating left/right will change the brightness smoothly of the selected light.
Not all functionality of the device is available at time of writing, e.g. double
press, long press and press and rotate.
Original blueprint by seamus65 (https://gist.github.com/seamus65/939a147634942dd885c8704334627f93).
@rosmo
rosmo / png.star
Created December 25, 2023 22:22
Generate a PNG dynamically using Starlark (eg. for Tidbyt/Pixlet)
load("render.star", "render")
load("encoding/base64.star", "base64")
load("hash.star", "hash")
# Author: Taneli Leppä <rosmo@rosmo.fi>
# PNG encoder from: https://github.com/miloyip/svpng
# Base64 encoder from: https://gist.github.com/caseyscarborough/8467877
def generate_png(w, h):
t = [ 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c ] # CRC32 table
import argparse
import json
import tempfile
import sys
import os
parser = argparse.ArgumentParser(
description='Validate a Terraform plan file against deletions.')
parser.add_argument('file', type=str, help='file to validate')
args = parser.parse_args()
@rosmo
rosmo / gist:7e77f26dcdd3fed6713bbb0499c79cf1
Created December 18, 2022 21:39
Home Assistant: Zigbee/ZHA - moving from CC2531 to SkyConnect without repairing
1. Install community Terminal & SSH addon, disable protection
2. Log into home assistant via SSH
3. ls -l /dev/serial/by-id
total 0
lrwxrwxrwx 1 root root 13 Dec 15 09:56 usb-Nabu_Casa_SkyConnect_v1.0_34b60e0f8318ec11a66ef69a47486eb0-if00-port0 -> ../../ttyUSB0
lrwxrwxrwx 1 root root 13 Dec 15 09:56 usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B001CDD4956-if00 -> ../../ttyACM0
4. pip install git+https://github.com/zigpy/zigpy-cli.git
5. Disable CC2531 in Home Assistant
5. Make backup: zigpy -vv radio znp /dev/serial/by-id/usb-Texas_Instruments_TI_CC2531_USB_CDC___0X00124B001CDD4956-if00 backup znp.json
6. Restore backup: zigpy -vv radio znp /dev/serial/by-id/usb-Nabu_Casa_SkyConnect_v1.0_34b60e0f8318ec11a66ef69a47486eb0-if00-port0 restore znp.json
@rosmo
rosmo / credentials.conf.j2
Last active January 19, 2022 09:35
Install Cloud Ops Logging agent in a VM
[Service]
Environment=GOOGLE_SERVICE_CREDENTIALS=/etc/google/auth/application_default_credentials.json
ExecStartPre=/bin/sed -i "s/gce_instance/generic_node\\n location europe-west3\\n namespace example\\n node_id host.example.com/g" ${RUNTIME_DIRECTORY}/fluent_bit_main.conf
@rosmo
rosmo / c6_test.py
Created January 12, 2022 21:54
TP-Link X90 Deco API example
from requests.api import request
from Crypto.Cipher import PKCS1_OAEP, PKCS1_v1_5
from Crypto.Cipher import AES
from Crypto.PublicKey import RSA
from Crypto.Util.Padding import pad
from Crypto.Util.number import bytes_to_long
import base64
import requests
import string
import random
@rosmo
rosmo / Dockerfile
Last active December 30, 2021 22:32
gcs2bq wrapper in golang
# To build and deploy:
#
# docker build -t gcr.io/YOUR-PROJECT/gsc2bq-cloudrun:latest .
# docker push gcr.io/YOUR-PROJECT/gsc2bq-cloudrun:latest
#
# gcloud run deploy gcs2bq --image=gcr.io/YOUR-PROJECT/gsc2bq-cloudrun:latest \
# --service-account=your-sa@YOUR-PROJECT.iam.gserviceaccount.com \
# --timeout=60m --set-env-vars=GCS2BQ_PROJECT=YOUR-PROJECT,... \
# --region=europe-west4
#
@rosmo
rosmo / delete-vpc.sh
Last active November 15, 2021 12:24
Deleting AWS default VPCs (except for one region) via CLI
delete_vpc_components() {
echo aws ec2 "describe-${7}" --filters "Name=$4,Values=$3" --output text --query "*[*].$5" --region $1
for id in $(aws ec2 "describe-${7}" --filters "Name=$4,Values=$3" --output text --query "*[*].$5" --region $1)
do
echo "Deleting $2: $id"
if [ "$2" == "internet-gateway" ] ; then
aws ec2 detach-internet-gateway $6 $id --vpc-id $3 --region $1
fi
aws ec2 "delete-${2}" $6 $id --region $1
done
#!/usr/bin/python
#
# Convert a Row-Based-Replication binary log to Statement-Based-Replication format, cheating a little.
#
# Additional added some code to transfer INSERT clauses to proper column names.
#
# Usage: mysqlbinlog -v --base64-output=DECODE-ROWS $log | python binlog-rbr-to-sbr.py -hHOST -uUSERNAME -pPASSWORD - | grep -B 1 '^INSERT '
# Based on: https://gist.github.com/shlomi-noach/cc243fd690403e7617e3
#