project: oil tank level sensor

14 Responses

  1. Ash says:

    Excellent write up. Thank you for taking the time to do this. It has helped with my own, very similar, project.

    One thing I am experiencing is timeouts. I see this in the log:

    [09:08:13][D][ultrasonic.sensor:025]: ‘Oil level in cm’ – Distance measurement timed out!
    [09:08:13][D][sensor:092]: ‘Oil level in cm’: Sending state nan cm with 0 decimals of accuracy

    This results in a ‘non-numeric’ error in Home Assistant. Have you experienced this? Any idea of the cause or a solution?

    • roger says:

      I have seen this error. At times I thought I had two many sensors on board so I slimmed down the code; at others I changed the ESP pins used or the ESP itself. Ultimately it seemed to be related to the strained connection of the sensor plug and the board. It went away so I took care not to touch the thing again.

      Generally errors happen everywhere – eg when trying to upload the firmware – so it’s easy to be discouraged. My tips would be a) experiment a lot b) take notes in a book c) buy two of everything if that’s affordable.

  2. Graham says:

    As an avid user of Home Assistant, this is a fantastic help guide for monitoring an oil tank here in the UK, thank you. To save hacking up a USB cable, would something like this board work for the ESP module ? Can you recommend a housing for the ESP and the sensor board?

    • roger says:

      Cheers Graham. Thank you for reminding that some ESP32’s have a USB socket.

      For a housing on this occasion I used a £4 (electronics) project box from ebay. There are dozens in all sizes, with see-through lids and waterproofness. Since then I’ve bought (from Screwfix or Toolstation) electrician’s junction / connection boxes also called chocboxes. This one fits an ESP32-CAM at £1; others are larger and waterproof

  3. Dan says:

    This is excellent. Do you have the plans for the oil cap that you custom printed? I’d love to order one like yours.

    • Douglas Telford says:

      I am just starting a similar project on my oil tank having managed to run out of oil on the coldest days. I don’t have access to a 3D printer and so have been trying to find a housing for the sensor to fit on the tank top pipe. I have found on my 600 Gallon tank a Sunpat Peanut butter jar lid fits the top rather well and will just need to have a hole cut to size for the sensor. I have yet to do this!

      • roger says:

        Sorry to hear this Dan but your/this project is worthwhile. It helps that my sensor cannot be displaced. For sure there’s a jar lid somewhere to suit. I’ve now updated the post with a hint to check the calibration and watch the graph as I now get a graph plateau at 0.72 m from the top. The actual reading therefore can mislead. As 760 litres was the trigger for ordering more oil the issue was never spotted – but something may have changed in the tank/sensor. I’ll investigate that as well as use collected data to somehow predict when oil might need a visual check. In the meantime thanks for reminding on a vital issue. (And while I ordered oil ahead of disaster last week, suppliers were offering dates three weeks ahead so an emergency delivery had to be bought).

  4. Dan says:

    Regarding the non-numeric issue that Ash inquired about; the fix is to add a filter to your code that ignores non-numeric readings. I added it after the lambda, so the code in your demo would be:
    – lambda: return x * 1053;
    – filter_out: nan

    • roger says:

      Oh thank you so much! I wish I’d known about that (– filter_out: nan) as a way to remove non-zero readings should they occur.

      There’s another need for a filter in my TRAIN TIMES* project. The Home Assistant overview shows (something like “Non-numeric” or “Not available”) after midnight when there are no local times. A filter is probably the answer.

      I’m currently posting projects on using unmodified Sonoff devices; using RFlink and 433MHz sensors. Pop back should these be of value. Thank you again Dan.


  5. sooty says:

    Hi Roger – Sincere thanks for posting this!

    I’ve now got a cost effective remote Oil Monitoring system for my overseas vacation home. In the past I have always been somewhat concerned not being able to see how much oil remains in the tank as we go through the cold winter months…

    • roger says:

      Thank you too for your feedback Lance and best wishes from here. Wow … measuring oil levels remotely offers a big gain. Thinking about the oil tank level as you’ll realise is an unnecessary worry. Even ordering oil is easier when you know you use say, 100 litres in a week. I will soon be posting a very easy project to constantly display the oil level on a TTGO T-Display.

  6. Youtube Mr12v says:

    Hi Roger. Thanks for the great write up on the oil level sensor. I have replaced my broken Apollo sensor with this setup so I can integrate it into my home assistant. I just thought I’d share here about the calibration that I used to convert the distance reading of the sensor to approximate oil in litres. ESPHome has a calibrate_linear function. Doing it this way let me calibrate better to my cylindrical shaped tank (1800 litres) and have a countdown of litres remaining instead of counting oil used. This would obviously work on a square tank too with much easier values! I have 1000 litres of oil coming next week so I’ll be able to test to see how accurate the readings are and adjust accordingly. The filters code for the sensor is below:

    – lambda: return x * 100;
    – filter_out: nan
    – sliding_window_moving_average:
    send_first_at: 7
    window_size: 7
    send_every: 7
    – calibrate_linear:
    # # Map 0.0 (from sensor) to 0.0 (true value)
    – 110 -> 0
    – 95 -> 204
    – 75 -> 544
    – 55 -> 900
    – 35 -> 1320
    – 15 -> 1660
    – 0 -> 1800

    I hope this provides some use to the readers of this blog! Keep up the good work!
    Best regards

    • roger says:

      Thank you. That’s a brilliant use of feature I couldn’t quite get. I see your need for a calibration table. I’ll guess that you’ve worked that from the volume of a regular cylinder while my tank was a steel box. As an obsessive measurer I’m stuck on this *** do please let’s know if you find a solution!
      o Keep your eye on the oil graph and if the readings plateaux, as mine seemed to, investigate the range of this sensor.
      o Take oil and average temperature readings each night for a spreadsheet using IFTT
      o Create a daily oil use (in litres per day) graph (still working on this) ***
      o Use an hour meter or electric monitoring smart plug to monitor boiler burning time

Leave a Reply

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