pFenners / mijia-sensor-domoticz

69 stars 38 forks source link

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

Open ClementMarrast opened 4 years ago

ClementMarrast commented 4 years ago

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

ClementMarrast commented 4 years ago

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

Albertopnp commented 4 years ago

Checked right now. It works OK on both versions.

poseidogithub commented 4 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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 commented 1 year ago

Hi Albertopnp,

I'm not using domoticz anymore, even not theses sensors. It will be hard for me to check and test.

Le sam. 15 juil. 2023 à 03:47, Albertopnp @.***> a écrit :

Hi Clement,

I don't know if you have time to maintain this old script. I'm using it in my Domoticz and it is the only one I found supporting V1 and V2 sensors.

The domoticz request (line 106) is not working in the new Domoticz version due to security updates. Do you mind check it? I guess it is related to the new format of the API URLs (see here please: https://www.domoticz.com/wiki/Security)

I tried to make it work myself but I couldn't... not good enough at python...

If you have some time to check it that would be great. If you don't, no worries I will try to investigate myself during summer holidays.

Thanks and Regards

— Reply to this email directly, view it on GitHub https://github.com/pFenners/mijia-sensor-domoticz/pull/10#issuecomment-1636618617, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALGCSZXILTUU7FVUF3LWOS3XQHZBRANCNFSM4LE56ADA . You are receiving this because you were mentioned.Message ID: @.***>

Albertopnp commented 1 year ago

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 commented 1 year ago

Good to know, thanks for sharing!

Le mer. 19 juil. 2023 à 23:11, Albertopnp @.***> a écrit :

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!

— Reply to this email directly, view it on GitHub https://github.com/pFenners/mijia-sensor-domoticz/pull/10#issuecomment-1642764512, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALGCSZUZFG3MTGB4W34VH2TXRBEO3ANCNFSM4LE56ADA . You are receiving this because you were mentioned.Message ID: @.***>