SwitchBotAPI icon indicating copy to clipboard operation
SwitchBotAPI copied to clipboard

Curtain: inconsistent payload format & hubDeviceId & incorrect field values

Open whatUwant opened this issue 4 years ago • 3 comments

The following example consists of 6 consecutive payloads returned by the API in 5 seconds.

  1. [12/27/2020, 12:06:10 AM]

    {
      "statusCode": 100,
      "body": {
        "deviceId": "C65A75******",
        "deviceType": "Curtain",
        "hubDeviceId": "C3E770******",
        "calibrate": true,
        "group": false,
        "moving": false,
        "slidePosition": 0
      },
      "message": "success"
    }
    
  2. [12/27/2020, 12:06:11 AM]

    {
      "statusCode": 100,
      "body": {
        "deviceId": "C65A75******",
        "deviceType": "Curtain",
        "hubDeviceId": "C3E770******",
        "calibrate": true,
        "group": false,
        "moving": false,
        "slidePosition": 0
      },
      "message": "success"
    }
    
  3. [12/27/2020, 12:06:12 AM]

    {
      "statusCode": 100,
      "body": {
        "deviceId": "C65A75******",
        "deviceType": "Curtain",
        "hubDeviceId": "C3E770******",
        "calibrate": true,
        "group": false,
        "moving": false,
        "slidePosition": 0
      },
      "message": "success"
    }
    
  4. [12/27/2020, 12:06:13 AM]

    {
      "statusCode": 100,
      "body": {
        "deviceId": "C65A75******",
        "deviceType": "Curtain",
        "hubDeviceId": "C65A75******",
        "slidePosition": 100
      },
      "message": "success"
    }
    
  5. [12/27/2020, 12:06:14 AM]

    {
      "statusCode": 100,
      "body": {
        "deviceId": "C65A75******",
        "deviceType": "Curtain",
        "hubDeviceId": "C65A75******",
        "slidePosition": 100
      },
      "message": "success"
    }
    
  6. [12/27/2020, 12:06:14 AM]

    {
      "statusCode": 100,
      "body": {
        "deviceId": "C65A75******",
        "deviceType": "Curtain",
        "hubDeviceId": "C65A75******",
        "slidePosition": 100
      },
      "message": "success"
    }
    

Issues:

  • The fields calibrate group moving are present in the first 3 payloads but missing in the last 3
  • hubDeviceId changed from C3E770****** to C65A75****** while I have only one hub
  • The value of field slidePosition were 0, then suddenly jumped to 100 even though the curtain is still moving
  • The value of moving remains false even though the curtain is still moving

whatUwant avatar Dec 26 '20 22:12 whatUwant

Not exactly sure if these problems have been resolved. I think this issue should remain open.

whatUwant avatar Jan 05 '21 23:01 whatUwant

I am seeing similar problems. I am using the slide position field to determine if I should sent an open/close command or suppress it, to save on calls. The position field is unreliable however, sometimes indicating closed when opened or vice versa.

alamers avatar Jul 24 '21 19:07 alamers

I see that this problem has been addressed already in 2020. So I want to give my feedback as well. I work with home-assistant and google nest. With google-nest there is no issue, somehow the curtains close perfectly. I use Home Assistant for all my devices/automations, so that everything is central. I know I can work a way around this, but a correct working API would make me so much more happier :)

With Home Assistant I use the API, but then the following issue occurs:

  1. Curtains close perfectly
  2. Curtains close on 98/99% (which also is reported back)

When option 2 happens, there are 2 ways this can be solved:

  1. Open through home-assistant and close with Google Assistant, this works 50% of the time
  2. Recalibrate.

I've stopped with the commands TurnOn and TurnOff, since they have this issue more than when I use setPosition. With the app itself it seems to work perfectly. So it looks like a result of what @whatUwant is reporting here.

For complete info see the below code (Yaml):

rest_command:
  switchbot_device_command:
    url: 'https://api.switch-bot.com/v1.0/devices/{{ deviceId }}/commands'
    method: post
    content_type: 'application/json'
    headers:
      Authorization: !secret switchbot_api
    payload: '{"command": "{{ command }}","parameter": "{{ parameter }}"}'

sensor:
  - platform: rest
    name: 'Positie Woonkamer Gordijn'
    resource: !secret switchbot_woonkamergordijn_status_url
    method: GET
    scan_interval: 600
    headers:
      Authorization: !secret switchbot_api
      Content-Type: 'application/json'
    value_template: '{{ value_json.body.slidePosition }}'
    json_attributes_path: "$.body"
    json_attributes:
      - deviceId
      - deviceType
      - hubDeviceId
      - calibrate
      - group
      - moving
      - slidePosition

cover:
  - platform: template
    covers:
      bedroom_curtains:
        device_class: curtain
        friendly_name: "Woonkamergordijn"
        position_template: "{{ states('sensor.positie_woonkamer_gordijn') }}"
        open_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamergordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,0"
        close_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamergordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,100"
        stop_cover:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamergordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,100"
        set_cover_position:
          service: rest_command.switchbot_device_command
          data:
            deviceId: !secret switchbot_woonkamergordijn_deviceId
            command: "setPosition"
            parameter: "0,ff,{{position}}"

spiderwolf27 avatar Jan 31 '22 12:01 spiderwolf27