windkh / node-red-contrib-shelly

Shelly control nodes for node red.
MIT License
31 stars 21 forks source link

Shelly BLU Door/Window #164

Open runcioa opened 2 weeks ago

runcioa commented 2 weeks ago

I can't understand if it's already possibile to retrive Shelly BLU Window data from a node of a plus device. In my case the Shelly BLU Window is connected via a Shelly Plus 1 Mini Gen3.

windkh commented 2 weeks ago

Hm good question ... never tried that... I will check it out

windkh commented 2 weeks ago

@runcioa I guess that is doable. I need to find out first if I can detect if the bluetooth server is active in a shelly

windkh commented 2 weeks ago

@windkh /rpc/BTHome.GetStatus contains an error property if bthome is not enabled { "errors": [ "observer_disabled" ] }

runcioa commented 2 weeks ago

I enable the BTHome and registered the device on components via mac address,

Component_Configuration

If i try:

curl -X POST -d '{"id":1,"method":"BTHomeSensor.GetStatus","params":{"id":200}}' http://192.168.2.41/rpc The json response is:

{
  "id": 1,
  "src": "shelly1minig3-ecda3bc252b0",
  "result": {
    "id": 200,
    "value": false,
    "last_updated_ts": 1720552148
  }
}

"BTHomeSensor.GetStatus","params":{"id":200} identify the windows and if response value is true the windows is open otherwise is false

curl -X POST -d '{"id":1,"method":"BTHomeSensor.GetStatus","params":{"id":201}}' http://192.168.2.41/rpc this is rotation and the response is:

{
  "id": 1,
  "src": "shelly1minig3-ecda3bc252b0",
  "result": {
    "id": 201,
    "value": 4.7,
    "last_updated_ts": 1720552422
  }
}

The value 4.7 is degree angle.

And so on.

runcioa commented 2 weeks ago

If i make a post request like this:

{
  "id": 1,
  "method": "BTHomeDevice.GetKnownObjects",
  "params": {
    "id": 200
  }
}

the response is:

{
  "id": 1,
  "src": "shelly1minig3-ecda3bc252b0",
  "result": {
    "id": 200,
    "objects": [
      {
        "obj_id": 45,
        "idx": 0,
        "component": "bthomesensor:200"
      },
      {
        "obj_id": 63,
        "idx": 0,
        "component": "bthomesensor:201"
      },
      {
        "obj_id": 5,
        "idx": 0,
        "component": "bthomesensor:202"
      },
      {
        "obj_id": 1,
        "idx": 0,
        "component": "bthomesensor:203"
      },
      {
        "obj_id": 58,
        "idx": 0,
        "component": "bthomesensor:204"
      }
    ]
  }
}

With an obj_id you can use it to make a request with method BTHome.GetObjectInfos

{
  "id": 1,
  "method": "BTHome.GetObjectInfos",
  "params": {
    "obj_ids": [
      45,
      63,
      5,
      1
    ]
  }
} 

and the result is:

{
  "id": 1,
  "src": "shelly1minig3-ecda3bc252b0",
  "result": {
    "objects": [
      {
        "obj_id": 45,
        "obj_name": "window",
        "type": "binary_sensor",
        "unit": ""
      },
      {
        "obj_id": 63,
        "obj_name": "rotation",
        "type": "sensor",
        "unit": "°"
      },
      {
        "obj_id": 5,
        "obj_name": "illuminance",
        "type": "sensor",
        "unit": "lux"
      },
      {
        "obj_id": 1,
        "obj_name": "battery",
        "type": "sensor",
        "unit": "%"
      }
    ],
    "offset": 0,
    "count": 4,
    "total": 4
  }
}
windkh commented 2 weeks ago

Well, the question is. Is it compatible with the blugateway or is it just another way to communicate with bt devices.

runcioa commented 2 weeks ago

I don't have a blugateway, so i can't try. The solution that i find for me is ok, because on nodered i make a simple POST request and I have the value of BT sensor.

The Bluegateway require a callback, i think is a bit more compicated.

runcioa commented 2 weeks ago

I have another solution that require only one Post Request:

{
  "id": 1,
  "method": "Shelly.GetComponents"
}

the complete response is:

{
  "id": 1,
  "src": "shelly1minig3-ecda3bc252b0",
  "result": {
    "components": [
      {
        "key": "ble",
        "status": {},
        "config": {
          "enable": true,
          "rpc": {
            "enable": true
          },
          "observer": {
            "enable": true
          }
        }
      },
      {
        "key": "bthome",
        "status": {},
        "config": {}
      },
      {
        "key": "bthomedevice:200",
        "status": {
          "id": 200,
          "rssi": -72,
          "battery": 100,
          "packet_id": 90,
          "last_updated_ts": 1720634555
        },
        "config": {
          "id": 200,
          "addr": "38:39:8f:74:b1:4f",
          "name": null,
          "key": null,
          "meta": {
            "ui": {
              "view": "Last updated",
              "icon": null
            }
          }
        }
      },
      {
        "key": "bthomesensor:200",
        "status": {
          "id": 200,
          "value": 100,
          "last_updated_ts": 1720634555
        },
        "config": {
          "id": 200,
          "addr": "38:39:8f:74:b1:4f",
          "name": "Battery",
          "obj_id": 1,
          "idx": 0,
          "meta": {
            "ui": {
              "icon": null
            }
          }
        }
      },
      {
        "key": "bthomesensor:201",
        "status": {
          "id": 201,
          "value": 22.00,
          "last_updated_ts": 1720634555
        },
        "config": {
          "id": 201,
          "addr": "38:39:8f:74:b1:4f",
          "name": " illuminance",
          "obj_id": 5,
          "idx": 0,
          "meta": {
            "ui": {
              "icon": null
            }
          }
        }
      },
      {
        "key": "bthomesensor:202",
        "status": {
          "id": 202,
          "value": false,
          "last_updated_ts": 1720634555
        },
        "config": {
          "id": 202,
          "addr": "38:39:8f:74:b1:4f",
          "name": null,
          "obj_id": 45,
          "idx": 0,
          "meta": null
        }
      },
      {
        "key": "bthomesensor:203",
        "status": {
          "id": 203,
          "value": 0.0,
          "last_updated_ts": 1720634555
        },
        "config": {
          "id": 203,
          "addr": "38:39:8f:74:b1:4f",
          "name": null,
          "obj_id": 63,
          "idx": 0,
          "meta": null
        }
      },
      {
        "key": "cloud",
        "status": {
          "connected": true
        },
        "config": {
          "enable": true,
          "server": "shelly-35-eu.shelly.cloud:6022/jrpc"
        }
      },
      {
        "key": "input:0",
        "status": {
          "id": 0,
          "state": false
        },
        "config": {
          "id": 0,
          "name": null,
          "type": "switch",
          "enable": true,
          "invert": false,
          "factory_reset": true
        }
      },
      {
        "key": "mqtt",
        "status": {
          "connected": true
        },
        "config": {
          "enable": true,
          "server": "192.168.2.60:1883",
          "client_id": "shelly1minig3-ecda3bc252b0",
          "user": null,
          "ssl_ca": null,
          "topic_prefix": "shelly1minig3-ecda3bc252b0",
          "rpc_ntf": false,
          "status_ntf": false,
          "use_client_cert": false,
          "enable_rpc": false,
          "enable_control": true
        }
      },
      {
        "key": "script:1",
        "status": {
          "id": 1,
          "running": false,
          "mem_free": 25200
        },
        "config": {
          "id": 1,
          "name": "abc",
          "enable": false
        }
      },
      {
        "key": "script:2",
        "status": {
          "id": 2,
          "running": false,
          "mem_free": 25200
        },
        "config": {
          "id": 2,
          "name": "script_2",
          "enable": false
        }
      },
      {
        "key": "switch:0",
        "status": {
          "id": 0,
          "source": "SHC",
          "output": false,
          "temperature": {
            "tC": 59.1,
            "tF": 138.4
          }
        },
        "config": {
          "id": 0,
          "name": null,
          "in_mode": "follow",
          "initial_state": "match_input",
          "auto_on": false,
          "auto_on_delay": 60.00,
          "auto_off": false,
          "auto_off_delay": 60.00
        }
      }
    ],
    "cfg_rev": 331,
    "offset": 0,
    "total": 16
  }
}

with all parameters (name and value) that i need.

windkh commented 2 weeks ago

Good idea. So the only thing to find out is how the shelly will forward the changes in the sensor data like for the callback mode...