No Products in the Cart
I am sure many can relate to going past the local shop after work to pick up some items for supper that evening and when you get home slice and dice some onions which is about to get fried on the gas stove and 2 minutes into the fry you hear that dreaded sound of the gas flame going out. No one is generally listening at the time within the household but you still feel the need to state... We're out of gas!, hoping that someone will quickly arrange for an replacement. Get notified Ideally we would like to know when the gas level is low prior to actually running out.
This DIY project is enables you to build a platform which the gas bottle will sit on and measured by weight. If the weight falls below a pre-set weight you receive a notification through the Home Assistant companion.
How it works
Before we begin, Credit goes to the The Hookup blog and YouTube channel for all the information associated with this project.
This idea behind this DIY project is building a simple internet of things weight sensor which measures how much gas is remaining in the tank. That information can be fed to Home Assistant and alerts or automations generated as a result.
What you need
To make this you will need an ESP8266 NodeMCU, a set of 4 load cells, and an HX711 amplifier, those parts are available locally in South Africa which I have supplied links for purchasing online under the Additional Information section of this blog.
For the purpose of this blog we will keep the method the same as that of Rob from The Hookup by using a spare piece of plywood that gets cut into a circle to fit the gas bottle.
You then mount the load cells equidistant from each other in a square configuration. The important thing to know about mounting the load cells is that they need to be able to deform, so you’ll need to provide some kind of a hole for the middle section to deflect into. In this case just drill a few holes underneath the loadcell and use a chisel to clean it up.
Screw the load cells into the cutout but be sure that the screw doesn’t protrude lower than the load cell foot. Once done label your load cells as 1, 2, 3, and 4 in a clockwise fashion.
Next we going to connect the white wires of cell 1 and cell 2, and the white wires of cell 3 and cell 4. Then connect the black wires of cell 1 and cell 4, and then the black wires of cell 2 and cell 3.
Attach some female pin headers to the 4 remaining red wires, and then connected them to the HX711 amplifier. The amplifier is necessary because the difference in resistance in the load cell is actually really small so we need a purpose built device with a better analog voltage resolution than you’d find in a normal microcontroller. We also want to keep the HX711 as close to our load cells as possible so we don’t introduce noise or more resistance into the circuit with our connecting wires. On the HX711 you’ll connect the red wire of cell 1 to the A minus terminal, cell 2 to the E plus terminal, cell 3 to the A plus terminal, and cell 4 to the E minus terminal.
Our next step is connecting the HX711 to the NodeMCU and set up Home Assistant to monitor it. For this, we’re going to use my Tasmota.
Download the Tasmotizer tool. In tasmotizer we’re going select release under image, and then choose “Tasmota-sensors.bin” from the dropdown, click the “self resetting device” checkbox and plug your NodeMCU in your computer’s USB port. If you hit refresh a new com port should show up and you’re ready to flash your device, so hit that blue Tasmotize button and let the program do the rest.
After it finishes you’re going to send your WIFI credentials, and your MQTT information using the send config button,. Also specify the topic in this window, to make it easier to identify in Home Assistant.
Navigate to the IP address specified during the flashing of the NodeMCU in your browser and this should redirect you to the Tasmota web UI where the sensor will need to be configured. Click on Configure, and then Configure Module and select Generic, which will cause the device to reboot. Repeat these steps to get back to the Configure Module screen where we can specify where we plan on attaching our HX711 load cell amplifier. At this point a clock pin and a data pin needs to be set which we used the same as specified in the original blog by using D1 and D2. So select D1 your clock pin or HX711 SCK, and D2 for your data pin or HX711 DAT and then hit save.
Next, we need to connect the NodeMCU to the HX711 by connecting ground to ground, 3v3 on the NodeMCU and VCC on the HX711, and then connect the clock pin to D1, and the Data pin to D2.
At this point there should be information that pop up in the Tasmota web interface for the scale but more than likely not accurate or correct.
To calibrate you need to open the console in Tasmota and something that you know the weight of. such as a 500 ml water bottle with a mass of 500g which we would expect to roughly weigh 510 grams if we include the bottle itself.
You calibrate the scale by typing in sensor34 2 1020 which is the calibrate command for the HX711 sensor, followed by the number of grams that it should be expecting. The console should ask to remove the weight, then replace it and then it will automatically calibrate itself.
If you get an error on this step, the wiring on your load cells may have been reversed from the factory and you can check it by typing in status 8, which should show you the raw value of the sensor. Putting things on the scale should make that value go up, and taking them off should make it go down. If it’s the opposite of that you’ll need to reverse your white and black wires, so every white connection that you had instead connect the black ones, and vice versa.
Home Assistant Integration
To add an MQTT sensor to Home Assistant open the configuration.yaml file and under the sensor heading specify a name and state topic according to the topic you put into Tasmotizer earlier. Since this topic reports a JSON output we want to grab the specific attribute for raw weight, so we’ll put in a value template to grab the json attribute from our HX711 sensor and then we just need to subtract the raw value of the scale that we wrote down earlier to calculate the number of grams on the scale. You can also specify that the unit of measurement is in grams, and then you’re all set.