WindowShade capability actions

I am building a custom window shade and using this as a learning opportunity.
I’ve got the basics working but still can’t get the command handlers to work 100%.
I need some help figuring out the correct actions for the window shade capability.

Here is my code:
– Window shade control CLOSE command
function command_handler.close(_, device, command)
local success = command_handler.send_lan_command(
{red=0, green=0, blue=255, close=true})
– Check if success
if success then
log.debug(’>>>>>>>>>>attempting to update on close’)
device.emit_event(caps.windowShade.close()) --this line breaks, idk the correct action
log.error(‘no response from device’)

Can someone please point me to the correct actions for windowShade?

The ST log shows:
2022-04-05T06:35:42.975996485+00:00 INFO Blinds8266 <Device: 2cebbcbf-42b7-45bb-9f3b-15aa6466a26b (Blinds8266)> received command: {“command”:“close”,“capability”:“windowShade”,“args”:,“positional_args”:,“component”:“main”}
2022-04-05T06:35:42.982623485+00:00 TRACE Blinds8266 Found CapabilityCommandDispatcher handler in Blinds8266
2022-04-05T06:35:43.574971151+00:00 INFO Blinds8266 ++++++++++++++++++++++++++++++++++++++++++attempting to update the ui on close
2022-04-05T06:35:43.581416152+00:00 ERROR Blinds8266 Blinds8266 thread encountered error: [string “st/dispatcher.lua”]:229: Error encountered while processing event for <Device: 2cebbcbf-42b7-45bb-9f3b-15aa6466a26b (Blinds8266)>:
arg1: table: 0xf61c38
[string “commands.lua”]:197: attempt to call a nil value (field ‘close’)


If caps is a reference to capabilities at the top level, I think you are probably missing a level of hierarchy and would need caps.windowShade.windowShade.close(), that is to say the capability ID and then the specific attribute you are setting a value for.


Thanks for the idea, I tried

but same error shows in logs.

There may be some other issue as the Window Shade capability displays (on the deltails screen in ST app) 4 buttons names: “Opening…”, “Closing…”, “Closed”, and “Close” and i wouldn’t think this is correct?

The Window Shade capability defined like this:
name: Blinds8266.v1

  • id: main
    • id: windowShade
      version: 1
    • id: windowShadeLevel
      version: 1
    • id: refresh
      version: 1
    • name: Blind
      deviceType: Blind8266
      ocfDeviceType: oic.d.blind
      deviceTypeId: Blind8266

In the hub log, i see this, which makes me think the open, close and pause commands are the right ones.
2022-04-06T03:49:40.141634660+00:00 TRACE Blinds8266 Setup driver Blinds8266 with Capability handlers:
CapabilityCommandDispatcher: Blinds8266

Any idea where to look?

The windowShade capability has a windowShade attribute which takes the values open, opening, closed, closing and unknown so I imagine I should have said caps.windowShade.windowShade.closed() for the event.

The available commands are open, close and pause.

The UI sounds odd. In your profile deviceType and deviceTypeId look wrong to my eyes. I can’t tell whether the formatting is correct because it isn’t shown as code. In YAML indentation is significant.

This probably needs a different set of eyes on it as I’ve barely touched Edge so nothing is totally familiar to me.

Have a look at SmartThingsEdgeDrivers repo for examples -

Two things I see - you need to use a colon after device, which causes device to be passed as the first parameter, and you need to use closed as the attribute value. Try this:


OMG so blind! The : took care of that problem! @philh30 thanks a lot!

One (i hope) last problem left is the UI. Here is what it looks like, the buttons don’t seem to be right:

The first button acts as “open” and the next 3 buttons all send the “closed” action. Also there is no “pause button” as the capability seems to suggest.

Here is the profile file i use:

Does anything look wrong? I think the “windowShade” capability determine the display of 3 buttons for open, close, and pause.


1 Like

You can see the top of four more buttons at the bottom of the capability too. You need to emit an event to limit the supported commands to just the three useful ones, eliminating the other states that shouldn’t have commands attached. This should just need to be done once per device - typically in the Added lifecycle event.

device:emit_event(caps.windowShade.supportedWindowShadeCommands({"open", "close", "pause"}))

Also, I agree with @orangebucket regarding deviceType and deviceTypeId in your profile. I believe both should simply be Blind based on what I’ve seen in the sample drivers. I’m not altogether sure which of the multiple metadata fields does what though.

@philh30 @orangebucket @hongtat THANKS for your great suggestions, seems that all is good now.

@philh30 I changed the deviceType and deviceTypeId back and forth and makes no different. I am not familiar enough with the code to understand why. Issuing supportedWindowShadeCommands was the missing link to a good UI.

I will have to work now on the details of the communication with my device, saving state, etc and when done will post the code for others.