I’m creating a Device Type to allow me to control some devices that I have connected to a VeraLite.
I can quite happily turn the devices on and off using HubAction but I would like to add a subscription so I get notified of any changes on the VeraLite.
To setup the subscription I need to know to know the IP and Port of the Hub but I can’t for the life of me work out how to get this information.
The examples seem to say I can do something like
def ip= device.hub.getDataValue(“localIP”)
def port= device.hub.getDataValue(“localSrvPortTCP”)
or use device.deviceNetworkId
But I get errors saying
java.lang.NullPointerException: Cannot get property ‘hub’ on null object
or
java.lang.NullPointerException: Cannot get property ‘deviceNetworkId’ on null object
What am I missing here? Do I need to do something special to get access to the Hub Data?
I have a Device which is associated with my Hub and Location called “Vera Switch Node 4” which is of type “Vera Switch” which is the Device Type I am writing and where I’m hitting the problem.
I’m wanting to get the Hub IP address from within my Device Type code.
You’re calling a function outside of the device context. That’s why your ‘device’ variable is undefined. You cannot do that. You can only execute code from the command handlers or from the parse() method.
Further question - where would I put the call to subscribeAction in my code? Is there an installed() method (or something similar) that would allow me to do what I want?
If not, do you have some advice on how I subscribe to updates from Vera unit?
I sold my Vera some time ago :), but I’m also interested in getting LAN callbacks to work for my other projects. No one have figured out yet to my knowledge. At least I have not seen any working code. The most commonly used method to push events to ST is via REST endpoint (a.k.a. Web Services SmartApp). An advantage of this method is that you don’t actually need a hub. You can push your data from anywhere. You can combine these two methods - use Hub for downstream commands and REST endpoint for upstream events.