Skip to content

Instantly share code, notes, and snippets.

View devjourney's full-sized avatar

W. Kevin Hazzard devjourney

View GitHub Profile
@devjourney
devjourney / bthome_ble_lux_control_only.js
Created January 16, 2026 20:53
Control the brightness of a Shelly RGBW PM channel with BTHome messages over BLE from a Shelly BLU Motion sensor.
let CONFIG = {
debug: false,
active: false, // passive BLE scanning is sufficient
// BTHome light sensor(s) that will report to this device
sensorMACs: [
"3c:2e:f5:ba:e8:bd" // Shelly BLU Motion sensor
],
lightId: 0, // Channel 0 in Lights x4 mode
fullBrightness: 100, // max brightness
minBrightness: 5, // min brightness (avoid completely dark)
@devjourney
devjourney / bthome_ble_motion_and_lux_trigger.js
Last active January 16, 2026 20:51
Script to trigger Gen2 Shelly devices from BTHome messages with motion and lux data from Shelly BLU devices.
let CONFIG = {
// the BTHome motion and light sensors that will report to this device
// add a Bluetooth MAC address for each reporting sensor
sensorMACs: [
"3c:2e:f5:ba:e8:bd".toLowerCase() // Shelly BLU Motion sensor
],
lightId: 0, // Channel 0 in Lights x4 mode
fullBrightness: 100, // max when very bright ambient
minBrightness: 5, // min when very dark (soft night light)
timeoutSec: 300, // shared timeout for motion
@devjourney
devjourney / ShellySyncWithPairedLight.js
Created December 27, 2025 03:31
Use this Shelly smart relay script to sync the switch state of the relay with that of another device using MQTT.
function subscribeToStatusUpdates(topic) {
MQTT.subscribe(topic , function(t, message) {
if (typeof message === "undefined" || message === null) {
print("Received undefined or null message - ignoring");
return;
}
try {
let payload = JSON.parse(message);
if (payload.source === "button") {
@devjourney
devjourney / configure_shelly.py
Created November 30, 2025 03:38
Configure many Shelly IoT devices at once.
# python configure_shelly.py --password <password> --method BLE.SetConfig --device-file .\shelly_ips.txt --config "{ \"rpc\": { \"enable\": true } }"
# python configure_shelly.py --password <password> --method BLE.GetConfig --device-file .\shelly_ips.txt
# python configure_shelly.py --password <password> --method Cloud.SetConfig --device-file .\shelly_ips.txt --config "{ \"enable\": true }"
# python configure_shelly.py --password <password> --method Cloud.GetConfig --device-file .\shelly_ips.txt
import requests
import json
from requests.auth import HTTPDigestAuth
import argparse
@devjourney
devjourney / SetSpeakerVolumeOnSchedule.yaml
Created February 13, 2025 15:45
A Home Assistant automation to set the volume of several media players at a specific time of day.
alias: Speakers - Set Sleep Volume
description: Set the volume of speakers lower overnight.
triggers:
- trigger: time
at: "23:00:00"
conditions: []
actions:
- action: media_player.volume_set
metadata: {}
data:
@devjourney
devjourney / AlertOnPoolGateHelpOpen.yaml
Created February 13, 2025 15:43
A Home Assistant automation that will play an audio message when a gate has been held open too long.
alias: Alert on Pool Gate Opened
description: ""
mode: single
triggers:
- type: opened
device_id: 896de4d80d8fa631e58804be71b50b51
entity_id: f40b16da6652e7402e9b819f707cedf3
domain: binary_sensor
for:
hours: 0
@devjourney
devjourney / SwitchesSync.yaml
Created February 13, 2025 15:41
A Home Assistant automation to have several switches follow the on-off state of another switch.
alias: Office Lights - Follow Moulding Lights
triggers:
- entity_id:
- switch.ofc_moulding_lights
from: "on"
to: "off"
trigger: state
- entity_id:
- switch.ofc_moulding_lights
from: "off"
@devjourney
devjourney / ILI9341_TFT_LCD_Simple_Counter.py
Last active January 7, 2024 01:23
CircuitPython ILI9341 TFT Showing Second Counter
import board
import time
import terminalio
import displayio
import digitalio
from adafruit_display_text import label
import adafruit_ili9341
# Release any resources currently in use for the displays
displayio.release_displays()
@devjourney
devjourney / flashingledswithbuttoncontrolleddelay.py
Last active December 8, 2019 04:36
Python script for Raspberry Pi to alternate flashing of two LEDs with two buttons for modifying the duration of the delays between alternations.
from gpiozero import LED, Button
from time import sleep
minimum = 0.0625
maximum = 1.00
increment = 0.0625
delay = minimum
def set_delay(offset):
global delay, minimum, maximum
@devjourney
devjourney / UpsertProcedureAndExecuteV1.js
Last active December 9, 2018 21:09
A Node.js app that creates a Cosmos DB stored procedure and executes it.
var CosmosClient = require('@azure/cosmos').CosmosClient;
var config = require('./config.js');
var client = new CosmosClient({
endpoint: config.connection.endpoint,
auth: { masterKey: config.connection.authKey }
});
async function upsertProcedureAndExecute(sprocDef, docToInsert) {
const { database } = await client.databases
.createIfNotExists({ id: config.names.database });