Closed seanio-dev closed 5 years ago
Thank you very much for your very thorough explanation of what is going on. The answer is actually quite simple. The switch device is designed to have it's openHab state updated when the switch is toggled. And, it is designed to be changed by openHab. The contact sensor is only designed to be changed when the contact is triggered.
This is actually the way Smartthings is designed. Look in the Smartthings capabilities reference. The switch includes a commands section in its definition. But the contactSensor does not include a commands section meaning that the smartthings hub isn't supposed to be able to update it.
Think about how it works in the physical world. For the switch when is is toggled you want openHab to know about it and update. And, you want to be able to change it from openHab. Think about a contact sensor on a door, openHab should be notified when it changes state (i.e. the door opens or closes). But, openHab can't open or close the door.
You might look at the door control device. It is designed to report when it is opening or closing and it is designed to allow openHab to control it.
Bob
Hi Bob, I'm having problems getting an contactSensor to post back to smartthings. I am however able to get switches to change states. I'm new to openhab so there's a chance i'm doing something completely wrong.
openHab >> Smartthings - Switch OK openHab << Smartthings - Switch OK
openHab >> Smartthings - Contact Not working openHab << Smartthings - Contact OK
default.sitemap
sitemap default label="myHome" { Text item=FrontDoor Text item=vsensor Switch item=vswitch }
default.itemsContact FrontDoor "Front Door [%s]" <door> {gpio="pin:16 debounce:10 activelow:yes"} Contact vsensor "vsensor [%s]" { channel="smartthings:contactSensor:MySTHub:vsensor:contact"} Switch vswitch "vswitch [%s]" {channel="smartthings:switch:MySTHub:vswitch:switch" }
default.things
Bridge smartthings:smartthings:MySTHub [ smartthingsIp="192.168.10.16", smartthingsPort=39500 ] { Thing contactSensor vsensor [ smartthingsName="vsensor" ] Thing switch vswitch [ smartthingsName="vswitch" ] }
default.rules ` rule "test" when Item FrontDoor changed from OPEN to CLOSED or Item FrontDoor changed from CLOSED to OPEN or Item vswitch changed from ON to OFF or Item vswitch changed from OFF to ON then logInfo("org.openhab", "Executing Rule 1")end
rule "test2" when Item FrontDoor changed from OPEN to CLOSED or Item FrontDoor changed from CLOSED to OPEN or Item vsensor changed from CLOSED to OPEN or Item vsensor changed from OPEN to CLOSED then logInfo("org.openhab", "Executing Rule 2")
end
`
Smartthings Logs
b2f93e4b-cdb5-4c8d-a600-fc61532e01cb 8:56:56 AM: debug Subscribing to event handler null b2f93e4b-cdb5-4c8d-a600-fc61532e01cb 8:56:56 AM: debug Subscribing inputHandler to device "[vswitch]" with attribute "switch" b2f93e4b-cdb5-4c8d-a600-fc61532e01cb 8:56:56 AM: debug Subscribing inputHandler to device "[vsensor]" with attribute "contact" b2f93e4b-cdb5-4c8d-a600-fc61532e01cb 8:56:56 AM: debug Updated with settings: [contactSensor:[vsensor], switch:[vswitch], openhabDevice:Openhabianpi]
OpenHab Logs
`018-10-09 09:27:43.862 [INFO ] [e.smarthome.model.script.org.openhab] - Executing Rule 2
2018-10-09 09:27:43.862 [INFO ] [e.smarthome.model.script.org.openhab] - Executing Rule 1
2018-10-09 09:27:43.875 [INFO ] [e.smarthome.model.script.org.openhab] - FrontDoor:OPEN
2018-10-09 09:27:43.888 [INFO ] [e.smarthome.model.script.org.openhab] - vsensor:CLOSED
2018-10-09 09:27:43.900 [INFO ] [e.smarthome.model.script.org.openhab] - open
==> /var/log/openhab2/events.log <==
2018-10-09 09:27:43.884 [ome.event.ItemCommandEvent] - Item 'vswitch' received command OFF
==> /var/log/openhab2/openhab.log <==
2018-10-09 09:27:43.909 [INFO ] [e.smarthome.model.script.org.openhab] - Executing Rule 1
==> /var/log/openhab2/events.log <==
2018-10-09 09:27:43.915 [ome.event.ItemCommandEvent] - Item 'vsensor' received command OPEN
==> /var/log/openhab2/openhab.log <==
2018-10-09 09:27:43.924 [INFO ] [e.smarthome.model.script.org.openhab] - Executing Rule 2
==> /var/log/openhab2/events.log <==
2018-10-09 09:27:43.929 [vent.ItemStateChangedEvent] - vswitch changed from ON to OFF
2018-10-09 09:27:43.938 [vent.ItemStateChangedEvent] - vsensor changed from CLOSED to OPEN
==> /var/log/openhab2/openhab.log <==
2018-10-09 09:27:44.028 [INFO ] [hings.internal.SmartthingsHttpClient] - Sent message "{"capabilityKey": "switch", "deviceDisplayName": "vswitch", "capabilityAttribute": "switch", "value": "off"}" with path "/update" to the Smartthings hub, recieved HTTP status 202
2018-10-09 09:27:49.719 [INFO ] [ings.handler.SmartthingsThingHandler] - Smartthings updated State for channel: smartthings:switch:MySTHub:vswitch:switch to OFF`