Small update. Since i dont want to implement all this logic in openhab, i have created it outside of openhab. After i got the code from Yaros i updated the bash script and created a c++ (very horrid) code.
Here is the new bash script:
#!/bin/bash
t="dev_sub_xx:xx:xx:xx:xx:bx"
if [ "$1" != "" ]; then
if [ "$1" == "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
elif [ "$1" == "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
elif [ "$1" == "dim" ]; then
# Gang opp med 100.
d=$(expr $2 \* 100)
k=$(/etc/openhab2/misc/kinalys/ckinalys $d) ; echo -en $k | mosquitto_pub -t $t -s
fi
else
echo "Usage: "
echo "$0 on - turn on"
echo "$0 off - turn off"
echo "$0 dim % - dimmer"
fi
the ckinalys code looks like this:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
using namespace std;
void setBrightnessLevel(int Level) {
//cout << "Debug: " << Level << "\n";
unsigned char MqttCommand[] = "\x28\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x00\x29";
MqttCommand[7] = (Level & 255);
MqttCommand[8] = ((Level >> 8) & 255);
unsigned char Checksum = 0;
for (int byteNum = 1; byteNum < 14; byteNum++)
{
Checksum ^= MqttCommand[byteNum];
}
MqttCommand[14] = (Checksum & 255);
char ut[512] = ""; // tom til å begynne med
for (int i = 0; i != 16; i++) {
char tmp[8];
sprintf(tmp, "\\x%02x", MqttCommand[i]);
strcat(ut, tmp);
}
printf("%s", ut);
}
int main(int argc, char** argv) {
if (argc == 2) {
std::istringstream ss(argv[1]);
int x;
if (!(ss >> x)) {
std::cerr << "Invalid number: " << argv[1] << '\n';
return 1;
} else if (!ss.eof()) {
std::cerr << "Trailing characters after number: " << argv[1] << '\n';
}
setBrightnessLevel(x);
}
else {
cout << "Usage: " << "\n";
cout << argv[0] << " dimlevel (int)" << "\n";
}
return 0;
}
its compiled with g++ main.cpp -o ckinalys
Now the slider actually works from 1 to 100%
Big thanks to Yaros!