Hi,
i tested alot and also tried to connect a second sensor.
However a lot of times i am getting error messages reading the data from the sensors.
Currently i am reading the data via the “exec binding”.
This is how the script on the RPI3b+ looks like:
#!/bin/bash
sudo hciconfig hci0 down && sudo hciconfig hci0 up
bt=$(timeout 40 gatttool -b $1 --char-write-req --handle=‘0x0038’ --value=“0100” --listen)
if [ -z “$bt” ]
then
a = 0
else
temphexa=$(echo $bt | awk -F ’ ’ ‘{print $12$11}’| tr [:lower:] [:upper:] )
humhexa=$(echo $bt | awk -F ’ ’ ‘{print $13}’| tr [:lower:] [:upper:])
temperature100=$(echo “ibase=16; $temphexa” | bc)
humidity=$(echo “ibase=16; $humhexa” | bc)
if [ $2 = “temperature” ]
then
echo “scale=2;$temperature100/100”|bc
else
echo $humidity
fi
fi
I have created 2 things:
Thing exec:command:humidor_temperature “Humidor - Temperatur” @ “Buero” [command=“sudo bash /home/openhabian/xiaomi_sensor_uni.sh ‘A4:C1:38:E6:FF:3E’ ‘temperature’”, transform=“REGEX((.*?))”, interval=300, timeout=80, autorun=true]
Thing exec:command:humidor_humidity “Humidor - Luftfeuchtigkeit” @ “Buero” [command=“sudo bash /home/openhabian/xiaomi_sensor_uni.sh ‘A4:C1:38:E6:FF:3E’ ‘humidity’”, transform=“REGEX((.*?))”, interval=300, timeout=80, autorun=true]
And put the command into the exec.whitelist
However most of the time i am getting this in the log screen:
2020-09-17 10:52:50.277 [vent.ItemStateChangedEvent] - Humidor_Temperature changed from connect: No route to host (113)
/home/openhabian/xiaomi_sensor_uni.sh: line 7: a: command not found
connect: No route to host (113)
/home/openhabian/xiaomi_sensor_uni.sh: line 7: a: command not found to Can’t init device hci0: No such device (19)
connect: No route to host (113)
/home/openhabian/xiaomi_sensor_uni.sh: line 7: a: command not found
Can’t init device hci0: No such device (19)
connect: No route to host (113)
/home/openhabian/xiaomi_sensor_uni.sh: line 7: a: command not found
But sometimes its also working:
2020-09-17 10:31:04.635 [vent.ItemStateChangedEvent] - Humidor_Humidity changed from connect: Device or resource busy (16)
/home/openhabian/xiaomi_sensor_uni.sh: line 7: a: command not found
connect: Device or resource busy (16)
/home/openhabian/xiaomi_sensor_uni.sh: line 7: a: command not found to 60
The second sensor is even worse and i am not getting any value (openhab or RPI) even if it is located just next to the RPI. I also connected it to my Xiaomi smartphone app, there i do not have any trouble.
[10:57:16] openhabian@openhab:~$ sudo -u openhabian bash /home/openhabian/xiaomi_sensor_uni.sh ‘A4:C1:38:E6:FF:3E’ ‘humidity’
connect error: Function not implemented (38)
/home/openhabian/xiaomi_sensor_uni.sh: line 7: a: command not found
However via sudo blescan i am able to find it:
Device (new): a4:c1:38:e6:ff:3e (public), -69 dBm
Flags: <06>
16b Service Data: <95fe30585b05123effe638c1a408>
Also using sudo bluetoothctl i can find and connect the device:
[bluetooth]# info A4:C1:38:E6:FF:3E
Device A4:C1:38:E6:FF:3E (public)
Name: LYWSD03MMC
Alias: LYWSD03MMC
Paired: no
Trusted: no
Blocked: no
Connected: no
LegacyPairing: no
UUID: Vendor specific (00000100-0065-6c62-2e74-6f696d2e696d)
UUID: Generic Access Profile (00001800-0000-1000-8000-00805f9b34fb)
UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
UUID: Device Information (0000180a-0000-1000-8000-00805f9b34fb)
UUID: Battery Service (0000180f-0000-1000-8000-00805f9b34fb)
UUID: Xiaomi Inc. (0000fe95-0000-1000-8000-00805f9b34fb)
UUID: Vendor specific (00010203-0405-0607-0809-0a0b0c0d1912)
UUID: Vendor specific (ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6)
ServiceData Key: 0000fe95-0000-1000-8000-00805f9b34fb
ServiceData Value:
30 58 5b 05 12 3e ff e6 38 c1 a4 08 0X[…>…8…
[bluetooth]# connect A4:C1:38:E6:FF:3E
Attempting to connect to A4:C1:38:E6:FF:3E
[CHG] Controller B8:27:EB:06:35:72 Powered: no
[CHG] Controller B8:27:EB:06:35:72 Discovering: no
Connection successful
Sorry for the extensive text but i am a little bit frustrated at the moment. Maybe someone can help