Alexa v3 Skill : Is it possible to have Switchable and ContactSensor on the same item line?

Hi team

  • On OpenHAB 2.5.3 with the cloud service + Alexa V3 skill.
  • Sonoff 4ch pro running Tasmota to open/close the garage/gate
  • Xiaomi magnetic door switches to read the open/close status

I’ve got the skill running fine and can use an Alexa routine to open/close the ‘Garage Door’. I’d like to be able to ask Alexa if the ‘Garage Door’ is open, but I can’t work out if it’s possible to do that on the same Switch item. Is it possible? I’ve been through the documentation and can’t quite find what I’m looking for that works.

Currently I have to have two items, one for the Switch and one for the Contact and call them different things so Alexa will get the status correctly. If I ask the status of the ‘Sectional Door’, it works fine but I have to remember what I called it.

As an aside. If you have your Alexa set to AU/NZ language, it says the ContactSensor status twice. ie Alexa, is the sectional door closed? The response is, ‘The sectional door is open, the sectional door is open’. Changed it to US in the settings and it’s fine now and only says the status once. Only seems to be a problem on ContactSensor and I’ll never get those 4 hours of my life back.

I hope I have these code fences right.

Group   	GF_Garage     "Garage"         <garage>        		(Home, GF)
Switch 	GF_Garage_01	"Garage Door"      <garage>    (GF_Garage)	{ alexa="Switchable", channel="mqtt:topic:mosquitto:GF_Garage_01:GF_Garage_01_Switch" }
Contact	GF_Garage_01_Status		"Sectional Door [%s]"	<garagedoor> (GF_Garage)	{ alexa="ContactSensor",channel="mihome:sensor_magnet_aq2:7c49eb1d10d0:158d00025295b2:isOpen" }

Cheers
Mike.

Since you are dealing with Switches and Contacts the answer is no. It’s helpful to review the concepts section of the docs from time to time.

A Thing represents a device, the garage door opener in this case. A device may have one or more Channels actuators and sensors. In this case you have one actuator (Switch) and one sensor (Contact). A Switch can only receive an ON/OFF as a command and stores state as ON/OFF. A Contact cannot receive commands at all and only stores state as OPEN/CLOSED. The two are completely incompatible. Therefore there is no way to merge both the status of the door and the Item that commands the door into the same Item.

If you represent the door as a Rollershutter, than this is more possible because this Item can receive some discrete commads (OPEN/CLOSE/UP/DOWN/STOP) and it stores the state as a percent number (so state > 0 means OPEN). But to use a Rollershutter Item you need a sensor on the door to indicate how far the door has opened. Since you are using a Contact I’m guess you, like many of us, just have something like a reed sensor to indicate OPEN/CLOSED.

So you might be able to get something like this to work with Rules so that you update a Rollershutter Proxy Item and then link that Item to Alexa. You should be able to command the door as well as ask whether the door is open or not on that Item and use Rules to synchronize that proxy Item with your Switch and Contact.

Along @rlkoshak suggestion, since it appears that you only have a two states device, you could use a Switch proxy item for this as well. I would have pointed to the item sensor concept but this requires to have the same item type between the command and status item unless you are willing to use the LockController interface limiting to lock/unlock command request only.

Going back to the Switch proxy item, you should model that proxy item as a ToggleController using Semantic Extensions. That way, you wouldn’t need Alexa routines and more importantly, you would be able to ask if your garage door is open/close.

items

Group GF_Garage "Garage" <garage> (Home, GF)
Switch GF_Garage_01	"Garage Door" <garage> (GF_Garage) { channel="mqtt:topic:mosquitto:GF_Garage_01:GF_Garage_01_Switch" }
Contact	GF_Garage_01_Status "Sectional Door [%s]" <garagedoor> (GF_Garage) { channel="mihome:sensor_magnet_aq2:7c49eb1d10d0:158d00025295b2:isOpen" }
Switch GF_Garage_Alexa "Garage Door" (GF_Garage) { alexa="ToggleComponent" [category="GARAGE_DOOR", friendlyNames="@Setting.Opening", actionMappings="Close=OFF,Open=ON", stateMappings="Closed=OFF,Open=ON"] }

rules

rule "Garage Door Command"
when
  Item GF_Garage_Alexa received command
then
  GF_Garage_01.sendCommand(receivedCommand)
end

rule "Garage Door Status"
when
  Item GF_Garage_01_Status changed
then
  switch GF_Garage_01_Status.state {
    case OPEN: GF_Garage_Alexa.postUpdate(ON)
    case CLOSED: GF_Garage_Alexa.postUpdate(OFF)
    default: GF_Garage_Alexa.postUpdate(NULL)
  }
end
2 Likes

@jeshab and @rlkoshak. Thanks very much for your advice. I set up the switch proxy and just had to change the actionMappings=“Close=OFF,Open=ON” to “Close=ON,Open=ON” because the Sonoff device is in inching mode and switches on for 0.5 of a second at either an open or close command. That closes the contacts for the door motor external switch and it works great.

When I ask Alexa if the ‘Garage Door’ is open, it responds with the proxy ‘Garage Door Opening is ON’ or OFF depending if the door is open or not.

Cheers.

1 Like

I would like to hijack this thread by placing one follow up question - so I hope you don’t mind.

Do I always use an alexa proxy item for being able to e.g. switch an item which has a channel linked to it?
Example - can I use the zwave channel AND the alexa link to this item:
Switch Z_Strega "Kaffeemaschine" (G_jdbc,G_All_OFF,Group_HabPanel_Dashboard) {alexa="Switchable"} {channel="zwave:device:12345678-9012-3456-7890-123456789012:node3:switch_binary"}

Hi @NCO. Yes, what you done is fine and in line the documentation. I’ve done exactly the same thing with some of my other Alexa controllable switches.

The reason I went down the proxy route as suggested by @rlkoshak and @jeshab was that I wanted a separate sensor item to report on the open/close status of the door without having two separate items with unique names.

1 Like

Awesome. Thank you for your quick response!

EDIT:
Neither this does work:
Switch Z_WoZiLicht "Wandlicht" (G_jdbc) {alexa="Switchable"} {channel="zwave:device:12345678-9012-3456-7890-123456789012:node4:switch_binary"}

nor this one:
Switch Z_WoZiLicht "Wandlicht" (G_jdbc) {channel="zwave:device:12345678-9012-3456-7890-123456789012:node4:switch_binary"} {alexa="Switchable"}

ERROR:
Configuration model 'zwave.items' has errors, therefore ignoring it: [16,111]: missing EOF at '{'

But this seems to work (at least no error while loading the items):
{alexa="Switchable",channel="zwave:device:12345678-9012-3456-7890-123456789012:node4:switch_binary"}