I’ve just put a smart scale together using 4 load cells and the HX711 to keep an eye on how much beer I have left in my keg. I have the update_interval set to every couple of hours. I’m curious if it’s possible to make the update interval dynamic based on an input boolean in HA so that, say, if I have some mates come round for drinks I can switch the boolean on and make it update more frequently and then revert to the default interval when it’s back to just me.
Keep the long update interval in the sensor config (2 hours).
Then create an interval component that updates as often as you need for your thirsty guests (3 minutes?).
The actions in the interval component would be to update the sensor, but would be conditional on the input_boolean being on.
Tell your friends to bring their own beer
Do you have battery life reasons to maintain such a long update_interval? If not, varying the update interval is the wrong idea because IMHO any kind of manual intervention is antithetical to true automation. Instead, set the interval to a reasonably fast rate (e.g. 1–5 minutes) and use filters to suppress updates when the weight hasn’t changed.
sensor:
- platform: hx711
name: "HX711 Value"
update_interval: 120s
filters:
- or:
- throttle: 2h # only send an update every 2 hours
- delta: 0.2 # unless weight has changed by more than 200g
Can I mark this one as the solution?
I like your solution.
No reasons to worry about battery, it’s running off USB power. Was more just a case of thinking that it was pointless polling the weight when it’s not likely to change a huge amount. Also read some stuff on having a heap of database entries for no real reason. But I like this idea, will give it a go. Thanks.
I’m assuming then, that all the calculations are done on the chip and nothing is actually sent to HA until the weight change happens?
Correct. It’s discarded. It’s not sent to HA; it doesn’t even modify Esphome’s internal state. It’s as if the sensor read never occurred.
This is a good thing to be conscious of. I do exactly the same thing with many different sensors for exactly this reason, for example:
- platform: wifi_signal
name: ${entity_prefix} Wifi Signal
update_interval: 1min
filters:
- or:
- throttle: 30min
- delta: 10
sensor:
- platform: sht3xd
address: 0x44
update_interval: 4s
temperature:
name: ${entity_prefix} Temperature
accuracy_decimals: 1
filters:
- offset: ${temperature_offset}
- or:
- throttle: 5min
- delta: 0.15
humidity:
name: ${entity_prefix} Humidity
accuracy_decimals: 1
filters:
- offset: ${humidity_offset}
- or:
- throttle: 5min
- delta: 0.3
Awesome, thanks for the info. Will definitely consider that moving forward with the next lot of sensors I work on.