Git Product home page Git Product logo

mijia-sensor-domoticz's Introduction

mijia-sensor-domoticz

Adapted version of miflora (https://github.com/Tristan79/miflora) for the Xiaomi Mijia Bluetooth Temperature Humidity Sensor (MJ_HT_V1).

The Xiaomi Mijia sensor provides temperature and humidity over BLE.

Preparing Domoticz

Create a virtual sensor (Temperature & Humidity) in Domoticz for each of your Xiaomi Mijia sensors.

Note down the IDX value for the virtual sensor.

Finding the Bluetooth MAC Address for the sensor

Turn on the sensor (insert battery).

Run the following command to find the MAC address:

sudo hcitool lescan

The address will be listed with the name 'MJ_HT_V1'

Note down the MAC Address for the sensor.

Edit the domoticz_mijia.py script

Enter your domoticz connection details in the varibles at the top of the script.

Edit the 'update' lines at the end of your script, enter the IDX and MAC address for each sensor.

e.g. update("4C:65:A8:D0:4C:98","752")

Schedule the polling

Enable this script to run at a regular interval (30 mins):

sudo crontab -e

And then add this line:

*/30 * * * * /usr/bin/python3 /home/pi/mijia-sensor-domoticz/domoticz_mijia.py >/dev/null 2>&1

mijia-sensor-domoticz's People

Contributors

pfenners avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mijia-sensor-domoticz's Issues

connect error: Transport endpoint is not connected (107)

I have set up MAX and ID but can't get the data
What I do wrong?

domoticz@housespririt:~/domoticz/plugins/mijia-sensor-domoticz$ sudo python3 domoticz_mijia.py

1: updating
connect error: Transport endpoint is not connected (107)

Reading Xiaomi temperature sensor v2

Hello
i try to read this kind of sensor with your code : https://www.banggood.com/fr/Newest-Version-XIAOMI-Mijia-Bluetooth-Thermometer-2-Wireless-Smart-Electric-Digital-Hygrometer-Thermometer-1Pcs-Work-with-Mijia-APP-p-1595119.html?gmcCountry=FR&currency=EUR&createTmp=1&utm_source=googleshopping&utm_medium=cpc_bgs&utm_content=frank&utm_campaign=ssc-fr-all-0716&ad_id=367115636049&gclid=CjwKCAiAu9vwBRAEEiwAzvjq-6pWtwVIoq_aZzaOPfZB-6hMEfc0_HjStrGWe1nLAs7WeRQfzApA9BoChNkQAvD_BwE&cur_warehouse=CN

But i have the following result:

 python3 domoticz_mijia.py 
1: updating
Characteristic value/descriptor read failed: Request attribute has encountered an unlikely error
Characteristic Write Request failed: Attribute can't be written
Error reading value retry after 5 seconds...

Is this sensor supported ?
Thanks

Mijia temperature sensor

Hello friend are you able to put it work ?
My one stay block on Updating 1: and don't do anything, can you help me ? thanks.

Bluetooth crash

After the some request the bluetooth crashes Different errors e.g.:
connect: Device or resource busy (16)
What can I do?

Characteristic value/descriptor read failed: Invalid handle

I had to add #! /usr/bin/python3 to the script to get it to execute at all.

Now I am getting:
./domoticz_mijia.py
./domoticz_mijia.py:24: DeprecationWarning: encodestring() is a deprecated alias since 3.1, use encodebytes()
base64string = base64.encodestring(('%s:%s' % (domoticzusername, domoticzpassword)).encode()).decode().replace('\n', '')

1: updating
Characteristic value/descriptor read failed: Invalid handle
Characteristic value/descriptor read failed: Invalid handle
Characteristic value/descriptor read failed: Invalid handle
Characteristic value/descriptor read failed: Invalid handle
Error reading value retry after 5 seconds...

Changing encodestring to encodebytes gets rid of the deprecation warning, but nets the same consecutive errors.

error

Hello! Thanks for the script!

Can you help with solving the problem?
When I run the script, the sensor gives the correct data, and then errors appear.

Can you help me figure out what the problem is?

P.S. The script miflora works without any problems..

1: updating
Mi Sensor: 4C:65:A8:DD:66:33
Firmware: 00.00.66
Name: MJ_HT_V1
Temperature: 24.0°C
Humidity: 39.7%
Battery: 90%
http://127.0.0.1:8000/json.htm?type=command&param=udevice&idx=41&nvalue=0&svalue=24.0;39.7;2&battery=90
Traceback (most recent call last):
File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
h.request(req.get_method(), req.selector, req.data, headers)
File "/usr/lib/python3.5/http/client.py", line 1107, in request
self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1152, in _send_request
self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1103, in endheaders
self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
self.send(msg)
File "/usr/lib/python3.5/http/client.py", line 877, in send
self.connect()
File "/usr/lib/python3.5/http/client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.5/socket.py", line 712, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 703, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "domoticz_mijia.py", line 92, in
update("4C:65:A8:DD:66:33","41")
File "domoticz_mijia.py", line 88, in update
domoticzrequest("http://" + domoticzserver + "/json.htm?type=command&param=udevice&idx=" + idx_temp + "&nval ue=0&svalue=" + val_temp + ";" + val_hum + ";"+ val_comfort + "&battery=" + val_bat)
File "domoticz_mijia.py", line 29, in domoticzrequest
response = urllib.request.urlopen(request)
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 466, in open
response = self._open(req, data)
File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
'_open', req)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

ModuleNotFoundError

When I try to run the script I get:

Traceback (most recent call last):
File "domoticz_mijia.py", line 5, in
from mijia.mijia_poller import MijiaPoller,
ModuleNotFoundError: No module named 'mijia'

mijia_poller.py is present in the same directory

error

the last file include is ok? no syncronizing

Get historical data

Is it possible to get historical data from the Mijia Temp sensor?

Or it is only possible to get current values?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.