Hello again, people. I have a LOT of good news regarding the script for the A1 Sensor! With the help of a great brazilian shell script forum, i discovered what was happening with
hum_stat: the A1 generates the decimal humidity value (eg 58.6) and the
IF can not handle the decimal values. The solution is use
AWK to generate
hum_stat. This is the definitive script for use in A1, removing the
' and leaving upper case the first letter on the text variables (air_quality, light and noise):
Code: Select all
#!/bin/bash
DOMO_IP="127.0.0.1" # Domoticz IP Address
DOMO_PORT="81" # Domoticz Port
AIRQ_IDX="20" # IDX for Virtual switch air_quality
LIGHT_IDX="21" # IDX for Virtual switch light
NOISE_IDX="22" # IDX for Virtual switch noise
TEMP_IDX="23" # IDX for Virtual switch temperature
HUM_IDX="23" # IDX for Virtual switch humidity
cd /domoticz/scripts/python/broadlink
function sensori {
python - <<END
import broadlink
import time
device = broadlink.a1(host=("A1-IP",80), mac=bytearray.fromhex("A1-MAC"))
device.auth()
sensors = device.check_sensors()
print sensors
END
}
# Call it and capture the output
SENSORI=$(sensori)
echo Sensores: $SENSORI
#
# Esempio output {'air_quality': 'excellent', 'light': 'dark', 'noise': 'quiet', 'temperature': 23.3, 'humidity': 48.0}
#
air_quality=$(echo $SENSORI | cut -d' ' -f2 - | tr -d ",'")
light=$(echo $SENSORI | cut -d' ' -f4 - | tr -d ",'")
noise=$(echo $SENSORI | cut -d' ' -f6 - | tr -d ",'")
temperature=$(echo $SENSORI | cut -d' ' -f8 - | tr -d ",'")
humidity=$(echo $SENSORI | cut -d' ' -f10 - | tr -d "}'")
#Treatment of the variables
air_quality=${air_quality^}
light=${light^}
noise=${noise^}
# Humidity_status peut être :
#
# 0=Normal
# 1=Confortable
# 2=Sec
# 3=Humide
# Ce paramètre est obligatoire, si vous ne savez pas quoi mettre, mettez 0
# is indeed the ranges from about 70% wet, below 30 Dry, between 30 and 45 Normal, and 45 and 70 comfortable.
#
hum_stat=$(awk '{if($1<30) print "2";else if($1>=30 && $1<45) print "0";else if($1>=45 && $1<=70) print "1";else if($1>70) print "3"}' <<< $humidity)
echo $air_quality
echo $light
echo $noise
echo $temperature
echo $humidity
echo $hum_stat
curl -s -i -H "Accept: application/json" "http://USER:PWD@$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$AIRQ_IDX&svalue="$air_quality""
curl -s -i -H "Accept: application/json" "http://USER:PWD@$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$LIGHT_IDX&svalue="$light""
curl -s -i -H "Accept: application/json" "http://USER:PWD@$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$NOISE_IDX&svalue="$noise""
curl -s -i -H "Accept: application/json" "http://USER:PWD@$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$TEMP_IDX&svalue="$temperature";"$humidity";"$hum_stat""
This is the output of the script:
Code: Select all
Sensores: {'air_quality': 'excellent', 'light': 'dark', 'noise': 'quiet', 'temperature': 25.5, 'humidity': 61.1}
Excellent
Dark
Quiet
25.5
61.1
1
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=eab2c6b52dc26bc6ae0a2155b2eb7c9e_YmY2YzM5YjktYzBlNC00M2JlLWJlNjUtMjdjYmFhYjg2NGI3.1485737119; path=/; Expires=Mon, 30 Jan 2017 00:45:19 GMT
{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=6af9a3dbf43daa1b5db9e43bc2dd67e1_MjJkMWM1N2UtZTc0Yi00Y2QwLTllYTQtZGZlYjQ3ZTc4MWY2.1485737119; path=/; Expires=Mon, 30 Jan 2017 00:45:19 GMT
{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=fd4308ffdaad925650aa44779d47fa64_MDVmZGJhYWItNjNiOC00ZDcyLTg1MmEtMTA0ZjRlOWQwY2Vj.1485737119; path=/; Expires=Mon, 30 Jan 2017 00:45:19 GMT
{
"status" : "OK",
"title" : "Update Device"
}
HTTP/1.1 200 OK
Content-Length: 53
Content-Type: application/json;charset=UTF-8
Cache-Control: no-cache
Pragma: no-cache
Access-Control-Allow-Origin: *
Set-Cookie: SID=e2ab149f8c3039b30b03eedd604705fa_NzM0YjVmYWUtN2MzZi00NjQ3LTg0MjEtOGE3ZjgxMDBmNjll.1485737119; path=/; Expires=Mon, 30 Jan 2017 00:45:19 GMT
{
"status" : "OK",
"title" : "Update Device"
}
Now the A1 works perfectly with Domoticz! I would like to thank everyone who helped and also to suggest an improvement for future versions of Domoticz: enable notifications on text sensors. If the sensor receives a certain text string, it will generate the configured notification. It would also be interesting to enable the possibility of changing the icon in the text sensors.