i'm new into bash scripts and i really need your help.
The following Script gets humidity and temperature from a DHT22 sensor on my BananaPi and sends it to my HomeAutomation.
#!/bin/bash
cd /opt/lol_dht22
WERTE=$(./loldht 7 | grep "Humidity")
Temp=( $(echo $WERTE | awk '{ print $ 7}'))
Hum=( $(echo $WERTE | awk '{ print $ 3}'))
perl /opt/fhem/fhem.pl 7072 "setreading DHT22 temperature $Temp"
perl /opt/fhem/fhem.pl 7072 "setreading DHT22 humidity $Hum"
The results are like 30.00 (With a Comma), and sometimes the sensor fails and gives an unrealistic value like -3000.00 or similar.
So i wanted to implement a IF Condition which checks if it's greater or equal 0 or less or equal 100.
I tried things like:
#!/bin/bash
cd /opt/lol_dht22
WERTE=$(./loldht 7 | grep "Humidity")
Temp=( $(echo $WERTE | awk '{ print $ 7}' | tr '.' ','))
Hum=( $(echo $WERTE | awk '{ print $ 3}' | tr '.' ','))
if [[ $Temp -ge 0 && $Temp -le 100 && $Hum -ge 0 && $Hum -le 100 ]]; then
Temp1=( $(echo $Temp | tr ',' '.'))
Hum1=( $(echo $Hum | tr ',' '.'))
perl /opt/fhem/fhem.pl 7072 "setreading DHT22 temperature $Temp1"
perl /opt/fhem/fhem.pl 7072 "setreading DHT22 humidity $Hum1"
else
exit;
fi
It seemed like the comma (.) was the problem, so i tried switching it to a (,) and back. But there are sometimes still values which are not between 0 and 100.
I hope someone can help me, thank you!
Regards,
Klaus