A quick introduction; I’m from the Netherlands (technician, but not a programmer, but starting to learn) and photograph and study kingfishers (Alcedo atthis) which visit my garden a few times a day. I did this for a few years with an ESP32, HX711 weigh sensor and pushed the results to my phone. As it was time consuming to set the results in Excel for further processing, I’m now trying to integrate it in HA. I have setup an ESP32 with a HX711, that’s working correctly, but I struggle a bit:
I need a quick response, sometime the kingfisher lands, spots a fish and dives straight away, so I set the interval at 1s.
when it rains, the branch where the bird will sit on slowly adds up weight to 2-10 grams, normally I correct for this every 30 min (scale.tare) if there is no weight above 20 grams (so there is no bird on the branch).
let’s just say that for convenience a kingfisher weighs 50 gram
I’m now a bit overwhelmed by all options, I checked the filter possibilities, spent hours googling, but still don’t know in which direction I can go best.
I can just store the value every second, but that will get a big database I guess?
The kingfisher visits the garden a few times a day, so I was thinking to only store those values. But than I can’t compare the measured value (lets say 53.4 grams) to the value a few seconds before (which would have been 3.4 grams because of rain). I can’t find something like that in the filters.
Is there a possibility to keep my original way of correcting this in Arduino and then integrate it in ESPHOME, or is that not the way to go? Can it be done with filtering?
Make a “copy sensor” from the HX711 and use a median filter to get the median of the last (say) 10 values. Maybe even much more like 300. This is a “longer term sensor”. This should return the weight a few seconds before the bird lands (even if it has been on the branch for a few seconds).
Then have another template sensor which is the HX711 - the copy sensor. Put a delta filter on this (say 80% of the lightest bird your expecting, let’s say 35g). Now the sensor will only pass values that change by more than 35g.That’s your weight data. It should be your “responsive and calibrated filter”. You can just push large changes only with low latency this way to HA rather than every second.
I’m not sure if my logic is quite right but perhaps it gives you ideas to try.
Yes, I did find that, but still don’t understand how and where to put the code? I think I’m completely overloooking something… I’m using the Home Assistant web interface/dashboard.
It should be something like this in your ESPHome Yaml. Code is untested.
sensor:
- platform: hx711
name: "HX711 Raw Value"
id: hx711_value_raw #Need an id to refer to it in code elsewhere.
internal: false #Toggle this to send this data to HA or just keep it internal. Maybe False intially and then True later after testing/minitoring.
dout_pin: GPIO18
clk_pin: GPIO19
gain: 128
update_interval: 1s
filters:
- calibrate_linear:
- 942656 -> 0
- 1051425 -> 50
unit_of_measurement: gram
accuracy_decimals: 1
#Long Term Senspr
- platform: copy
source_id: hx711_value_raw #Point to sensor above
id: hx711_value_moving_median
name: "HX711 Moving Median"
internal: false
accuracy_decimals: 0
filters:
#Use moving median to create "longer term sensor"
- median:
window_size: 10
send_every: 1
send_first_at: 10 # Will take ~ 10secs for first value to show up. Adjust as required.
#Subtract the background / long term weight from the more responsive weight using a template sensor / lambda
- platform: template
id: hx711_value_calibrated_delta
name: "HX711 Calibrated Delta"
accuracy_decimals: 0
internal: false
lambda: |-
return (id(hx711_value_raw).state) - (id(hx711_value_moving_median).state);
update_interval: 1s
filters:
- or: #Send a value to HA every throttle seconds, or when the value changes by more thna 34.
- throttle: 300s
- delta: 34.0
Damn, I just add it to that sensor I couldn’t find anything about it and because it is the first project with yaml, I wasn’t aware of it, I was trying to copy/duplicate the integration
Thanks, just uploaded it, it is not working completely right but that will come tomorrow, you helped me out a lot, big thanks!!
Just out of curiosity - whith the setup shown in the photo, wouldn’t the pressure vary with the place where the bird sits? Closer to the joint being lower pressure than at the far end of the stick?
I was afraid of that when starting this project too, but luckily it doesn’t matter at all. I think because there is no turning point like with a lever. Otherwise I could have solved that with a ping sensor to measure the birds position.
As for now I see it is working great, the delta is exactly 50 gr each (my calibration weight), but when the throttle of 300s (which for testing I changed to 10) is expired, the delta becomes 0. So I have to dive deeper
I mean when the bird is longer than 300 seconds on the branch, the long term sensor will then be no longer p.e. 0.7 grams, but becomes 50.7 grams, resulting in that the calibrated delta is no longer 50, but 0, when the bird leaves, it will be -50.
But tonight I’m gonna take a look at custom sensor component and give that a try, so I’m more flexible and can integrate my existing sketch, which worked always great.
I’m not familiar with Grafana, will check that out later too
Got a pretty ‘brilliant’ idea cough a few hours ago, I just put an Arduino nano between the HX711 to manage that part and communicate via I2C (or something) to the ESP32 board
I saves me a lot of hassle, maybe not the way a real programmer would choose, but for me it saves me a lot of time.