How to Push Notify Recorded Weight Changes?

I setup some loadcells and report the weight of my beer kegs to home assistant, that is all working fine and dandy.

I also setup automation to push notify me when the volume gets too low.

The dream is so also have it notify me and display the amount of oz when they change. For example, When I pour a 10oz glass I want a push notification to my phone saying “you just poured a 10oz glass”.

Is this possible?

I push the loadcell data every 20 seconds, the “plan” was for wait for the sensor to see a dip in weight from when the new loadcell data comes and and just report the dip, that should report the live pour to my phone. Id imagine it would also need to pass a threshold so I dont get notifications for every tiny dip in weight, like if its more then 3oz then send the push. Im just not sure how to do that, any recommendations?

Since you didn’t really provide any details on what sensors are available and what the units are we can only give general advice…

You can do what you want with templates but that’s a bit advanced for a brand new user. Not out of the question tho.

you will need to use the data from the state before the change and the new state to calculate the weight change. then use that difference in the push notification.

Hello, if you dont mind I can provide what im doing (which is not working) any input would be great. config/automation - Album on Imgur

it’s usually preferable to post actual text instead of screenshots. It keeps me from needing to type everything out again if I need to edit something. It’s easier to copy/paste.

make sure it’s correctly formatted as well.

sensor:
  - platform: mqtt
    name: "Keg 1 oz"
    state_topic: "tele/Keg1/SENSOR"
    value_template: "{{ ((value_json.HX711.WeightRaw | float - 14668) | float * 0.0338) | round(0) }}"
    unit_of_measurement: "fl. oz."

  - platform: mqtt
    name: "Keg 1 gallon"
    state_topic: "tele/Keg1/SENSOR"
    value_template: "{{ ((value_json.HX711.WeightRaw | float - 14668) | float * 0.000264) | round(2) }}"
    unit_of_measurement: "gal"

  - platform: statistics
    name: "Keg 1 pour"
    entity_id: sensor.keg_1_oz
    state_characteristic: change

- id: '1645659076329'
  alias: New Automation
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.keg_1_oz
    below: '3'
  condition: []
  action:
  - service: notify.mobile_app_matts_iphone
    data:
      title: Keg 1 Pour Detected
      message: You just poured {{ states('sensor.keg_1_pour') }} oz
  mode: single

I’ve never really used the statistics sensor so just now learning it but…

I think you will need to define the number of samples in order to use the “state_characteristic: change” option.

the description for that option says:

The difference between the oldest and newest measurement stored.

Which tells me that it will use the value of the first sample and then the value of the last sample. then since the default “sample_size” is 20 (and you haven’t specified a different value) then it will look at value of sample 1 and then the value of sample 20 and subtract the two to get the “change” value.

Since your sensor updates every 20 seconds it will take 20 seconds * 20 samples = 400 seconds = 6 min 40 seconds to get that pour value change.

since it updates every 20 seconds you could change the sample size to 2 and then assume it takes less than 20 seconds to pour a glass of beer. That could get you the pour value change.

However, I’m not sure what would happen if the sensor updated right in the middle of your pour. That would cause the value to be off and you wouldn’t get the correct value in the notification. Or you might get 2 notifications - one that says “you just poured 4 oz” followed some seconds later by another notification that says “you just poured 6 oz” (for a single 10 oz pour divided over 2 pour samples). I don’t know how to solve that problem using a statistics sensor. Maybe there is but I just don’t know enough about it.

…thinking on this for a while now…I’m not sure you will be able to do what you want.

there are too many variables to account for.

You already said that you needed to use a change greater than 3 oz due to variations in the sensor. (BTW, you have the numeric_state trigger ion your automation backwards. It should be “above: 3” not “below: 3”).

how long in time is a pour? a small one is a shorter time than a bigger one.

how long is there between pours? if it’s just you then that time will likely be a while (hopefully… :wink: :laughing:). If there are 4 of you pouring drinks it could be pretty often.

None of the solutions I can think of will ever be able to take all of those variables into account and give you a real-time notification of how much the last pour amount was to any degree of accuracy - especially if your sensor is ±3 oz at any point in time.

You were right on the sample_size being needed, I set that to 2 and I just got it working! So now I see an entity updating every time data is pushed with the difference.

Now the automation is not working… more specifically the trigger is not working. Any ideas?

I know the statistic works and posts the right data, I also know that the action works since I tested it in dev tools. It has to be the trigger which is not working. I have a similar automation setup to let me know (by numeric_state) when the keg gets below a gallon, so im not sure why this is not working considering they are similar on the setup. Any ideas?

- id: '1645659076329'
  alias: Keg 1 Pour Notification
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.keg_1_pour
    above: '3'
  condition: []
  action:
  - service: notify.mobile_app_matts_iphone
    data:
      title: Keg 1 Pour Detected
      message: You just poured {{ states('sensor.keg_1_pour') }} oz
  mode: single

the trigger will only activate if the “sensor.keg_1_pour” goes from below 3 to above 3 (you originally had it set so that the “keg_1_oz” sensor had to go from above 3 to below 3 so I knew that wouldn’t work).

could you describe to me again when you want to get the notification?

I believe from what you said before that you could try to use the state change in the sensor as a trigger instead of a numeric state crossing a threshold.

it’s hard to imagine what might work since I don’t have you sensors for live values for me to test with.

so try this and see what you get:

- id: '1645659076329'
  alias: Keg 1 Pour Notification
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.keg_1_pour
  condition: []
  action:
  - service: notify.mobile_app_matts_iphone
    data:
      title: Keg 1 Pour Detected
      message: You just poured {{ states('sensor.keg_1_pour') }} oz
  mode: single

Ah ok after tinkering quite a bit with stuff I got it working! Right now data is getting sent every 30 seconds. I may even bump up the timer to every minute. Still need to test. I just poured a glass and it was only .3oz off. Here is the code if you are interested or if anyone in the future is interested:

sensor:
  - platform: mqtt
    name: "Keg 1 oz"
    state_topic: "tele/Keg1/SENSOR"
    value_template: "{{ ((value_json.HX711.WeightRaw | float - 14434) | float * 0.0338) | round(1) }}"
    unit_of_measurement: "fl. oz."
    
  - platform: mqtt
    name: "Keg 1 gallon"
    state_topic: "tele/Keg1/SENSOR"
    value_template: "{{ ((value_json.HX711.WeightRaw | float - 14434) | float * 0.000264) | round(2) }}"
    unit_of_measurement: "gal"

  - platform: statistics
    name: "Keg 1 pour"
    entity_id: sensor.keg_1_oz
    state_characteristic: change_sample
    sampling_size: 2
    precision: 1

automation:
- id: '1645659076329'
  alias: Keg 1 Pour Notification
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.keg_1_pour
    below: '-3'
  condition: []
  action:
  - service: notify.mobile_app_matts_iphone
    data:
      title: Keg 1 Pour Detected
      message: You just poured {{ states('sensor.keg_1_pour') }} oz
  mode: single

I still don’t think that numeric state trigger looks right but you say it’s working so I can’t argue with results.

Glad you got it working.