marcosav / fermax-blue-intercom

Fermax Blue script to open the door
19 stars 4 forks source link

device ID and Access ID? #1

Closed dacorde closed 1 year ago

dacorde commented 1 year ago

Thanks a lot for this script!! I have it already working in HA (9449 model too) but it opens 1 of the 2 doors I have, so I suppose I would need device id and also access ID per each door. Please how could I obtain it?

marcosav commented 1 year ago

Hi @dacorde, you can use the /pairing endpoint for that.

First authenticate to get a token:

curl --location 'https://oauth.blue.fermax.com/oauth/token' \
--header 'Authorization: Basic ZHB2N2lxejZlZTVtYXptMWlxOWR3MWQ0MnNseXV0NDhrajBtcDVmdm81OGo1aWg6Yzd5bGtxcHVqd2FoODV5aG5wcnYwd2R2eXp1dGxjbmt3NHN6OTBidWxkYnVsazE=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=password' \
--data-urlencode 'password=yourpassword' \
--data-urlencode 'username=email@domain.com'

Which will output this:

{
    "access_token": "your_token",
    "token_type": "bearer",
    "refresh_token": "another_token_im_not_using",
    "expires_in": 345599,
    "scope": "user",
    "jti": "more_data"
}

Take the access_token value, and use it here, in the Authorization header:

curl --location 'https://blue.fermax.com/pairing/api/v3/pairings/me' \
--header 'Authorization: Bearer <your_token>'

This will output your devices, in my case there's just one, and I have one available door (the one the script opens, "ZERO"), but it shows three doors, I don't know much about what its content stands for:

[
    {
        "id": "an UUID you don't need",
        "deviceId": "2XXXXXXXXXXXXXXXXXXXXXXX", // deviceId
        "tag": "",
        "status": "PAIRED",
        "updatedAt": 100000,
        "createdAt": 100000,
        "appBuild": 100,
        "appVersion": "",
        "phoneModel": "",
        "phoneOS": "",
        "home": null,
        "address": null,
        "accessDoorMap": { // Doors containing the accessId
            "ZERO": {
                "title": "",
                "accessId": {
                    "block": 100,
                    "subblock": -1,
                    "number": 0
                },
                "visible": true
            },
            "ONE": {
                "title": "",
                "accessId": {
                    "block": 100,
                    "subblock": -1,
                    "number": 1
                },
                "visible": false
            },
            "GENERAL": {
                "title": "",
                "accessId": {
                    "block": 100,
                    "subblock": -1,
                    "number": 0
                },
                "visible": false
            }
        },
        "master": true
    }
]

If you have two doors I don't know what the accessDoorMap will contain, let me know, so I can improve the script.

marcosav commented 1 year ago

I have just added support for opening multiple doors at once by providing multiple accessId, it may be useful for you.

dacorde commented 1 year ago

Gracias, Marcos! I got IDs (big thanks!) but now I am struggling with shell command in HA. I previously had it working only with username and password, but trying to add device and access ids it does not work. I updated open_door.py as well with your multidoors version. So I suppose I am not writting it well:

shell_command: open_door_portal: 'python3 python_scripts/open_door.py --username=xxxxxxxx@gmail.com --password=ABCDE12345. [--deviceId XXXXXXXXXXXXXXXXX] [--accessId ACCESSID_JSON [{"subblock": -x, "block": xxx, "number": X}]]' open_door_calle: 'python3 python_scripts/open_door.py --username=xxxxxxxx@gmail.com --password=ABCDE12345. [--deviceId XXXXXXXXXXXXXXXXX] [--accessId ACCESSID_JSON [{“block”: xxx,”subblock”: -x,”number”: x}]]'

marcosav commented 1 year ago

Hi!, it may be the format, it's a little bit tricky, here's how I have it in my config:

shell_command:
  abrir_portal: 'python3 python_scripts/open_door.py --username email --password pass --deviceId 12345 --accessId "{\"subblock\": 0,\"block\": 0,\"number\": 0}"'

Make sure you escape the JSON's double quotes.

dacorde commented 1 year ago

Working!! The format above adding "=" is perfect.

shell_command:
  open_door_portal: 'python3 python_scripts/open_door.py --username=email --password=pass --deviceId=12345 --accessId="{\"subblock\": -1,\"block\": 200,\"number\": 0}"'
yawor commented 1 year ago

Hi @marcosav , I just wanted to add this info here, as you've mentioned that you only have a single door. Where I live, there are 7 buildings with a single door and 4 gates from the street. From the Blue app I can connect to the cameras only on entrance to my building and the closest gate, I can also open these directly without connecting to the cameras. The API returns following JSON object for accessDoorMap:

{
      "ZERO": {
        "title": "Building door",
        "accessId": { "block": 200, "subblock": -1, "number": 0 },
        "visible": true
      },
      "ONE": {
        "title": "Door 3",
        "accessId": { "block": 200, "subblock": -1, "number": 1 },
        "visible": false
      },
      "GENERAL": {
        "title": "Fence gate",
        "accessId": { "block": 100, "subblock": -1, "number": 0 },
        "visible": true
      }

The visible property doesn't depend on the installation, but it's a setting from the Blue application, whether a specific door is enabled or not. This is actually saved on the server. You can also set your own door names in the Blue app (the title property).

I think I may try to do some tests if it's possible to open doors other than these two by trying other block and number values.

viseniv commented 2 months ago

I think this must be on the readme. Now i can open 2 doors with one command through HomeAssistant