That’s fine when you’re running code from the command line and unhandled exceptions get printed to screen or you can get to the actual application logs. In particular they shouldn’t be used to catch programmer error. The general advice for using try/catch exception handling instead of if/else error handling is that you should use exceptions for – as the name suggests – exceptional circumstances. This one will be blindingly obvious to experienced programmers, but it’s easy to forget when you’re looking at the sample code, especially if you’re not used to languages with that kind of try/catch exception handling block. In hindsight it was a ridiculously obvious solution, and maybe I was just having a slow day not to hit on it sooner! I just put a motion sensor on my desk, subscribed to motion events, and triggered them by waving my hand over it. Once I realised this I switched to the door sensor and spent a while making changes to my code and then walking to the front door to open it and trigger an event. You don’t want to make a change to your event handling code and then have to wait indefinitely to see if it works. You can’t predict when they’ll occur, so they’re not a lot of use for testing. Temperature events are triggered only when the temperature changes. You may be wondering why I started off by subscribing to a motion sensor when my end goal is to get temperature. Motion sensors are great debugging tools. Make sure you know where the logs are – the link is just below the box in the IDE where you enter your code and can also be found via the live logging tab. Once that’s installed and running you should get a log message every time the motion sensor activates. Subscribe(sensors, "motion", evtHandlerMotion) Input("sensors", "capability.motionSensor", Here’s my first pass (definition stuff excluded for brevity): Making sure you can do that, and finding the error messages when things do go wrong, is the first hurdle. With any new system it’s tempting to jump in at the deep end and try to do it all at once, but every system has its own way of getting code to install and run. If you can get a simple debug log message at least you know you’ve managed to set everything up properly. If you write too much code to start off with, you’ll have trouble figuring out why it’s not working. Have your event handler do nothing but log that it’s been called. Follow the tutorial to get the boiler plate code set up in the IDE and start by subscribing to one event type. Some of them might be obvious, especially to experienced programmers, but I know from the forums that plenty of ST users are new to coding and might find this useful. This is how I did it, and my tips for getting started with SmartApps. It took a combination of reading documentation, forum posts, example code and plain old guesswork. As a first step I want to log the temperature readings from the sensors.Īfter a lot of trial and error I managed to get ST to post HTTP messages to my home server. Step one of my automation project is to get data out of my SmartThings system and into my home server.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |