Refill Trigger

I’m trying to setup an automation that triggers when a tank has been refilled. Specifically, I want to trigger when:

From Below 60
To Above 75

However the only triggers that take into account the old state are things like state triggers that don’t use things like below and above.

I’ve tried toying with templates, but can’t find a way to use the old state to compare to the new state.

You could use “above 75” as a trigger and a template condition in order to check the previous state:

{{ (trigger.from_state.state | int(0)) < 60 }}"

With below 60 and above 75 it will only trigger if there is no other readings in between.

So if the sensor says.
25
40
60
70
80
then it will not trigger.

25 then 80 will trigger it.

I’m not looking for below 60 and above 75, I’m looking for

changes from below 60 to above 75

I’m trying to trigger when it gets refilled.

That is exactly what I explained.

In one step or in multiple steps in between?

Here’s the scenario:

I’ve got a node-red job that polls the REST API for my propane tank level sensor every hour. Let’s say the propane company comes out at 7:30 and refills the tank. The tank was at say 52% and now it’s at 79%. I want to get a notification that the tank was refilled.

In order to do this I need to trigger when the previous state was below 60 and the new state is above 75

Put your tank’s REST sensor into a Trend binary sensor and run the automation, if the trend sensor’s state changes from off to on (ascending REST sensor value).

Not a bad idea, except the sensor value will change slightly depending on the outside air temp. As the day warms up the pressure inside the tank will increase, slightly changing the value of the sensor to read fuller throughout the day. This is why it has to be large scale change from below 60 to above 75. In a typical day the reading may be 68 in the morning and 70 in the afternoon. In a trend sensor that’s a false trigger.

Create an “input number” helper (using the UI):

input_number:
  tank_lowest:
    name: Propaine Tank's Lowest 
    initial: 0

Create an automation, that updates the input helper to the new minimum, whenever your tank’s sensor reports a change.

automation:
- alias: tank_fill_goes_down
  trigger:
  - platform: numeric_state
    entity_id: sensor.tank_rest_sensor
    below: input_number.tank_lowest
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: "{{ states('sensor.tank_rest_sensor') | float }}"
    target:
      entity_id: input_number.tank_lowest
  mode: single

Create a second automation, that reports refill and “resets” the input helper:

automation:
- alias: tank_refill
  trigger:
    - platform: template
      value_template: "{{ (states('sensor.tank_rest_sensor') | float) - (states('input_number.tank_lowest') | float) > 20 }}"
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: '{{ states(''sensor.tank_rest_sensor'') | float }}'
    target:
      entity_id: input_number.tank_lowest
  - service: notify ...
  mode: single

Be aware, that the automation code above may neither be valid nor working, it’s a hint.

This is probably the best I’ve seen so far. I ended up taking the easy way out. I modified my node-red flow to record the value the entity before updating it. Then it compares the two and if the criteria fits, it fires an event over to HomeAssistant and then I’ve got an automation that triggers on the event. No extra helpers needed.

Although I do like your idea of a tank min number helper. That could be useful in other logic as well. I may end up going with your solution after all.

1 Like