Inkbird IBS-M1 with IBS-P01

@Nir @Keeema
I have bought a Inkbird IBS M2 with the pool temperature sensor IBS P02R, and i used the python script from Keeema to retrieve data and was successfully (just had to change channel_id to ch_1 and ch_2).
I successfully convert the temperature data from the ch_1, which is the temperature from the pool sensor, but I’m having troubles converting the temperature values from the IBS M2 gateway, the values converted are not correct

I suppose the way data is encoded in this device is different from yours.
Could you tell me your how did you found how to decode the temperature data, so i can try to decode my, because i dont have idea how to do it

here some examples of the data (ch_0)

AQgBXgIAEA4AZA==

AQkBTgIAEA4AZA==

does this make sense?

i will put the https response in here, just in case.

{“result”:[{“id”:“bf71b6920027724e2atwmg”,“status”:[{“code”:“temp_current”,“value”:-200},{“code”:“temp_unit_convert”,“value”:“c”},{“code”:“signal_strength”,“value”:-200},{“code”:“ch_para”,“value”:“AAEBAQABCAEWHgAAAP//AAAA//8AAAD//wAAAP//AAAA//8AAAD//wAAAP//AAAA//8=”},{“code”:“ch_0”,“value”:“AQkBTgIAEA4AZA==”},{“code”:“ch_1”,“value”:“CAYB////////ZA==”},{“code”:“ch_2”,“value”:“”},{“code”:“ch_3”,“value”:“”},{“code”:“ch_4”,“value”:“”},{“code”:“ch_5”,“value”:“”},{“code”:“ch_6”,“value”:“”},{“code”:“ch_7”,“value”:“”},{“code”:“ch_8”,“value”:“”},{“code”:“ch_9”,“value”:“”},{“code”:“ch0_alarm”,“value”:0},{“code”:“ch1_alarm”,“value”:0},{“code”:“ch2_alarm”,“value”:0},{“code”:“ch3_alarm”,“value”:0},{“code”:“ch4_alarm”,“value”:0},{“code”:“ch5_alarm”,“value”:0},{“code”:“ch6_alarm”,“value”:0},{“code”:“ch7_alarm”,“value”:0},{“code”:“ch8_alarm”,“value”:0},{“code”:“ch9_alarm”,“value”:0},{“code”:“ch_cfg”,“value”:“WAIgA1gCIAOc/2QAnP9kAAAAAAAAAAAAAVgCIANYAiADnP9kAJz/ZAAAAAAAAAAAAAFYAiADWAIgA5z/ZACc/2QAAAAAAAAAAAABWAIgA1gCIAOc/2QAnP9kAAAAAAAAAAAAAVgCIANYAiADnP9kAJz/ZAAAAAAAAAAAAAFYAiADWAIgA5z/ZACc/2QAAAAAAAAAAAABWAIgA1gCIAOc/2QAnP9kAAAAAAAAAAAAAVgCIANYAiADnP9kAJz/ZAAAAAAAAAAAAAFYAiADWAIgA5z/ZACc/2QAAAAAAAAAAAABWAIgA1gCIAOc/2QAnP9kAAAAAAAAAAAAAQ==”},{“code”:“beep_status”,“value”:0},{“code”:“add_ch”,“value”:1},{“code”:“ch_setting_char”,“value”:0},{“code”:“alm_ch_rtd”,“value”:“AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA”}]}],“success”:true,“t”:1686563085648,“tid”:“c39738b4090511eebfbfa24bf1d21c99”}

@miguel.silvestre I suspect you are right. The conversion I found is likely unique for the pool sensor and not other sensors. It makes sense because pool temperature sensor will have different range than other sensors. i.e. it will only be above 0 degrees Celsius and will have no humidity data.

The way I found out how the conversion works is by studying it systematically and finding the patterns. I placed the thermometer in a warm glass of water and wrote the data from the sensor and the actual temperature. Then, every time the temperature changed by 0.1 of a degree I wrote those values again. Eventually I had enough values to figure out the pattern as I described above. I am not sure how you will have such fine control over non-pool sensors.

From you example, I suspect some similarities between the conversion methods, i.e. I suspect they use the unicode for Q and then an assigned value for ‘g’ and ‘k’ given that those are the same letters I found. What were the actual temperatures when the values were ‘AQgBXgIAEA4AZA==’ and ‘AQkBTgIAEA4AZA==’?

@lgnunes, I am not sure why but your data in ‘ch_rtd1’ is not like mine or other examples I saw. The relevant data in previous examples is in the beginning of the string whereas your data has no relevant data in the beginning. You do have a string ‘wAD1QAUBRQF’ later in ‘ch_rdt1’, but this string doesn’t make sense to me. Your ‘ch_rtd2’ doesn’t have any data.

Can you see the temperature correctly in the Inkbird app?

At the moment, I have no info on Inkbird app because there is no way to keep the sensor connected to Inkbird app and Tuya at the same time. But before i’ve connected to Tuya, the Inkbird app was showing the temperature correctly.

Is your sensor a pool thermometer? The script only works for those.

Yes, IBS-M1 with IBS-P01.

Hi @bortek i followed your instructions with a rtl_433 dongle and i believe in the rtl_433 next i see the ibs-p01 data coming
‘[rtl_433]
[rtl_433] time : 2023-06-13 21:49:32
[rtl_433] model : Inkbird-ITH20R
[rtl_433] id : 47826
[rtl_433] Battery : 100
[rtl_433] sensor_num: 3
[rtl_433] Integrity : CRC
[rtl_433] Temperature: 33.0 C
[rtl_433] Temperature2: 130.0 C
[rtl_433] Humidity : 130.0 %’

But now i dont have any clue how to go from there…I dont see any devices popping up, mqtt does not show entities or devices.

Can you help me out?

Not sure if this oke or causing issues…

Your code had been working for a while (and I was very happy). Now I face issue with value

A8YAAAAAAAAARgD//////////wAA//////////8AAP//////////AAD//////////wAA//////////8AAP//////////AAD//////////wAA//////////8AAP//////////AAD//////////wAA//////////8AAP//////////AAD//////////wAA//////////8AAP//////////AAD//////////wAA//////////8AAP//////////AAD//////////wAA//////////8AAP//////////AAD//////////wAA//////////8AAP//////////AA==

which is something like 19.8°.

But

ord(raw_temp_first_charecter)

is 56 so no temp_by_ten value is assigned

I’ve added else part I don’t understand why exactly this value:

#!/usr/bin/env python3
import json
import requests
import hmac
import hashlib
import time

debug = False

# Declare constants
ClientID="<<ENTER CLIENT ID HERE>>"
ClientSecret="<<ENTER CLIENT SECRET HERE>>"
DeviceID = "<<ENTER DEVICE ID HERE>>"
ChannelID = "<<ENTER DEVICE CHANNEL HERE e.g. ch_1 or ch_rtd1"
BaseUrl = "https://openapi.tuyaeu.com"
EmptyBodyEncoded = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"


# Character conversion dictionary for decoding the temperature value
charcter_conversion = {
    "A": 0, "E": 1, "I": 2, "M": 3, "Q": 4, "U": 5, "Y": 6, "c": 7,
    "g": 8, "k": 9, "o": 10, "s": 11, "w": 12, "0": 13, "4": 14, "8": 15
}

# Get current time in milliseconds
tuyatime = int(time.time()) * 1000

# Prepare signing for Access Token
URL = "/v1.0/token?grant_type=1"
StringToSign = f"{ClientID}{tuyatime}GET\n{EmptyBodyEncoded}\n\n{URL}"
AccessTokenSign = hmac.new(ClientSecret.encode(), StringToSign.encode(), hashlib.sha256).hexdigest().upper()

# Get Access Token
headers = {
    'client_id': ClientID,
    'sign_method': 'HMAC-SHA256',
    't': str(tuyatime),
    'sign': AccessTokenSign
}
response = requests.get(f"{BaseUrl}{URL}", headers=headers)
AccessToken = response.json()['result']['access_token']

# Send Device status request
URL = f"/v1.0/iot-03/devices/status?device_ids={DeviceID}"
StringToSign = f"{ClientID}{AccessToken}{tuyatime}GET\n{EmptyBodyEncoded}\n\n{URL}"
RequestSign = hmac.new(ClientSecret.encode(), StringToSign.encode(), hashlib.sha256).hexdigest().upper()

headers.update({
    'sign': RequestSign,
    'access_token': AccessToken
})

response = requests.get(f"{BaseUrl}{URL}", headers=headers)
RequestResponse = response.text

# Parse and process the request response
device_param = json.loads(RequestResponse)
number_of_status = len(device_param["result"][0]["status"])

for i in range(number_of_status):
    if device_param["result"][0]["status"][i]["code"] == ChannelID:
        raw_temp = device_param["result"][0]["status"][i]["value"]

# Decode the temperature value
raw_temp_lead_charecter = raw_temp[0:1]
raw_temp_first_charecter = raw_temp[1:2]
raw_temp_second_charecter = raw_temp[2:3]
raw_temp_third_charecter = raw_temp[3:4]

if raw_temp_lead_charecter == "C":
    temp_by_ten = (ord(raw_temp_first_charecter) - 65)*16 + charcter_conversion[raw_temp_second_charecter]

if raw_temp_lead_charecter == "A":
    # print(ord(raw_temp_first_charecter))
    if ord(raw_temp_first_charecter) <= 47:
        temp_by_ten = (ord(raw_temp_first_charecter) - 32)*16 + charcter_conversion[raw_temp_second_charecter]
    else:
        if ord(raw_temp_first_charecter) >= 119:
            temp_by_ten = (ord(raw_temp_first_charecter) - 119)*16 + charcter_conversion[raw_temp_second_charecter]
        else:
            temp_by_ten = (ord(raw_temp_first_charecter) - 44)*16 + charcter_conversion[raw_temp_second_charecter]    


if raw_temp_third_charecter == "B":
    temp_by_ten = temp_by_ten + 256

# Calculate and print the pool temperature
Pool_temp = temp_by_ten / 10
print(Pool_temp)

OK, and this had been working to 22.3°. For higher temperatures it started again from 17.6

From this point (I noticed that on 23.9) I had to add another else…

if raw_temp_lead_charecter == "C":
    temp_by_ten = (ord(raw_temp_first_charecter) - 65)*16 + charcter_conversion[raw_temp_second_charecter]

if raw_temp_lead_charecter == "A":
    if debug:
        print(ord(raw_temp_first_charecter))
    if ord(raw_temp_first_charecter) <= 43:
        temp_by_ten = (ord(raw_temp_first_charecter) - 29)*16 + charcter_conversion[raw_temp_second_charecter]
    else:
        if ord(raw_temp_first_charecter) <= 47:
            temp_by_ten = (ord(raw_temp_first_charecter) - 32)*16 + charcter_conversion[raw_temp_second_charecter]
        else:
            if ord(raw_temp_first_charecter) <= 118:
                temp_by_ten = (ord(raw_temp_first_charecter) - 44)*16 + charcter_conversion[raw_temp_second_charecter]
            else:
                temp_by_ten = (ord(raw_temp_first_charecter) - 119)*16 + charcter_conversion[raw_temp_second_charecter]
                    


if raw_temp_third_charecter == "B":
    temp_by_ten = temp_by_ten + 256

We must miss something…

This data has to be sent to somewhere and in my case (and most cases) it is sent to MQTT which will then populate devices and entities into the HASS. My rtl_433 config file is located and called like this

config/rtl_433/rtl_433.conf.template

output mqtt://${host}:${port},user=${username},pass=${password},retain=${retain}

output kv
verbose

protocol -2
protocol -59
protocol -60
protocol -82
protocol -85
protocol -88
protocol -89
protocol -90
protocol -95
protocol -110
protocol -123
protocol -128
protocol -133
protocol -140
protocol -141
protocol -156
protocol -168
protocol -180
protocol -186
protocol -201
protocol -203

protocol 194 # Inkbird ITH-20R temperature humidity sensor

and my logs of rtl_433 add-on are looking like this

[rtl_433] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[rtl_433] 
[rtl_433] time      : 2023-06-14 21:25:43
[rtl_433] model     : Inkbird-ITH20R
[rtl_433] id        : 16049
[rtl_433] Battery   : 0
[rtl_433] sensor_num: 3
[rtl_433] Integrity : CRC
[rtl_433] Temperature: 29.5 C
[rtl_433] Temperature2: 130.0 C
[rtl_433] Humidity  : 130.0 %
[rtl_433] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

hope this helps

@keeema, I know we are missing something - I have already wrote on the 28/5, after I suggested a solution, that “there is one problem with this system - if you start counting from w (unicode 119) for temp above 25.5, there are only 8 further increments you can do before getting to unicode 127, which doesn’t have a letter assigned. This means that the highest temp that can be expressed will be 38.3, which doesn’t make sense.”

Clearly, your system doesn’t follow the same rules as mine. To figure out the rules your system uses, we need more systemic data, as I said previously - “It will be useful to have more examples from your readings for temps < 23.9 and > 38.3.”. If you provide me with various values and their corresponding temperatures, I may be able to find out the logic.

@lgnunes, sorry, I don’t know why you are not getting data.

It’s okay, i’m trying to figure out myself. Which encode is this used on the device? Why A is 0, E is 1, etc?

I described the logic of the conversion in a post above from few weeks ago. I think they just decided to use that way, not sure why this particular conversation.

Hi, in the end it did help yes. thanks for that! I was too impatience, took some time to see the data coming in.

Do you have some mqtt sensor defined?
I see some other like:
mqtt:
binary_sensor:
- state_topic: “rtl_433/…/reed_open” #ellipses to obscure identifying info
name: “Bedroom External Door Status”
payload_on: “1”
payload_off: “0”
device_class: door

Hello,

can somebody tell me how to use / place the python script? i never worked with python :frowning:

I got an original ibs-m1 and p01r back in March 2021 for AUD $105.

I then replaced just the p01r for AUD $46 in November 2022 after it got damaged by a child throwing it.

I am finding that the newer p01r just goes through batteries way too quickly, like only lasting 3 weeks per set of batteries.

Given the poor battery life and the difficulties with the newer inkbird ibs-m1s talking to home assistant, I am starting to look around for alternatives.

I have found an alternative brand called ecowitt.

The floating pool thermometer model I am looking at is the wn36 and the wifi gateway model is GW1100.

The wn36 has a non removable battery due to the unit being hermetically sealed using “ultrasonic body welding” according to the manual.
The battery life is advertised as a minimum of 3 years or a maximum of 5 years if you put it to sleep for 6 months each year.

I assume the reason for the better battery life is due to the sample rate being 60 seconds, which I am completely fine with.

The price for these 2 together is AUD $116 delivered which is very close to what I originally paid for the inkbird gateway and thermometer bundle.

Anyone have experience or thoughts on this alternative before I decide to purchase?

Links:

https://www.ecowitt.com/shop/goodsDetail/252

https://www.ecowitt.com/shop/goodsDetail/107

1 Like

Hey guys, I figured out a way to decode my payload of the gateway. Looks like my sensor send a different string of yours, so that python code didn’t work. For those who are in the same situation, hope it helps! It’s a Node.js script (JavaScript), so you need to install it in your machine and run npm install at the root folder where the script is located.

I’ve created a GitHub repository with the script because it’s two files.GitHub - luizgununes/inkbird-ibs-m1-decoder: Script to retrieve temperature from IBS-P01 sensor with the IBS-M1 gateway.

Any doubts, reply this message.

I’ve never heard about this brand, but looking at the product description, looks like it’s easier to retrieve information from the sensor.

1 Like