Hi guys,
Wanted to say thanks for the information in this thread. Inspired me to get an oddball bulb working that I had picked up when it was on sale.
Sengled Smart LED with Bluetooth Speaker Bulb – Sengled Canada - that guy
The tricky bit I had to work around was the bulb expecting brightness between 1-100, but in hex which I solved in my bash script. Then Home Assistant wants to use 1-255…
Here’s what I came up with.
#!/bin/bash
sendBluetoothCommand() {
mac="$mac"
characteristic="$characteristic"
commandcode="$1"
gatttool -i hci0 -b $mac --char-write-req -a $characteristic -n $commandcode
}
mac="01:23:45:67:89:AB"
command="$1"
characteristic=0x0017
case $command in
volume_up)
commandcode="7efeffffff0000000000000d000101"
;;
volume_down)
commandcode="7efeffffff0000000000000d000001"
;;
on)
commandcode="7efeffffff0000000001000000000000"
;;
off)
commandcode="7efeffffff0000000001000000000001"
;;
[0-9]|[1-9][0-9]|100)
hex=$(printf '%02x\n' $1)
commandcode="7efeffffff00000000010001000000ff$hex"
;;
*)
echo "Unsupported command!"
exit 22
;;
esac
sendBluetoothCommand $commandcode
Then for the light in home assistant - template to the rescue. Here I convert 1-255 to 1-100 which is what the script is expecting.
- platform: template
lights:
workbench_lamp:
friendly_name: "Workbench Lamp"
icon_template: mdi:desk-lamp
turn_on:
service: shell_command.sengled_control_on
turn_off:
service: shell_command.sengled_control_off
set_level:
service: shell_command.sengled_brightness_control
data:
brightness: "{{ (brightness | float / 255 * 100) | round(0) }}"
Oh right I also made simple shell command that just calls the script with args specified.
# Sengled Pulse Solo control
sengled_control_on: bash /config/scripts/sengled_control.sh on
sengled_control_off: bash /config/scripts/sengled_control.sh off
sengled_control_volume_up: bash /config/scripts/sengled_control.sh volume_up
sengled_control_volume_down: bash /config/scripts/sengled_control.sh volume_down
sengled_brightness_control: bash /config/scripts/sengled_control.sh {{brightness}}
Magically this all works and made an otherwise useless bulb very useful.
Thanks again everybody!