Comments (3)
you need to do use json= as the body in the post.
See my implementation below. You can ignore all the other nonsense in here, just look at my global variables and the api.post area. I have an alexa skill I develop for my home use as well as a watch app for my samsung watch so a lot of the hacky code in that function exists in support of those two considerations.
The unique token you obviously have already, and the device guids you have to query for with /devices get request.
import requests as api
botToken = 'INSERT YOUR PERSONAL TOKEN HERE'
botHeader = {'Authorization':botToken,'Content-Type':'application/json; charset=utf8'}
bedroomCurtain = 'INSERT UNIQUE DEVICE ID HERE'
livingroomCurtain = 'INSERT UNIQUE DEVICE ID HERE'
openCurtains = {'command':'turnOn'}
closeCurtains = {'command':'turnOff'}
def SwitchBotCommand(command):
command = command.lower()
if "living" in command:
localRoom = livingroomCurtain
localroomText = "living room"
elif "bed" in command:
localRoom = bedroomCurtain
localroomText = "bedroom"
else:
print("SwitchBot Problem: {} Is Not A Valid Room.".format(command))
return("Bad-You stated an invalid room, please try again.")
try:
if "open" in command:
data = api.post('https://api.switch-bot.com/v1.0/devices/{}/commands'.format(localRoom),headers=botHeader,json=openCurtains)
return("Good-Opening {} curtain.".format(localroomText))
elif "close" in command:
data = api.post('https://api.switch-bot.com/v1.0/devices/{}/commands'.format(localRoom),headers=botHeader,json=closeCurtains)
return("Good-Closing {} curtain.".format(localroomText))
else:
print("SwitchBot Problem: {} Is Not A Valid Command.".format(command))
return("Bad-You stated an invalid command, please try again.")
except Exception as E:
print("SwitchBot Error: {}".format(E))
return("Bad-There was an error talking to the SwitchBot.")
from switchbotapi.
That’s exactly it! Thanks.
my command changed to:
response = requests.post(url, headers=HEADERS, json=params)
from switchbotapi.
That’s exactly it! Thanks.
my command changed to:
response = requests.post(url, headers=HEADERS, json=params)
Very good :) you may want to mark your issue resolved and close at this point. TY
from switchbotapi.
Related Issues (20)
- SwitchBot Hub 2 Touch Buttons - On/Off State HOT 2
- About the keypad command parameter HOT 4
- API returns misleading success message with old readings for offline sensor HOT 4
- API document for Robot Vacuum shows wrong deviceType HOT 6
- Vacuum state in API shows clearing instead of cleaning HOT 2
- Getting no response after requesting device list
- Historical data for devices such as outdoor meters HOT 4
- Intermittent 500 internal server errors HOT 11
- Open single curtain (of 2 curtains grouped together) via API HOT 3
- Light Remote color and timer HOT 1
- [Keypad Touch] Send lock codes in response to Get Device Status
- [Keypad Touch] Delete Key command does not work HOT 1
- API Daily Limit HOT 4
- Support for s10 vacuum HOT 3
- Add support for K10+ vacuum HOT 2
- example java script to initiate a bot press
- Expand Switchbot API for Lock Pro HOT 1
- API 190 Error HOT 53
- Expose last update timestamp for device
- More Keypad Touch Webhook Events Required HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from switchbotapi.