Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Xiaomi sensors V1 and V2 (square form) #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ClementMarrast
Copy link

Add the support of V2 sensors by modifying function to specify the sensor version.

@ClementMarrast
Copy link
Author

I'm not able to check it's still working for V1 sensors. If someone can do that, it would be nice.
Thanks

@ClementMarrast ClementMarrast force-pushed the master branch 2 times, most recently from 5ba3ead to 04a6d2c Compare March 10, 2020 13:16
@Albertopnp
Copy link

Checked right now.
It works OK on both versions.

@poseidogithub
Copy link

poseidogithub commented Jul 24, 2020

very newbie here: so I guess with this modifications v2 (square ones) will work as confirmed by @Albertopnp , right?
what has to happen so this modifications are accepted on the main code? (I dont have a clue on how to use this code... sorry)

thanks!

@BoudewijnvanLangerak
Copy link

@pFenners Can this be merged on the master? I can do it for myself but @poseidogithub and probably some other people would like it.

@BoudewijnvanLangerak
Copy link

BoudewijnvanLangerak commented Jan 8, 2021

@ClementMarrast I have tried the code and added some extra logging for debugging purposes because I get an error.
I am not able to retrieve the temp and hum values:
Logging:
_1: updating
Polling: A4:C1:38:AC:82:49, 1506, 2
Poller created
Battery: 99%
Mi Sensor: A4:C1:38:AC:82:49
Firmware: 1.0.0_0109
Name: LYWSD03MMC
Battery: 99%
Traceback (most recent call last):
File "/home/pi/mijia-sensor-domoticz/domoticz_mijia.py", line 127, in
update("A4:C1:38:AC:82:49","1506", 2)
File "/home/pi/mijia-sensor-domoticz/domoticz_mijia.py", line 60, in update
print("Humidity: {}%".format(poller.parameter_value(MI_HUMIDITY)))
File "/home/pi/mijia-sensor-domoticz/mijia/mitemp2_bt_poller.py", line 134, in parameter_value
raise BluetoothBackendException("Could not read data from Mi Temp sensor %s" % self.mac)
btlewrap.base.BluetoothBackendException: Could not read data from Mi Temp sensor A4:C1:38:AC:82:49

Any suggestions what is happening? Maybe a newer Firmware with some changes in the parameters?

Hope you can help me.

Greetings,

Boudewijn

@ClementMarrast
Copy link
Author

@ClementMarrast I have tried the code and added some extra logging for debugging purposes because I get an error.
I am not able to retrieve the temp and hum values:
Logging:
_1: updating
Polling: A4:C1:38:AC:82:49, 1506, 2
Poller created
Battery: 99%
Mi Sensor: A4:C1:38:AC:82:49
Firmware: 1.0.0_0109
Name: LYWSD03MMC
Battery: 99%
Traceback (most recent call last):
File "/home/pi/mijia-sensor-domoticz/domoticz_mijia.py", line 127, in
update("A4:C1:38:AC:82:49","1506", 2)
File "/home/pi/mijia-sensor-domoticz/domoticz_mijia.py", line 60, in update
print("Humidity: {}%".format(poller.parameter_value(MI_HUMIDITY)))
File "/home/pi/mijia-sensor-domoticz/mijia/mitemp2_bt_poller.py", line 134, in parameter_value
raise BluetoothBackendException("Could not read data from Mi Temp sensor %s" % self.mac) btlewrap.base.BluetoothBackendException: Could not read data from Mi Temp sensor A4:C1:38:AC:82:49

Any suggestions what is happening? Maybe a newer Firmware with some changes in the parameters?

Hope you can help me.

Greetings,

Boudewijn

I'm running an older firmware :
Firmware: 1.0.0_0106

Can't tell you what's happening here. It seems to be more on Bluetooth side. Maybe the sensor is too far?

I've done an update for V2 sensors and negative temperature... It's getting cold now!
Now it's working great.

@BoudewijnvanLangerak
Copy link

Oke I have done some debugging. As far as I can see the fill_cache is called without an error but after that self.cache_available() is still false.... and the cache seems not to be filled.
The sensor is next to the pi.

Any suggestions?

@ClementMarrast
Copy link
Author

@BoudewijnvanLangerak I don't know, I didn't write this part of the code, I don't know what's happening behind.
Did you try to get the values from a phone using MijiaTemp application?

Using bluetoothctl, do you correctly see your Mijia from your Pi? The MAC address is correct?

Can't tell you more than these "classic" checks.

@BoudewijnvanLangerak
Copy link

Oke just to let you know. I used the MijiaTemp application from my phone didn't change anything to the script and now it works. I get the values. Not all the time but most of the times it just works. Made a cronjob for every single sensor because if a sensor does not respond the others are not called because of th error.
Thanks for de support.

@ClementMarrast
Copy link
Author

Good to know, thanks for the feedback.
On my side, I also have a no response sometime but it continues to check the next one. It just slow down the all process if many are not available.

@ClementMarrast
Copy link
Author

ClementMarrast commented Jul 19, 2023 via email

@Albertopnp
Copy link

Albertopnp commented Jul 19, 2023

Hi Clement,

Thanks for your answer. I undestand.

In fact I've found the solution. (That's why I removed my message).
Just in case somebody gets here with the same problem:
You need to add the following line to Domoticz - Settings - Security - Trusted Networks : 127.0.0.;192.168.1..
(or the IP address from your Domoticz).

I'm still using your script and It works really nice.
So I would like to take the oportunity to say to you: thanks for developping it!!.

Bonne continuation!

PS: by the way, thanks to pFenners as well!!

@ClementMarrast
Copy link
Author

ClementMarrast commented Jul 20, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants