@sircharlo wrote:
Hello everyone,
I recently purchased a TechLife Pro bulb on AliExpress, not really knowing the rabbit hole I was throwing myself into. Upon receiving it, I realized to my dismay that it was not ESP-based, and therefore of course wouldn’t run Tasmota. This means I am stuck with the terrible stock firmware controlled by a mediocre app.
After much reading and research, it turns out that all the app does is communicate with a Chinese server through MQTT, which then talks to the bulb. Using DNS redirection on my router, I was able to get to lightbulb to talk to my HA server instead of the external Chinese server.
I thought I could just integrate the light into HA as an MQTT light, but it turns out that the messages that are sent by the app over MQTT are hexadecimal encoded and not at all straightforward; unless I am incorrect, there is no way to send complex hex-encoded bytestring payloads through HA.
In any case, I adapted a few scripts that I found online into one Bash script which, when run, can either turn off, turn on, or dim the specified lightbulb.
#!/bin/bash t="dev_sub_""$1" t=$(echo $t | tr '[:upper:]' '[:lower:]') if [ "$2" != "" ]; then if [ "$2" == "on" ]; then echo -en "\xfa\x23\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x23\xfb" | mosquitto_pub -t $t -s -u user -P "password" elif [ "$2" == "off" ]; then echo -en "\xfa\x24\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x24\xfb" | mosquitto_pub -t $t -s -u user -P "password" elif [ "$2" == "dim" ]; then d=$(expr $3 \* 100) prefix='28' oneToSix='000000000000' sevenToTen=$(printf %08X "$d" | grep -o .. | tac | tr "\n" "," | sed "s/,//g") elevenToThirteen='0000f0' oneToThirteen=$(echo $oneToSix$sevenToTen$elevenToThirteen) oneToThirteenMod=$(echo $oneToThirteen | sed 's/../0x&^/g' | sed 's/.$//') xor=$(python3 -c "print(hex($oneToThirteenMod)[2:].lower())") suffix='29' k=$(echo $prefix$oneToSix$sevenToTen$elevenToThirteen$xor$suffix | sed 's/../\\x&/g' | tr -d "\n") echo -en $k | mosquitto_pub -t $t -s -u user -P "password" fi else echo "Usage: " echo "$0 [MAC] on" echo "$0 [MAC] off" echo "$0 [MAC] dim [0-100]" fi
This script runs great when SSH’d into my HA server, and from the web HA terminal as well. The problem is when I try to set up a templated light to tie all the pieces together. I can’t for the life of me get it to work.
Here is the relevant portion of my
configuration.yaml
light: - platform: template lights: lr_media_center: friendly_name: "Living Room Media Center" # level_template: # not there yet... # value_template: # not there yet... turn_on: service: shell_command.techlife data: mac: "7E:28:6B:AD:21:7C" action: "on" turn_off: service: shell_command.techlife data_template: mac: "7E:28:6B:AD:21:7C" action: "off" # set_level: # not there yet... # service: script.techlife # data_template: # mac: "7E:28:6B:AD:21:7C" # action: "dim" # brightness: "{{ brightness }}" # not sure how to send a dim percentage to my script shell_command: techlife: ./custom_components/TechLife/TechLife.sh {{ mac }} {{ action }}
Tapping on my light entity gives the following error message:
Error running command: `./custom_components/TechLife/TechLife.sh {{ mac }} {{ action }}`, return code: 127 NoneType: None
I believe error code 127 means that HA can’t find my command? I am extremely confused, as the script is in fact there! What am I doing wrong?
Once I have all this sorted out, my end goal is to share the finished result with others who might have TechPro bulbs and not know how to integrate them with HA.
Thank you for your time and help!
Posts: 3
Participants: 2