0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
206 stars 58 forks source link

I added support for the plant sensor that I have #423

Open nequam opened 6 months ago

nequam commented 6 months ago

Device Infomation JSON File

{
      "activeTime": 1702923560,
      "category": "zwjcy",
      "createTime": 1702923252,
      "customName": "Tree",
      "icon": "smart/icon/ay1545813662186VvWHx/70ea6bda8e2a8d541a97191cc4b97beb.jpg",
      "id": "stuff",
      "ip": "",
      "isOnline": true,
      "lat": "xxx",
      "localKey": "",
      "lon": "xxx",
      "model": "QT-07S-Zigbee",
      "name": "Soil sensor",
      "productId": "myd45weu",
      "productName": "强泰温湿度检测器",
      "sub": true,
      "timeZone": "-05:00",
      "updateTime": 1702923649,
      "uuid": ""
    },

{
  "modelId": "00000492q4",
  "services": [
    {
      "actions": [],
      "code": "",
      "description": "",
      "events": [],
      "name": "默认服务",
      "properties": [
        {
          "abilityId": 3,
          "accessMode": "ro",
          "code": "humidity",
          "description": "",
          "extensions": {
            "iconName": "icon-shidu",
            "attribute": "1152",
            "trigger": "direct"
          },
          "name": "湿度",
          "typeSpec": {
            "max": 100,
            "min": 0,
            "scale": 0,
            "step": 1,
            "type": "value",
            "typeDefaultValue": 0,
            "unit": "%"
          }
        },
        {
          "abilityId": 5,
          "accessMode": "ro",
          "code": "temp_current",
          "description": "",
          "extensions": {
            "iconName": "icon-dp_c",
            "attribute": "1152",
            "trigger": "direct"
          },
          "name": "当前温度",
          "typeSpec": {
            "max": 70,
            "min": -30,
            "scale": 0,
            "step": 1,
            "type": "value",
            "typeDefaultValue": -30,
            "unit": "℃"
          }
        },
        {
          "abilityId": 9,
          "accessMode": "rw",
          "code": "temp_unit_convert",
          "description": "",
          "extensions": {
            "iconName": "icon-dp_mode",
            "attribute": "1152"
          },
          "name": "温标切换",
          "typeSpec": {
            "range": [
              "c",
              "f"
            ],
            "type": "enum",
            "typeDefaultValue": "c"
          }
        },
        {
          "abilityId": 14,
          "accessMode": "ro",
          "code": "battery_state",
          "description": "",
          "extensions": {
            "iconName": "icon-dp_battery",
            "attribute": "1152",
            "trigger": "direct"
          },
          "name": "电池电量状态",
          "typeSpec": {
            "range": [
              "low",
              "middle",
              "high"
            ],
            "type": "enum",
            "typeDefaultValue": "low"
          }
        },
        {
          "abilityId": 15,
          "accessMode": "ro",
          "code": "battery_percentage",
          "description": "",
          "extensions": {
            "iconName": "icon-dp_battery",
            "attribute": "1152",
            "trigger": "direct"
          },
          "name": "电池电量",
          "typeSpec": {
            "max": 100,
            "min": 0,
            "scale": 0,
            "step": 1,
            "type": "value",
            "typeDefaultValue": 0,
            "unit": "%"
          }
        }
      ]
    }
  ]
}

Detail Informations

I am not all that familiar with characteristics, ultimately mapped the humidity to accessory.Service.HumiditySensor / Characteristic.CurrentRelativeHumidity I mapped the battery level to Service.AccessoryInformation / accessory.Characteristic.BatteryLevel I used the existing CurrentTemperature.ts for the temperature.

I used: case 'zwjcy': handler = new SoilAccessory(platform, accessory); break;

I don't do much with TS normally, but it's pretty simple. It's the characteristic stuff, which ones to use, not sure of. This is funny, because the soil humidity needs to be WAY higher than air humidity, so looks funny in homekit.

I forked the repository, checked it in, forgot to branch it, but feel free to take anything. I just wanted to make the sensor work for a rule to remind people to water a plant and I needed it to talk to non-tuya stuff. I hope I gave you enough information.

https://github.com/nequamus/homebridge-tuya-platform-more

0x5e commented 6 months ago

Thanks @nequam , that's great!

I've seen your commit:

  1. There's already have battery value code in BaseAccessory.ts, you can add 'battery_value' to BATTERY_PERCENT directly.
  2. And there has CurrentRelativeHumidity.ts too :)

Would you like to create a pr for this? Or I will do this later. Thanks again!

nequam commented 1 month ago

Sorry to take so long to get back to you. I’ll cycle back this over the weekend, resync with your code base, and then make sure the changes all work. I’ll fix the way that I fork/branch/build, I’ve been focused on understanding how it works in GitHub and setting up the build process. (Our office is moving to GitHub). I use a couple of RPI4s and setting up an RPI5 Saturday.

As stupid as this sounds, I had no clue what a PR was, I am new to doing things in open source/git hub land. Anyway, I’ll figure it all out and let you know when I’m done.

Note: The best way to get me to do something is nag.. I have about 3 times as many things I want to do as I have time for, and tend to gravitate towards whatever beeps the loudest.