Using BROADLINK RM2 on DOMOTICZ

Compatibility (hardware, devices and OS)
aldodemi
Posts: 36
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by aldodemi » Tuesday 24 January 2017 10:01

Here a script to read A1 sensors, where 192.168.0.16 is the IP address for YOUR A1 and "XX YY ZZ KK JJ WW" is its mac address, varius xxxx_IDX the index for the virtual switchs in domoticz:

Code: Select all

#!/bin/bash
#
DOMO_IP="127.0.0.1"                     # Domoticz IP Address
DOMO_PORT="8080"                        # Domoticz Port
AIRQ_IDX="821"                          # IDX for Virtual switch air_quality
LIGHT_IDX="822"                         # IDX for Virtual switch light
NOISE_IDX="823"                         # IDX for Virtual switch noise
TEMP_IDX="819"                          # IDX for Virtual switch temperature
HUM_IDX="820"                           # IDX for Virtual switch humidity

cd /home/domoticz/domoticz/scripts/python/broadlink/

function sensori {
python - <<END
import broadlink
import time
device = broadlink.a1(host=("192.168.0.16",80), mac=bytearray.fromhex("XX YY ZZ KK JJ WW"))
device.auth()
sensors = device.check_sensors()
print sensors
END
}

# Call it and capture the output
SENSORI=$(sensori)
echo Sensori: $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 })

#/json.htm?type=command&param=udevice&idx=IDX&nvalue=HUM&svalue=HUM_STAT
# IDX =idx de votre capteur. A obtenir depuis l’écrans des dispositifs.
# HUM = Humidité: 45 par exemple pour 45%
# HUM_STAT = Humidity_status
# 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

hum_stat=0
#if [ $humidity<25 ]; then hum_stat=2; fi
#if [ $humidity>60 ]; then hum_stat=3; fi
#if [ $humidity>=25 && $humidity<=60 ]; then hum_stat=1; fi

case $humidity in
[0-25])
  hum_stat=2
  ;;
[26-60])
  hum_stat=1
  ;;
[61-100])
  hum_stat=3
  ;;
*)
  hum_stat=0
  ;;
esac

echo $air_quality
echo $light
echo $noise
echo $temperature
echo $humidity
echo $hum_stat

curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$AIRQ_IDX&svalue="$air_quality""
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$LIGHT_IDX&svalue="$light""
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$NOISE_IDX&svalue="$noise""
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$TEMP_IDX&svalue="$temperature""
Sensor hum_stat at the moment doesn't works...
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)

woody4165
Posts: 424
Joined: Monday 14 March 2016 14:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by woody4165 » Tuesday 24 January 2017 10:36

aldodemi wrote:Here a script to read RM2 temperature sensor, where 192.168.0.15 is the IP address for YOUR RM2 and "XX YY ZZ KK JJ WW" is its mac address, TEMP_IDX the index for the virtual switch in domoticz:
Grazie Aldo

You made my day, I was looking for something to solve the temp issue, after moving to the new way on managing the RM2...

deennoo
Posts: 897
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by deennoo » Tuesday 24 January 2017 11:57

all this great works will make easy a Python Plugin creation for Domoticz !

Does someone manage to drive Broadlink Plug ?

I made a how to base on this topic, in french : http://domo-attitude.fr/broadlink-rm-promini-domoticz/
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Wednesday 25 January 2017 0:59

Thank you aldodemi!!! Magic scripts! I'm new to Domoticz and i have a beginner question: it is possible to create dummy sensors or only dummy switches? In the dummy hardware i created to be able to use RM2, there is a button called create virtual sensors. When i use this button to create a temperature sensor for example, it is created in the temperature tab, but i can not edit any properties, just name, description and adjustment.

EDIT:

I got it!!! I read the Domoticz documentation and updated my sensors! I scheduled the scripts in CRON to run every minute and everything is OK, except hum_stat. Again, THANK YOU aldodemi for the scripts!!!
Last edited by moacir on Wednesday 25 January 2017 23:51, edited 1 time in total.

deennoo
Posts: 897
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: RE: Re: Using BROADLINK RM2 on DOMOTICZ

Post by deennoo » Wednesday 25 January 2017 11:37

aldodemi wrote:Here a script to read A1 sensors, where 192.168.0.16 is the IP address for YOUR A1 and "XX YY ZZ KK JJ WW" is its mac address, varius xxxx_IDX the index for the virtual switchs in domoticz:

Code: Select all

#!/bin/bash
#
DOMO_IP="127.0.0.1"                     # Domoticz IP Address
DOMO_PORT="8080"                        # Domoticz Port
AIRQ_IDX="821"                          # IDX for Virtual switch air_quality
LIGHT_IDX="822"                         # IDX for Virtual switch light
NOISE_IDX="823"                         # IDX for Virtual switch noise
TEMP_IDX="819"                          # IDX for Virtual switch temperature
HUM_IDX="820"                           # IDX for Virtual switch humidity

cd /home/domoticz/domoticz/scripts/python/broadlink/

function sensori {
python - <<END
import broadlink
import time
device = broadlink.a1(host=("192.168.0.16",80), mac=bytearray.fromhex("XX YY ZZ KK JJ WW"))
device.auth()
sensors = device.check_sensors()
print sensors
END
}

# Call it and capture the output
SENSORI=$(sensori)
echo Sensori: $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 })

#/json.htm?type=command&param=udevice&idx=IDX&nvalue=HUM&svalue=HUM_STAT
# IDX =idx de votre capteur. A obtenir depuis l’écrans des dispositifs.
# HUM = Humidité: 45 par exemple pour 45%
# HUM_STAT = Humidity_status
# 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

hum_stat=0
#if [ $humidity<25 ]; then hum_stat=2; fi
#if [ $humidity>60 ]; then hum_stat=3; fi
#if [ $humidity>=25 && $humidity<=60 ]; then hum_stat=1; fi

case $humidity in
[0-25])
  hum_stat=2
  ;;
[26-60])
  hum_stat=1
  ;;
[61-100])
  hum_stat=3
  ;;
*)
  hum_stat=0
  ;;
esac

echo $air_quality
echo $light
echo $noise
echo $temperature
echo $humidity
echo $hum_stat

curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$AIRQ_IDX&svalue="$air_quality""
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$LIGHT_IDX&svalue="$light""
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$NOISE_IDX&svalue="$noise""
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$TEMP_IDX&svalue="$temperature""
Sensor hum_stat at the moment doesn't works...
According api :

https://www.domoticz.com/wiki/Domoticz_ ... 2Fhumidity

Have you try to update only one device who get temp + hum + hum_stat ?

Code: Select all

/json.htm?type=command&param=udevice&idx=IDX&nvalue=0&svalue=TEMP;HUM;HUM_STAT
Will be

Code: Select all

curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$TEMP_IDX&svalue="$temperature";"$humidity";"$hum_stat"" 
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Wednesday 25 January 2017 18:35

Yes deennoo, i did it. But these lines not always forcing hum_stat to be 0 (normal)?

hum_stat=0
#if [ $humidity<25 ]; then hum_stat=2; fi
#if [ $humidity>60 ]; then hum_stat=3; fi
#if [ $humidity>=25 && $humidity<=60 ]; then hum_stat=1; fi


I'm still starting in shell script.

deennoo
Posts: 897
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by deennoo » Wednesday 25 January 2017 23:13

sorry didn't get A1 sensors

what answer

Code: Select all

http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$TEMP_IDX&svalue="$temperature";"$humidity";"$hum_stat"
from you browser ?

what is hum-stat ? add some print to get it, maybe value isn't good
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Wednesday 25 January 2017 23:42

I use separate temperature and humidity. My command for humidity is:

Code: Select all

curl -s -i -H "Accept: application/json" "http://myuser:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$HUM_IDX&nvalue="$humidity"&svalue=;"$hum_stat""
And the result:

Code: Select all

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=50c2a1b034ae5327c681d1c9668f7bfb_NzFjNjUzZTAtNjRkYi00ZjAzLTg5NzAtODM4OWYzMGVlZmU0.1485380559; path=/; Expires=Wed, 25 Jan 2017 21:42:39 GMT

{
   "status" : "OK",
   "title" : "Update Device"
}
And the result of the A1 readings:

Code: Select all

Sensores: {'air_quality': 'excellent', 'light': 'dark', 'noise': 'normal', 'temperature': 26.4, 'humidity': 59.7}
'excellent'
'dark'
'normal'
26.4
59.7
0
At the time of reading, the weather was rainy and the humidity is a bit higher. According to the script, for this value of humidity (59.7) should return state 1 (comfortable) and not 0 (normal) as it is occurring. The function on the script that returns the hum_stat according to the value of the humidity is not working.

deennoo
Posts: 897
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by deennoo » Wednesday 25 January 2017 23:55

have you remove # on

Code: Select all

#if [ $humidity<25 ]; then hum_stat=2; fi
#if [ $humidity>60 ]; then hum_stat=3; fi
#if [ $humidity>=25 && $humidity<=60 ]; then hum_stat=1; fi
who give

Code: Select all

if [ $humidity<25 ]; then hum_stat=2; fi
if [ $humidity>60 ]; then hum_stat=3; fi
if [ $humidity>=25 && $humidity<=60 ]; then hum_stat=1; fi
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Thursday 26 January 2017 0:06

Even removing the comment from these lines hum_stat remains equal to 0.

deennoo
Posts: 897
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by deennoo » Thursday 26 January 2017 0:07

you have to check if

if condition and if are correct, this part of script is python
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Thursday 26 January 2017 0:38

I did some tests here but with no success. Programming in scripts runs away from my knowledge, so i will keep this way. Having the humidity indication in percentage is already 99% of everything! Thanks deennoo for all helps!

aldodemi
Posts: 36
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by aldodemi » Thursday 26 January 2017 9:13

For HUM_STAT try modify the script this way:

Code: Select all

# 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=0
if [ $humidity<30 ]; then hum_stat=2; fi
if [ $humidity>=30 && $humidity<=45 ]; then hum_stat=0; fi
if [ $humidity>=45 && $humidity<=70 ]; then hum_stat=1; fi
if [ $humidity>70 ]; then hum_stat=3; fi
remote all code between "case" and "esac"
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)

hasan
Posts: 38
Joined: Saturday 31 October 2015 15:41
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by hasan » Thursday 26 January 2017 11:11

Hi guys,

I see big movement in RM2 integration. So I would like to ask somebody if can help me with integration switch TC2 (http://www.ibroadlink.com/tc2/) it is RF controlled switch.

Thanks for any idea.

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Thursday 26 January 2017 12:00

I'm at work now aldodemi and i can only test your code later. But i have good news for hasan. I use TC2 switches with Domoticz, which i used before with RM Bridge. The TC2 have a code to ON and another to OFF each gang. To clone the TC2 codes, it does a bit of work:

1) Install a TC2 normally with a RM2 (called "A") and the E-control app in a LOCAL net.
2) Install ANOTHER RM2 (called "B") in same E-control app (this other will only be used to clone the code with the RM Bridge).
3) Connect RM2 "B" to RM Bridge (you will need to know the mac of this RM2, so consult your router) and go to learn code page and at the same time open the app on the TC2 you want to copy.
4) Scan the frequency on RM Bridge while activating the TC2 in the app several times.
5) In RM Bridge, while placing RM2 "B" to clone codes, activate TC2 by the app in the gang you want to clone, remembering that each gang have two different codes (ON and OFF).

I did this way to clone all my TC2. In the first few tries it may not work, because when testing the cloned code, it may return an error message due to the size of the code. After a few tries you'll get the hang of it. My tip is to activate the cloning in the RM2 "B", wait around 2 seconds and then trigger the TC2 to be cloned, so that the code read is not out of the maximum size.

Good luck!

hasan
Posts: 38
Joined: Saturday 31 October 2015 15:41
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by hasan » Thursday 26 January 2017 13:03

moacir wrote:I'm at work now aldodemi and i can only test your code later. But i have good news for hasan. I use TC2 switches with Domoticz, which i used before with RM Bridge. The TC2 have a code to ON and another to OFF each gang. To clone the TC2 codes, it does a bit of work:

1) Install a TC2 normally with a RM2 (called "A") and the E-control app in a LOCAL net.
2) Install ANOTHER RM2 (called "B") in same E-control app (this other will only be used to clone the code with the RM Bridge).
3) Connect RM2 "B" to RM Bridge (you will need to know the mac of this RM2, so consult your router) and go to learn code page and at the same time open the app on the TC2 you want to copy.
4) Scan the frequency on RM Bridge while activating the TC2 in the app several times.
5) In RM Bridge, while placing RM2 "B" to clone codes, activate TC2 by the app in the gang you want to clone, remembering that each gang have two different codes (ON and OFF).

I did this way to clone all my TC2. In the first few tries it may not work, because when testing the cloned code, it may return an error message due to the size of the code. After a few tries you'll get the hang of it. My tip is to activate the cloning in the RM2 "B", wait around 2 seconds and then trigger the TC2 to be cloned, so that the code read is not out of the maximum size.

Good luck!
Nice... Thanks... I'll order second RM2 and try to do it... ;)

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Thursday 26 January 2017 15:22

Hi again aldodemi. I've tested your code with no success. I switched my sensor from only humidity to temperature + humidity and with the "old" script it was working OK, just forcing hum_stat = 0. My "new" code looks like this:

Code: Select all

#!/bin/bash

DOMO_IP="127.0.0.1"                     # Domoticz IP Address
DOMO_PORT="81"                          # Domoticz Port
AIRQ_IDX="18"                          # IDX for Virtual switch air_quality
LIGHT_IDX="19"                         # IDX for Virtual switch light
NOISE_IDX="20"                         # IDX for Virtual switch noise
TEMP_IDX="21"                          # IDX for Virtual switch temperature
HUM_IDX="21"                           # IDX for Virtual switch humidity

cd /domoticz/scripts/python/broadlink

function sensori {
python - <<END
import broadlink
import time
device = broadlink.a1(host=("my-ip",80), mac=bytearray.fromhex("my-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 })

# 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=0
if [ $humidity<30 ]; then hum_stat=2; fi								>>> LINE 46
if [ $humidity>=30 && $humidity<=45 ]; then hum_stat=0; fi		>>> LINE 47
if [ $humidity>=45 && $humidity<=70 ]; then hum_stat=1; fi		>>> LINE 48
if [ $humidity>70 ]; then hum_stat=3; fi

curl -s -i -H "Accept: application/json" "http://myuser:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$AIRQ_IDX&svalue="$air_quality""
curl -s -i -H "Accept: application/json" "http://myuser:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$LIGHT_IDX&svalue="$light""
curl -s -i -H "Accept: application/json" "http://myuser:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$NOISE_IDX&svalue="$noise""
curl -s -i -H "Accept: application/json" "http://myuser:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$TEMP_IDX&svalue="$temperature";"$humidity";"$hum_stat""
The texts >>> LINE 4X i included for your reference only, they are not in the script.

And the output looks like this:

Code: Select all

Sensores: {'air_quality': 'excellent', 'light': 'normal', 'noise': 'quiet', 'temperature': 24.8, 'humidity': 60.3}
/domoticz/scripts/python/broadlink/a1reads2.sh: line 46: 30: File or directory not found
/domoticz/scripts/python/broadlink/a1reads2.sh: line 47: [: missing `]'
/domoticz/scripts/python/broadlink/a1reads2.sh: line 48: [: missing `]'
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=f0817775507e8cfc4b141f09caf78a20_ZGM5MzE0MjYtZTZmNC00YWNhLWIwOTktYjkzOTM1ODIxMGM1.1485435650; path=/; Expires=Thu, 26 Jan 2017 13:00:50 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=9f0ebfb2d5662ce0e1289447c0c07a20_YWVlOGU1ZmYtNjU2Zi00YzkzLWE2NDctODI1NjU3ZTVhZTRm.1485435650; path=/; Expires=Thu, 26 Jan 2017 13:00:50 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=5c3f7dfc659c328eb4dcb83b3042fc68_ZmIxMDU4Y2YtOWQ0NC00MWViLWE0MTMtMWE1YWI5NDg5NWJj.1485435650; path=/; Expires=Thu, 26 Jan 2017 13:00:50 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=6c4c41789e0ef3f9eaf41ca4deb90ecf_MmRjMGZhZDAtZTQwMi00NDBlLTk0OTItZmZhMjFhMWM1OWY5.1485435650; path=/; Expires=Thu, 26 Jan 2017 13:00:50 GMT

{
   "status" : "OK",
   "title" : "Update Device"
}
The temperature and humidity sensor is updated OK, but now with status 3 (wet, wrong because it should be 1 for humidity = 60.3) and in /domoticz/scripts/python/broadlink three empty files are created: "=30", "=45" and "70".

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Monday 30 January 2017 2:42

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:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$AIRQ_IDX&svalue="$air_quality""
curl -s -i -H "Accept: application/json" "http://USER:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$LIGHT_IDX&svalue="$light""
curl -s -i -H "Accept: application/json" "http://USER:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$NOISE_IDX&svalue="$noise""
curl -s -i -H "Accept: application/json" "http://USER:[email protected]$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=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.

deennoo
Posts: 897
Joined: Wednesday 10 December 2014 14:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by deennoo » Monday 30 January 2017 8:22

Cool news,

Which device did you use text sensor ?
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / ESP8266 / MQTT / BLE
http://domo-attitude.fr

moacir
Posts: 11
Joined: Monday 23 January 2017 21:21
Target OS: Raspberry Pi
Domoticz version: V3.5877
Location: Curitiba - PR - BR
Contact:

Re: Using BROADLINK RM2 on DOMOTICZ

Post by moacir » Monday 30 January 2017 16:47

In Broadlink A1, for air quality sensor (variable air_quality in script), luminance (variable light in script) and noise (variable noise in the script), text-mode sensors are required in Domoticz, since they send text (eg. Excellent, Dark, Quiet etc.) rather than numbers or percentage.
Last edited by moacir on Tuesday 31 January 2017 5:18, edited 1 time in total.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests