Last active
September 8, 2022 08:49
-
-
Save LemonHaze420/b78843e8fe0065d34ee0f9ed2da97549 to your computer and use it in GitHub Desktop.
Simple BLEDOM LED controller bash script with sample HomeAssistant config. Supports RGB and brightness manipulation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Configuration | |
device="XX:XX:XX:XX:XX:XX" | |
device_san="XX_XX_XX_XX_XX_XX" | |
characteristic="/org/bluez/hci0/dev_$device_san/service0006/char0007" | |
mode=on | |
brightness=100 | |
red=255 | |
green=0 | |
blue=0 | |
# Main script body | |
if [ "$1" == "on" ]; then | |
cmd="0x7e 0x00 0x04 0xf0 0x00 0x01 0xff 0x00 0xef" | |
printf "connect $device\ntrust $device\ngatt.select-attribute $characteristic\ngatt.write \"$cmd\"\nquit\n\n" | bluetoothctl | |
fi | |
if [ "$1" == "off" ]; then | |
cmd="0x7e 0x00 0x04 0x00 0x00 0x00 0xff 0x00 0xef" | |
printf "connect $device\ntrust $device\ngatt.select-attribute $characteristic\ngatt.write \"$cmd\"\nquit\n\n" | bluetoothctl | |
fi | |
if [ "$1" == "brightness" ]; then | |
tbr=$(printf '0x%x' $2) | |
cmd="0x7e 0x00 0x01 $tbr 0x00 0x00 0x00 0x00 0xef" | |
printf "connect $device\ntrust $device\ngatt.select-attribute $characteristic\ngatt.write \"$cmd\"\nquit\n\n" | bluetoothctl | |
fi | |
if [ "$1" == "rgb" ]; then | |
values=$(printf '0x%x 0x%x 0x%x' $2 $3 $4) | |
cmd="0x7E 0x00 0x05 0x03 $values 0x00 0xEF" | |
printf "connect $device\ntrust $device\ngatt.select-attribute $characteristic\ngatt.write \"$cmd\"\nquit\n\n" | bluetoothctl | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HA configuration YAML: