Saturday, April 15, 2017

IFTTT - If This Then That

If you, by now, haven't heard about this service it is time that you did. IFTTT is a free service that can make all kind of things in your life much easier.

First if you think it looks like some kind of programming language. You are wrong. You do not have to have any programming knowledge to use the service. The term IFTTT has however indeed originated in the programming world. It looks like the IF.......THEN...... statements in many programming languages.

So what does it do. Well exactly as the name suggest.

IF THIS (an action you perform) THEN THAT (Initiate another action).

So what can we do with it.

Let me give you a simple example.

I make a lot of photo's with my Android Phone. In fact I use my phone more for photographing as I use my regular cam. Well that is just because it is so convenient. The phone has a good camera quality and I always carry it around. But there is one flaw. I make a lot of photo's but I always forget to upload them to my computer. So they are stuck on my camera and there is always the risk of loosing them. In a previous story I told you that I use cloud services like Copy, Dropbox and Google Drive to upload my photo's, but you need the discipline to actually do that and that is where it lacks me.
So wouldn't it be great if you could automate that.

And that is where IFTTT comes in.


Direct your browser to ifttt.com and open an account. As it is a free service there is nothing that should prevent you from doing that.

In IFTTT you can make automated actions called Recipes. So I made a recipe that works as follows:

IF (I make a photograph on my phone) THEN (upload it automatically to Google Drive).

Ok let's do that in a step by step order.




First click on the tab 'My Recipes'
And choose Create a Recipe. A new screen opens that looks like this:




 Now click on the blue 'this'


The screen changes and there is a line in which you can type what you are looking for.


As you can see I filled in that I was looking for android.
Choose Android Photo and IFTTT gives you some options.


 Choose 'any new photo'




 Now press the blue button that says 'Create trigger'

Next step is choosing what happens after the photo is taken. The IF THIS from IFTTT is IF a photo is taken. We are now going to tell IFTTT what to do: the THEN side. So click the blue 'that' and search for the Google Drive logo and click on it.








Connect to your Google Drive account by filling in the form.
Just finish the required steps (for privacy reasons I do not show them here) and you're done.

Next thing is to download the IFTTT app on your phone from the play store and activate the account on your phone and you're set to go. Each time you make a new photograph with your phone the picture will automatically upload to your Google drive account.


I made the same recipe for my dropbox account. So a picture taken is automatically written to both my Dropbox as well as Google Drive. Just for safety.

However you can make things easy by making the following recipe:

This means that any new posting in your Drop-Box account is automatically copied to your Google Drive.

There are hundreds no maybe thousands recipes to discover.


This recipe couples Blogger to twitter. So the IF is Blogger and the THAT is Twitter. This tells IFTTT to post any new web-log entry automatically to twitter.


The recipe above is just for your phone. The IF is your home location and the THAT is to turn wifi in your phone off to save battery power.

Just browse all the channels in IFTTT and use your imagination. There are hundreds of possibillities which can make life a lot easier.

And then there is one channel on IFTTT that deserves our special attention and that is the Maker Channel. Using the Maker Channel we can trigger events with an ESP-8266 for example. This gives us tremendous possibilities with the Internet of Things. I'll show you how to use that in another story.

For now. Just try it and have fun.

Luc Volders

Saturday, April 1, 2017

Cheapskate

As this is a real functioning project I still urge you to look at the day it is published. Many people took this as a serious project and that just demonstrates what a hype the IOT is.

Hey I am Dutch. I am allowed to be a cheapskate.
So what does this have to do with this tech-weblog. Well I'll tell you.

What does every family has in their house: a fridge
And what is every Dutch guy and girl afraid of: that the light in the fridge will not turn off when you close the door and keeps burning money. Bull ?? No really. I have colleges at work that admitted that they on purpose broke the light in the fridge to make sure it was out. Another college told me that he just removed the light.

Well I did not want to do that because one of our fridges is in our basement in where there is insufficient light. So I need the light in the fridge. But what if it really will not turn off when I close the door. It keeps using electricity unnecessarily and therefore keeps wasting money.

As I am a tinkerer I knew I had to come up with something. And here is my solution.



I attached an LDR (Light Dependant Resistor) to the analogue I/O of a NodeMCU. That way I could measure the amount of light and could therefore tell wether the light in the fridge was on or off.

And here is the setup. If the light in the fridge would be off it would be totally dark in the fridge and that would set the LDR to its highest resistance. Something like 10M Ohm. If the light would be on it would fully expose the LDR and it's resistance would be Minimal.
I used the Axel Benz formula and that showed me that the pull-down resistor would have to be 10K in this case.

I will delve deeper into this very usefull formula in an upcoming story.

Now that I had the working setup I wanted to make a nice looking webpage that informed me wether the light in the fridge would be on or off. I used my favorite development environment: ESP-BASIC



First in the filemanager section I uploaded two pictures of lamps one on and one off. That would be the base of my monitoring.

Then I examined which values the ESP analog port would registrate in darkness and in light. I did that by writing a simple Basic Program.



timer 100,[test]

wprint |<h1 style="text-align:center;">Luc Volders</br>Light Tester</br>|
wprint "<br/>"
textbox value
wprint "<br/><br/>"
button "<h2>Off</h2>", [Off]
wprint "<br/>"
wait

[test]
sensor =  io(ai)

value = sensor
wait

[Off]
end


Let's look at the program:

timer 100,[test]

this statement at the beginning of the program makes sure that the routine called 'test' is called every 100 miliseconds.

[test]
sensor =  io(ai)
value = sensor
wait

The routine just reads the analog port of the NodeMCU and puts that in the variable 'value'

textbox value

just puts the measured value in a textbox on the screen.

The rest is just HTML code to put the text in a fancy way on your screen and generates a button that, when pressed, ends the program.

So that is easy. Lets look at the values the program produces.







In darkness I would get a value of 13 and in full light 850.




Naturally I also get inbetween values if the LDR is in the shade. This helps enormously. The LDR is not always positionable direct under the lamp. So I need to place it at any vacant location in the fridge and it has to react to any little bit of light it can detect.




And here is the setup in real life. Well it is a testing setup just to prove the concept works. A PCB and casing will follow later on. The red arrow points to the breadboard and in front of it is a  powerbank with an enormous capacity.



The only thing I had to do is to alter the program in such a way that in darkness the picture of the lamp that is off would get on the screen and when the light in the fridge is on the picture of the lamp that is on would be put on the screen. That gives me the above webpages on my phone.


onofnew = 1000
onof=0
timer 100, [TOP]
wait

[TOP]
onof = io(ai)
if abs(onof - onofnew) > 30 then
   CLS
   wprint "<h2>Fridge light 

status</h2>"
   wprint "<br>"
     if onof < 25 then
       image "lampoff.jpg"
     else
       image "lampon.jpg"
     end if
onofnew = io(ai)
end if
wprint "<br>"
wait

And there is the full program. Not much to it.
Every tenth of a second a subroutine is called that tests wether the value of the LDR has altered with whatever small amount. Next the program tests if the value of the LDR is below 25 and that indicates that it is in full darkness.

So it works.

There are however some small problems.
First the power supply is giving me some problems. The batteries seem to loose strength in the cold of the fridge.So they do not last long.

Next is the Wifi connection. The problem is not the distance from my router as I have a good connection when the door of the fridge is open. But the connection fades away when the door is closed. Well that is obvious as the fridge's walls are made from sheet metal and that works like a faraday cage letting no signals escape. However that makes it impossible to really test wether the light is out when the door is closed.

The workaround.

Above mentioned problems are really annoying so I had to find a work around and I did. I still have to implement it but I will give you the setup:


Drill a hole in the door of the fridge and kit some perspex on it as a looking glass. That way you can easily see if the light in the fridge turns off as you close the door. However it is not as sexy as my ESP setup.

Till next time
have fun

Luc Volders