This seemed like it could use a dedicated topicā¦
From what I understand, devices on Hubitat should be able to receive notifications from LAN devices, as long as the Hubitat device is using the same deviceNetworkId
as the real LAN device.
In STās Building the device type docs, they suggest doing the following to subscribe to device events (for devices that support SUBSCRIBE commands):
new physicalgraph.device.HubAction(
method: "SUBSCRIBE",
path: path,
headers: [
HOST: ip,
// ST docs have the /notify path, but aren't clear on where it comes from. I've
// tried with and without.
CALLBACK: "<http://${address}/notify$callbackPath>",
NT: "upnp:event",
TIMEOUT: "Second-28800"
]
)
The host address is the address of the LAN device and the callback address is the address of the hub, which we can get with something like
def getHostAddress() {
def ip = getDataValue('ip')
def port = getDataValue('port')
"${convertHexToIP(ip)}:${convertHexToInt(port)}"
}
On my hub, the function above gives me a host address like ā10.0.1.99:39501ā, which looks reasonable enough.
It seems straightforward enough, but Iāve noticed a couple of problems (or at least, some things arenāt working as I expect). For one, the above āSUBSCRIBEā HubAction doesnāt seem to work. When I issue it (Iām working with a WeMo switch), I never see a response from the device. However, the following HubAction does work (in that my deviceās parse
method gets a response with a subscription ID after this action is issued):
new hubitat.device.HubAction("""SUBSCRIBE /upnp/event/basicevent1 HTTP/1.1
HOST: ${ip}
CALLBACK: <http://${callback}>
NT: upnp:event
TIMEOUT: Second-300
""", hubitat.device.Protocol.LAN)
The other issue is that my deviceās parse
method is never called with any event notifications. I know that the subscription is working. For one, I get a subscription ID back from the LAN device. I also tried setting up a simple server on my MacBook and used that address:port as the callback address when I created the device subscription; that server then received notifications from the LAN device.
My Hubitat device does receive request responses from the LAN device. For example, after issuing the āSUBSCRIBEā command above, my deviceās parse
method is called with with a response containing the subscription ID. Similarly, parse
is called with responses after I issue device control commands.
The deviceNetworkId
property of the Hubitat device is set to the MAC address of the LAN device (WeMo switch), where the address is a hex string in all caps with no colons. This address matches the MAC address I see in the responses I receive from the LAN device, so it seems to be correct.
Is there anything else I need to configure to be able to receive LAN notifications?
This is my driver: hubitat/jason0x43-wemo_switch.groovy at master Ā· jason0x43/hubitat Ā· GitHub