hi there
I had some spart parts lying around and thought I try to turn my toilet paperholder into a smart one. I realized it with the following components:
ESP8266 / Wemos D1 mini ESP-Home config
HX711 loadcell-amplifier
loadcell bar-type
so far so good, please find below a short video of the prototype. It still lacks proper wiring and a plate on top of the loadcell but it works.
the idea
the holder can take up to 3 rolls and I would like to change the color depending on the load (1 = red, 2 = yellow, 3 = green)
this is where I need your help
How can I implement a counter that depends on the weight that the scale measures? I would like to use Node-RED if possible, otherwise HA is fine too.
I already saw something similiar but there is no information how it has been done: Toilet paper sensor - #7 by diplix
all the best
Andrew
3 Likes
You could do it with a template sensor in your esphome code
thanks for the quick reply, I must admit that I am not that familiar with templating, would you mind helping me out with it?
this is how the ESPHome yaml looks like:
esphome:
name: "paperholder"
esp8266:
framework:
version: 2.7.4
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "XX"
wifi:
ssid: 'XX'
password: 'XX'
# Example configuration entry
light:
- platform: fastled_spi
chipset: APA102
data_pin: D7
clock_pin: D8
num_leds: 2
rgb_order: BGR
default_transition_length: 500ms
name: "Paperholder Light"
sensor:
- platform: hx711
name: "Paperholder Value"
dout_pin: D1
clk_pin: D2
gain: 128
update_interval: 2s
filters:
- calibrate_linear:
- -28066 -> 0
- -187602 -> 101
unit_of_measurement: g
These are the entities from the ESP:
scale: sensor.paperholder_value
light: light.paperholder_light
one roll weighs 102 gramms. as for now I only realized very basic templates like window open/closed but not something where different dimensions (weight and pieces) come into.
The goal is to make it work as supposed and post it here in the projects so anybody can build its own paperholder
Whats the value of the hx711 sensor when 1, 2 and 3 rolls are present ? Is it 102, 204 and 306 ? If so is it stable or does it vary a bit ?
many thanks. it varies by around +/- 5g. I just did some research and am happy to get some help so I can adapt it for future templating, at the moment it is abstract for me
Something like this might work ?
light:
- platform: fastled_spi
chipset: APA102
data_pin: D7
clock_pin: D8
num_leds: 2
rgb_order: BGR
default_transition_length: 500ms
name: "Paperholder Light"
id: rgb_light
sensor:
- platform: hx711
name: "Paperholder Value"
dout_pin: D1
clk_pin: D2
gain: 128
update_interval: 2s
filters:
- calibrate_linear:
- -28066 -> 0
- -187602 -> 101
unit_of_measurement: g
on_value_range:
below: 97
then:
- light.turn_off:
id: rgb_light
on_value_range:
above: 97
below: 107
then:
- light.turn_on:
id: rgb_light
brightness: 100%
red: 100%
green: 0%
blue: 0%
on_value_range:
above: 199
below: 209
then:
- light.turn_on:
id: rgb_light
brightness: 100%
red: 100%
green: 100%
blue: 0%
on_value_range:
above: 301
then:
- light.turn_on:
id: rgb_light
brightness: 100%
red: 0%
green: 100%
blue: 0%
many thanks! works great, actually I already realized this in another way with Node-RED. maybe I wasnt clear enough.
what I am trying to achieve additionally is the following:
If the scale measures 102g +/- 5g it should display 1 roll on the stand
If the scale measures 204g +/- 5g it should display 2 rolls on the stand
If the scale measures 306g +/- 5g it should display 3 rolls on the stand
of course vice-versa if a roll has been used. I think I may could use the counter-helper Counter - Home Assistant in some way.
something like this in this thread: Toilet paper sensor - #7 by diplix
This would create a sensor showing number of rolls:
sensor:
- platform: hx711
name: "Paperholder Value"
id: paperholder_value
dout_pin: D1
clk_pin: D2
gain: 128
update_interval: 2s
filters:
- calibrate_linear:
- -28066 -> 0
- -187602 -> 101
unit_of_measurement: g
text_sensor:
- platform: template
name: Number of Rolls
lambda: |-
if ((id(paperholder_value).state >= 97) and (id(paperholder_value).state <=107)) {
return {"1 Roll"};
}
if ((id(paperholder_value).state >= 199) and (id(paperholder_value).state <=209)) {
return {"2 Rolls"};
}
if ((id(paperholder_value).state >= 301) and (id(paperholder_value).state <=311)) {
return {"3 Rolls"};
} else {
return {"Empty"};
}
update_interval: 5s
or maybe this:
sensor:
- platform: hx711
name: "Paperholder Value"
id: paperholder_value
dout_pin: D1
clk_pin: D2
gain: 128
update_interval: 2s
filters:
- calibrate_linear:
- -28066 -> 0
- -187602 -> 101
unit_of_measurement: g
- platform: template
name: Rolls
lambda: |-
if ((id(paperholder_value).state >= 97) and (id(paperholder_value).state <=107)) {
return 1;
}
if ((id(paperholder_value).state >= 199) and (id(paperholder_value).state <=209)) {
return 2;
}
if ((id(paperholder_value).state >= 301) and (id(paperholder_value).state <=311)) {
return 3;
} else {
return 0;
}
update_interval: 5s
unit_of_measurement: rolls
made my day! the first config worked like a charm! now I understand the mechanism better. Now I have to finetune the values and post the project as soon as I have finished the build.
1 Like