Integration with the Sunsa Wand Cloud API using REST Commands
In the Sunsa mobile app, you can turn on cloud API access and copy your secret API key, but for some reason, the app doesn’t give you access to your numeric User ID which is also necessary when calling the API. If you’re reading this and your User ID still doesn’t show up in the app, you will need to send them a message from the email address on your account to ask them for it. It can look something like this:
To: [email protected]
Subject: What's my User ID?
Hello,
Can I please have the numeric user ID that goes with my API key?
I'm trying to use Home Assistant for controlling my blinds and until a local control API is available, I'm following the instructions here: https://community.home-assistant.io/t/sunsa-wand-for-mini-blinds-and-vertical-blinds/370564
Thank you!
Next, you will need to find the Device ID associated with your specific wand(s). That can easily be found on the details page for your wand in the app.
Once you have your User ID, Device ID, and API key, you will use those three things to craft the API URL for each wand like this:
https://sunsahomes.com/api/public/123/devices/456?publicApiKey=123456789-1234-12345-1234-123456789abcd
Replace 123
with your User ID, and 456
with your device ID. The string at the end is obviously your API key
Since your API key needs to remain a secret, the URL(s) will need to be stored in your secrets file. I use the names “north” and “east” on my wands to indicate which window they’re attached to. Example secrets.yaml
:
sunsa_api_north: https://sunsahomes.com/api/public/123/devices/456?publicApiKey=123456789-1234-12345-1234-123456789abcd
sunsa_api_east: https://sunsahomes.com/api/public/123/devices/789?publicApiKey=123456789-1234-12345-1234-123456789abcd
Next, create REST commands in the Home Assistant config file for each wand. From there, a template cover
can be created for each wand that calls the REST command service each time open or close is called. Here’s my configuration.yaml:
rest_command:
sunsa_north:
url: !secret sunsa_api_north
method: PUT
headers:
accept: 'application/json'
payload: '{"Position": {{ position }}}'
content_type: 'application/json'
sunsa_east:
url: !secret sunsa_api_east
method: PUT
headers:
accept: 'application/json'
payload: '{"Position": {{ position }}}'
content_type: 'application/json'
cover:
- platform: template
covers:
north_blinds:
unique_id: living_room_blinds_north
friendly_name: North Blinds
device_class: blind
open_cover:
service: rest_command.sunsa_north
data:
position: 0
close_cover:
service: rest_command.sunsa_north
data:
position: -100
east_blinds:
unique_id: living_room_blinds_east
friendly_name: East Blinds
device_class: blind
open_cover:
service: rest_command.sunsa_east
data:
position: 0
close_cover:
service: rest_command.sunsa_east
data:
position: -100
Note that the position in my close commands are set to “-100” because I want the blinds to close up instead of down. According to the Sunsa Wand API “0” is “open” (which is the opposite of what Home Assistant uses for cover position), “100” is “closed down”, and “-100” is “closed up”. You can customize that value as desired.
Once HA Core is restarted, your new cover(s) should be available.
As a bonus, here’s my automation for closing the blinds 30 minutes before sunset every day:
alias: 'Living Room Blinds: close 30min before sunset'
mode: single
trigger:
- platform: sun
event: sunset
offset: '-0:30:00'
action:
- service: cover.close_cover
target:
entity_id:
- cover.north_blinds
- cover.east_blinds
If you found this post helpful, give it a like so that I know it was worth writing.