Skip to content

Instantly share code, notes, and snippets.

@LemonHaze420
Last active September 8, 2022 08:49
Show Gist options
  • Save LemonHaze420/b78843e8fe0065d34ee0f9ed2da97549 to your computer and use it in GitHub Desktop.
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.
#!/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
@LemonHaze420
Copy link
Author

HA configuration YAML:

shell_command:
  poweron_desk_leds: bash /config/bledomctl.sh on
  poweroff_desk_leds: bash /config/bledomctl.sh off
  set_brightness_desk_leds: bash /config/bledomctl.sh brightness {{brightness}}
  set_rgb_desk_leds: bash /config/bledomctl.sh rgb {{red}} {{green}} {{blue}}
  
light:
  - platform: template
    lights:
        desk_leds:
            friendly_name: "Desk LEDs"
            icon_template: mdi:desk-lamp       
            turn_on:
                service: shell_command.poweron_desk_leds
            turn_off:
                service: shell_command.poweroff_desk_leds
            set_level:
                service: shell_command.set_brightness_desk_leds
                data:
                    brightness: "{{ (brightness | float / 255 * 100) | round(0) }}"
            set_color:
                service: shell_command.set_rgb_desk_leds
                data:
                    red: "{{ states.light.desk_leds.attributes.rgb_color[0] }}"
                    green: "{{ states.light.desk_leds.attributes.rgb_color[1] }}"
                    blue: "{{ states.light.desk_leds.attributes.rgb_color[2] }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment