Skip to content

Instantly share code, notes, and snippets.

View bdraco's full-sized avatar

J. Nick Koston bdraco

View GitHub Profile
@bdraco
bdraco / core_integration_pr
Last active December 1, 2023 07:26 — forked from ludeeus/core_integration_pr
Install HA Core PR as custom component
#!/bin/bash
# curl -o- -L https://gist.githubusercontent.com/bdraco/43f8043cb04b9838383fd71353e99b18/raw/core_integration_pr | bash /dev/stdin -d domain -p 12345
while getopts d:p: flag
do
case "${flag}" in
d) domain="${OPTARG}";;
p) pull_request="${OPTARG}";;
esac
done
@bdraco
bdraco / shellypm1_fan.yaml
Last active March 12, 2021 08:25 — forked from xbmcnut/shellypm1_fan.yaml
How to make a dumb device smart using a Shelly PM1 | Fan Template example in Home Assistant
fan:
- platform: template
fans:
template_bedroom_fan:
friendly_name: "Master Bedroom Fan"
# Measures the power use from a Shelly1 PM and if over 3W, marks the fan as on
value_template: "{% if states('sensor.bedroom_fan_shelly_power') | float > 3 %}on{% else %}off{% endif %}"
# Uses the Shelly1 PM sensor value to determine what speed the fan is going at. Only set to measure 33, 66, 100
percentage_template: "{{ states('sensor.template_fan_percentage_master') }}"
# Uses a fake switch from an input_boolean as the fan has no way of reporting direction back to HA
@bdraco
bdraco / remove_foreign_keys.py
Created November 26, 2020 20:21 — forked from SalemHarrache/remove_foreign_keys.py
SQLAlchemy : remove all foreign keys constraints
def remove_foreign_keys(db):
log("Dropping all foreign key constraints from archive database")
inspector = reflection.Inspector.from_engine(db.engine)
fake_metadata = MetaData()
fake_tables = []
all_fks = []
for table_name in db.metadata.tables:
@bdraco
bdraco / TempDropFKContraint.py
Created November 26, 2020 20:21 — forked from nZac/TempDropFKContraint.py
Temporarily Drop a Foreign Key Constraint, Python, SQLAlchemy
class TempDropConstraint(object):
def __init__(self, table, column):
self.table = table
self.table_name = table.__tablename__
self.column = column
self.constraint = list(self.table.__table__.columns[column.name].foreign_keys)[0]
self.constraint_name = self.constraint.name
self.referred_table = self.constraint.column.table.name
@bdraco
bdraco / Jinja module loader.md
Created August 10, 2020 14:37 — forked from voscausa/Jinja module loader.md
Jinja2 compiled templates module loader for App Engine Pyhton 2.7.

Jinja compiled templates module loader

This code is part of a Jinja CMS for Google App Engine Python 2.7 and NDB datastore

A Jinja enviroment is created for every CMS site: site_key_id = 'example

The modules are created using compiler.py The resulting code objects are stored in the dadastore using Kind Runtimes and a BlobProperty

The modules can also be saved / downloaded as .pyc in a zip archive: -compiled-templates.zip

#!/usr/bin/env python
"""
Python class to interface with local Tesla Powerwall JSON API
https://github.com/piersdd/tesla-powerwall-json-py
Example:
import powerwall_site
gateway_host = '192.168.5.6'