#Switchbot API - need help with payload syntax

2 messages · Page 1 of 1 (latest)

strong saffron
#

Hello! I just picked up the Switchbot Evaporative Humidifier and am learning about the Switchbot API (and I am new to using APIs).

I am able to get the device to turn on and off via REST commands. Boy did that feel good when I finally got it to work! However I am unable to change the mode of the device. I have a feeling it's a syntax thing or I'm not including the parameter correctly.

This is what Switchbot's API documentation provides for commands:

deviceType
Humidifier2

commandType
command

Command
setMode

command parameter
{"mode": mode_int, "targetHumidify": humidity_int}

Description
set the mode. mode_int, 1, level 4; 2, level 3; 3, level 2; 4, level 1; 5, humidity mode;* 6*, sleep mode; 7, auto mode; 8, drying mode; targetHumidify, the target humidity level in percentage, 0~100.

This is the code I'm using - returns a "Success" message via Developer Tools/Actions but nothing happens!

yaml

  switchbotapi_humidifier_mode4:
    url: https://api.switch-bot.com/v1.1/devices/XXXXXXXXXXXXXX/commands
    method: POST
    headers:
      Authorization: "{{ states('input_text.switchbot_token') }}"
      sign: "{{ states('sensor.switchbot_sign') }}"
      t: "{{ state_attr('sensor.switchbot_sign','t') }}"
      Content-Type: "application/json"
      nonce: ""
    payload: '{"commandType": "command","command": "setMode","parameter":"7"}'
    content_type:  'application/json; charset=utf-8'

I'm using instructions from here: https://www.speaktothegeek.co.uk/2023/07/switchbot-api-v1-1-and-home-assistant/
And API documentation from here: https://github.com/OpenWonderLabs/SwitchBotAPI?tab=readme-ov-file#send-device-control-commands

Thanks y'all!

SwitchBot make a lot of very interesting and often unique gadgets, like the SwitchBot Curtain and my personal favourite the Blind Tilt. They also make a number of other devices and sensors, such as…

GitHub

SwitchBot Open API Documents. Contribute to OpenWonderLabs/SwitchBotAPI development by creating an account on GitHub.

strong saffron
#

I am certain the answer lies in the payload syntax... interestingly, various other configurations also return "SUCCESS"... but no version I've tried that includes {"mode": mode_int, "targetHumidify": humidity_int} works.