One of the most common thing my parents get after me for is turning off the lights when I leave for school, which is fair because I often leave every bulb possible turned on as I stumble out of the house. So the goal was simple - make a setup that would turn off my lights when I leave, and preferably turn them back on when I come back. This would save energy, save money, and be one less thing to think about in the mornings.
I contemplated a number of was to do this, from tracking when my phone connects to home wifi, tripwires, lasers, but none of these were quite right for what I needed. I often turn of wifi for specific tasks, tripwires were too physically cumbersome and there is no ideal place for them in my room, laser sensors would go off every time I go in or out of my room etc. I could have worked with a combination of these methods, but there was a simpler way. I decided I would use a pressure sensor set to detect when I set my backpack down, which would publish a web-hook to IFTTT and turn on the lights in my room. The system would repeatedly check for pressure, and not turn the lights off until the pressure is removed.
By this point I created the basic board setup that I would stick with throughout the project:
The left side plus rail is connected to the ground via black wire. The red wire connects the pressure sensor on one side to the ground, while on the other the orange connects it to the A5 analog pin. The LED is grounded via blue and connected to D7 via white.
As I began to code I messed with other various different logics to ensure the light would not turn off until the pressure was removed, which briefly saw me use a board setup seen below, using two LEDs to keep track of an extra variable called status, seen in the code also below.
Ultimately once I got the logic down and the web hooks to only run at the appropriate times I removed the second (blue) light.
Once I manage to get the the web hooks responding to the pressure sensor the next problem was how I would get my lights to turn on. My initial train of thought was that since I had a smart bulb, there would be a way to talk directly to the light via the Wiz (the brand of smart lights) cloud. However after trying to make this work for a while, it turns out that the Wiz cloud is not publicly accessible without certain developer powers. There were in theory workarounds for this, and people "have reverse-engineered the communication protocols to control the bulbs locally or through custom applications. However, this approach requires technical expertise and may not be officially supported by WiZ, " - Redditor. This plan seemed beyond my abilities.
My next option was to go through a service that could talk to my light for me. To do this I went through IFTTT, creating applets that would run when my webhook is published. These applets are linked directly to my Wiz account and thus had the power to control my lights.
The final step was to create particle integrations to take those two web hooks and build them into my code. The two POST web hooks from IFTTT correspond to two separate integrations, shown in the particle console below.













Comments