NOTE: Updated code 10-27-2018

In this day and age where everything is measured, recorded, and available remotely (via a REST API most of the time!), it really bothered me that our heating oil tank measured the remaining gallons of oil by a crude plastic dip stick. It’s not accurate, there is no historical data, and there is no way to audit (for honesty, accuracy, or problems/errors).

So the problem is simple enough: Find a quick and easy way to remotely monitor the number of gallons of heating oil in a home, and alert at pre-set intervals (let’s say 75%, 50%, and 25%) of remaining oil in the tank.

After looking for commercial solutions, the cheapest one I found is $120 with a $10/year fee. In my view, that’s simply ridiculous. I decided that I could build something better for 1/3rd of the price ($40), without an yearly fee.

Hardware How-To

Start with this Instructable I created with the exact parts/steps, and with lots of pictures:
https://www.instructables.com/id/Monitor-Heating-Oil-Tank-Gallons-With-Email-SMS-an/

This should take care of the hardware side.

Firmware code and How-To Access Data

Once you have it built – flash your Photon with the code here (see bellow – large code paste).

After that, you should be able to do this from the particle CLI (replace $device-id-here$ with actual device #):

If you have not used the Particle Photon, I am going to provide some additional information on the bottom of this post that will walk you through building/flashing the code, and how to setup the web hook. I have also added a lot of pictures of this on the Instructables page to go with the steps.

Particle Photon web IDE code:

Now that you have everything you need, the last part is to web hook the “Alert” publish call into something that actually alerts you. The easiest way to do this is to create a JSON “custom” webhook, which allows you to “hook” a publish event. In this case, I will hook the “Alert” published event, and redirect it to Pushbullet. You can just as easily call a 3rd party SMS service (Twilio), Email (Sendgrid, Mailgun, etc), or some other custom notification/hook.

Here is the Pushbullet config (please replace “Access-Token” with your token):

Web Hook for Notifications (free with Pushbullet)

Or, if you are using Pushover

You will note that I have added a whole lot of pictures showing the steps around the Photon code build/flash and the Webhooks on the Instructables page. Here is some more informations/detials:

What if you have never used a Particle Photon? Detailed Help on setup/code/flashing!

I made the assumption that a most people who would be interested in a hardware project like this one would be very familiar with Particle’s photons/arduino, and I think this is a bad assumption. If you have not used these before, here is a step by step walk thru what to do from the software side in order to get this to work.

1.) Start by following this: https://docs.particle.io/guide/getting-started/start/photon/#step-1-power-on-your-device
2.) After you have initialized/”set up” your photon, go to: https://build.particle.io
3.) On the left side, under “Current Apps” (where it says “Title”) create an app called “oil-tank”.
Paste the large code from “Particle Photon web IDE code:” above, and click on the top-left “Save” (folder icon)
4.) On the left, click on “Libraries” (bookmark icon) and under “Community Libraries” search in the box for “HC_SR04”.
5.) Click on the found “HC_SR04” and click the blue “INCLUDE IN PROJECT” button. Then select from the list “oil-tank” (what you called your app in step #3), and click the blue “CONFIRM” button.
6.) At this point, make sure there is only ONE line that looks like this:

at the top of the file.
7.) Now clic on “Devices” and click on the star icon next to the device you setup in step #1 — this selects it for flashing the firmware.
8.) Go back to your “Code” for “oil-tank” and click “Verify” (check icon above “Save”) and then “Flash” (lightning bolt icon above “Verify”)
9.) That’s it — you have now flashed the firmware on your Photon.

What are these Web Hooks/Notifications – step by step instructions

1.) Go to: https://console.particle.io/devices
2.) Click on “Integrations” (star-looking icon above the Billing icon) and click on “New Integration”, and click on “Webhook”.
3.) There are TWO differentways to do this – using the “WEBHOOK BUILDER” step by step, OR pasting the whole JSON in the “CUSTOM TEMPLATE” section. No matter which you do, the only thing to really pay attention to is the “Event Name”. It always needs to be “Alert” (unless you change the Particle.publish in your firmware. This is what hooks that notifications into some “real world” notifcation – alert, SMS, Email, etc.)
4.) If you use the “CUSTOM TEMPLATE”, you can paste the “Web Hook for Notifications (free with Pushbullet)” code.
Alternative, and let’s say if you want SMS for example, you can go to the “WEBHOOK BUILDER” section, and follow something like this: https://www.twilio.com/docs/guides/sms-mms-messages-particle-photon#sign-into-or-sign-up-for-a-twilio-account, specifically following this sub-section: https://www.twilio.com/docs/guides/sms-mms-messages-particle-photon#example-1-a-simple-example-of-sending-smses-with-a-particle-photon (the “Set Up a Particle Webhook” part, and noting that the “Event Name” should be “Alert”).
5.) That’s it — you now have a method to “Alert” to external services. Generally, look for the REST POST URL, and either place it in your “WEBHOOK BUILDER” section, or into the JSON template I provided above.

19 Thoughts on “DIY – Monitor Heating Oil Tank Gallons with Pushbullet, SMS, and Email Alerting

  1. Is your oil sensor still working? Are you powering it with an AC adapter? Do you have a photo of how you ran the cord into the pipe. Oil tanks can see 5-7PSI when being filled. How airtight is your design? I’d hate to come home and find my basement full of oil :-O

    • Chris – Yes – I’ve been using my solution for a little 2 years now, with no issues other than the Photon needing to be rebooted one time as it stopped connecting due to some wifi changes (I believe this was the old photon firmware which did not handle SSID changes gracefully 100% of the time).

      Quite a few co-workers built one after I showed it to them, and from what I’ve heard, no one has had any issues.

      I actually have 2 Photons on our oil tank for testing/making sure originally that the numbers were accurate, and since then I’ve left both.
      This gives me an easy way to “sanity check” the numbers. I have one on the most left and one on the most right, which given the slight tilt, provides me with a pretty exact real average.

      I am powering them with AC adapters, which are plugged into one of those very thin 3-outlet extension cords (looks like this: https://www.cmple.com/content/images/thumbs/3-outlet-power-extension-cord-white-6-feet_NID0013781.jpeg)

      I drilled a hole in the cap from the Instructables I posted, placed the micro-usb cable through, and then epoxy glued the hole. You can get away with a much cleaner/”better” design by using the micro-usb cable from something like the Wyze camera which uses a flat cable. For an “ideal” design, I would cut the cable and re-connect it through the cap, but again, there was no need in my case. It’s faster/cheaper/easier just to buy a new cap for a few cents and drill it if you ever need one.

      The wiring to the units is not fancy/pretty, but given that my tank is in a basement corner, there’s no need for it to be pretty. It also makes it easy to unplug/reset/swap out the photon if I ever needed to — which was quite handy initially while building this.

      You don’t have to worry about oil coming out of this at all. The typical/average 275 gallon tank is only filled to ~250 gallons. The whistle mechanism they use to fill the tank prevents the tank from overfilling past ~250 galoons (you will see it go potentially up to ~260 gallons at most if they are careless when filling it, but never past that). You will never come home to find any oil in your basement through the bung holes (that’s really what they are called! :)) in your oil tank.

      I was actually much more paranoid than you (mostly about fire/sparks/etc), and I scheduled an appointment with the fire chief to get this inspected and looked at, along with a few different oil companies for their input. While I never went through any certifications, it’s as safe as it can get.

      I would suggest wrapping thread seal (or “pfte/teflon/plumbers” tape) tape before you screw it into the oil bung holes – this way you won’t get any smell, but even that is not an issue health wise (I checked!)

      Since the original post, other than the Pushbullet (or Pushover, preferred by some over Pushbullet) alerts at the different percent intervals, I’ve added a Siri Shortcuts. This is actually my favorite since it’s polling the photon and it’s truly instant, plus it can be activated with voice from any apple device, including the Apple Watch.

      Good luck, and hope you find this useful. I actually cannot believe something like this isn’t built by default into every oil tank at this point, but I guess there is a relatively small “US market” for oil (compared to gas/propane/etc) – mostly in the northeast and a few other remote areas.

      • Thanks for the update. I wish I had found your site before I made a very similar unit. I also used a particle proton and hc ping sensor. I designed / 3D printed an insert for a 2” pipe. In my code I tried both a 5th order polynomial fitted to table data and trig formulas to convert ping distance to remaining gallons. I’m using IFTTT to send alerts. I used Blynk to create an iPhone app that plots history and shows a gauge.

  2. Yea – It’s a “hacky” (but effective) way of eliminating sensor hardware read errors. Every once in a while the sensor will read invalid values — either be it due to Hardware issues or a library issue. This re-init takes care of that. I have only seen this problem twice so far, but with the double call, it always fixes itself on the 2nd call. It could be because I am using cheap sensors — I bought a bulk bag of them from Amazon for less than $10.

  3. I forgot to ask. Does this need to be called 2 times on line #59?
    59: inches = rangefinder.getDistanceInch(); inches = rangefinder.getDistanceInch();

  4. Thanks guys! 🙂 Appreciate it.

  5. Thanks. It was actually peekay123 on the Particle forum that saw my error. I just did not want anyone else to trip on it.

  6. Thought you would like to know that the instructable shows: D1 to Trig & D2 to Echo, your code says D0 to Trig & D1 to Echo.

    • Hi Bruce — thanks for pointing it out. It’s a typo on the Instructable. I am assuming at some point “wire 1” and “wire 2” somehow translated incorrectly to the writeup. The pictures are correct however, and the code matches those. It should be D0 and D1, although technically it doesn’t matter as long as 2 digital pins are used, and the same ones are in the code 🙂 Either way, I just updated the Instructable.

      Thanks again for finding this and pointing it out!

  7. gada888 on January 16, 2018 at 2:16 am said:

    I got an answer from them,’Each device can only trigger a webhook 10 times per minute.’.May the device request webhook service too frequent.

    • I would be surprised if that’s preventing you from creating a webhook though (it seems unrelated).
      Also, in reality you are sending a single call every 10-15 days. The worst case is on bootup – but even then, if your tank is almost empty, you should never generate more than 4-5 calls. By the way – check out the new code I released a couple of days ago. I think it greatly improves a whole bunch of stuff.

  8. gada888 on January 5, 2018 at 8:03 am said:

    Hi,Ventz

    I foolishly deleted the custom template integration of webhook.it’s been working ever since i followed your direction.Then when i try to build a new one.the ‘create webhook’button on Particle webhook webpage is grey.very weird,have you met this situation before.

    • How many other web hooks do you have? One reason I can think of the create being greyed out is if you have hit the free limit on the # of hooks you can have (can’t remember if it was 5 or 20 — if it’s 20, that’s probably not the issue).

      Try simple things like login out and back in/another browser/etc.

      You can also try to see what the CLI says/creating a webhook with the cli: https://docs.particle.io/guide/tools-and-features/cli/photon/
      I personally do everything from the CLI. It’s really great for a lot of things (flash firmware, get variables, stream events, check console, and even compile code and flash it)

      For webhooks, you can do “particle webhook list”.
      You can also create the webhook from the code I provided directly with the CLI if you put it in a JSON file.

      As a last resort, try contacting their support (hello@particle.io) – in my opinion, they are incredible.

      Post when you figure out what causes this. I am personally curious 🙂

  9. gada888 on January 2, 2018 at 10:17 pm said:

    Hi,Ventz

    Thanks for your follow-up explaination.now i can hook them up.it works,one thing i thought is about the pushbullet.it uses google account to login. so i am thinking if it wll work with ‘pushover’.which no need to use google accrount.

    • Funny you should mention this — I actually just switched my alerts yesterday to Pushover because I wanted a dedicated app JUST for alerts (PushBullet is good, but seems bloated. Also, they lowered the free tier to 500 msgs).

      Here is the exact Webhook you need:

  10. Thanks, Ventz, I am making one! I have not used Pushbullet before (or Particle Photon until yesterday), but now have it in my browser. I am having trouble getting node.js installed properly so I can use the Pushbullet CLI.
    Any advice on that?
    AND:
    When you say, “Here is the Pushbullet config (please replace “Access-Token” with your token):”
    Where does your subsequent code go? In the app that gets flashed into the Photon? If so, where exactly?
    Or is there somewhere in Pushbullet I am supposed to enter this code?
    Thanks!

    • Steve, replied on Instructables, but just so you have it here — I’ve added two new sections:

      What if you have never used a Particle Photon? Detailed Help on setup/code/flashing!

      and

      What are these Web Hooks/Notifications – step by step instructions

      These should provide the much needed clarifications.

      At last – I have uploaded a bunch of new screenshots to go with with both sections (on the Instructables post) for the software side of the Photon and the Webhooks.

      Let me know if these help and especially if something could use some more clarifications.

  11. Thanks for posting this.nice tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

>> NOTE: Please use <code>...</code> to post code/configs in your comment.

Post Navigation