SwitchBotAPI
SwitchBotAPI copied to clipboard
Curtain: inconsistent payload format & hubDeviceId & incorrect field values
The following example consists of 6 consecutive payloads returned by the API in 5 seconds.
-
[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" }
-
[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" }
-
[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" }
-
[12/27/2020, 12:06:13 AM]
{ "statusCode": 100, "body": { "deviceId": "C65A75******", "deviceType": "Curtain", "hubDeviceId": "C65A75******", "slidePosition": 100 }, "message": "success" }
-
[12/27/2020, 12:06:14 AM]
{ "statusCode": 100, "body": { "deviceId": "C65A75******", "deviceType": "Curtain", "hubDeviceId": "C65A75******", "slidePosition": 100 }, "message": "success" }
-
[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 fromC3E770******
toC65A75******
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
remainsfalse
even though the curtain is still moving
Not exactly sure if these problems have been resolved. I think this issue should remain open.
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.
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:
- Curtains close perfectly
- Curtains close on 98/99% (which also is reported back)
When option 2 happens, there are 2 ways this can be solved:
- Open through home-assistant and close with Google Assistant, this works 50% of the time
- 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}}"