Tank levels rising or falling (trend)

I’m trying to use the trend feature so that I can be notified if my water tank levels are rising or falling.

So far, I’ve configured this in my configuration.yaml, using my cell phone’s charge percentage to test more easily:

template:
  - binary_sensor:
      - name: "Garage Left Bay Presence"
        state: "{{ states('sensor.garage_bay_left_ultrasonic_sensor')|float(0) < 2 }}"
        device_class: presence
        
  - binary_sensor:        
      - platform: trend
        sensors:
          cell_charging:
            entity_id: sensor.hein_s21_battery_level
            sample_duration: 600
            max_samples: 2
            min_gradient: 10
            device_class: battery_charging

But, I do not see any cell_charging entity when I try to create the automation.

If anyone can help me correct my mistake I would greatly appreciate it.

You have it under template (sensor) but it’s simply a binary sensor, not a binary template sensor.

So just adjust it all to the left (or put it with your other YAML binary sensors, if you have them).

Thanks, though I am quite confused as to what goes where still. I’ve tried putting it all to the left, here is my entire file:


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

template:
  - binary_sensor:
      - name: "Garage Left Bay Presence"
        state: "{{ states('sensor.garage_bay_left_ultrasonic_sensor')|float(0) < 2 }}"
        device_class: presence
        
  - sensor:
      - name: "Rainwater Tank Percentage"
        unit_of_measurement: "%"
        state_class: measurement
        state: >
          {% set total_height = 1.9 %}
          {% set distance = states('sensor.esphome_web_6d522e_water_level')|float(2) %}
          {% set distance_abs = distance - 0.181 | float(2) %}
          {% set fullness = distance_abs / total_height %}
          {{ '%.0f' | format((1-fullness)*100) | float(2)}}
        availability: "{{ has_value('sensor.esphome_web_6d522e_water_level') }}"
        
      - name: "Sump 3 Water Level Percentage"
        unit_of_measurement: "%"
        state_class: measurement
        state: >
          {% set total_height = 1.00 %}
          {% set distance = states('sensor.esphome_web_0c955c_sump_3_water_level')|float %}
          {% set distance_abs = distance - 0.07 %}
          {% set fullness = distance_abs / total_height %}
          {{ '%.0f' | format((1-fullness)*100) }}         
        availability: "{{ has_value('sensor.esphome_web_6d522e_water_level') }}"
        
      - name: "Side Tank Water Level Percentage"
        unit_of_measurement: "%"
        state_class: measurement
        state: >
          {% set total_height = 1.00 %}
          {% set distance = states('sensor.pico_side_tank_side_tank_water_level')|float %}
          {% set distance_abs = distance - 0.07 %}
          {% set fullness = distance_abs / total_height %}
          {{ '%.0f' | format((1-fullness)*100) }}         
        availability: "{{ has_value('sensor.pico_side_tank_side_tank_water_level') }}"      
    
    
sonoff:
    username: [redacted]
    password: [redacted]
    reload: always
    sensors: [power, current, voltage]

sensor:
  - platform: template
    sensors:
    #   rainwater_tank_percentage:
    #     friendly_name: "Rainwater Tank Percentage"
    #     unit_of_measurement: "%"
    #     value_template: >-
    #       {% set total_height = 1.9 %}
    #       {% set distance = states('sensor.esphome_web_6d522e_water_level')|float(2) %}
    #       {% set distance_abs = distance - 0.181 |float(2) %}
    #       {% set fullness = distance_abs / total_height|float(2) %}
    #       {{ '%.0f' | format((1-fullness)*100) | float(2)}}
          
      sump_2_water_level_percentage:
        friendly_name: "Sump 2 Water Level Percentage"
        unit_of_measurement: "%"
        value_template: >-
          {% set total_height = 1.00 %}
          {% set distance = states('sensor.esphome_web_bc8568_sump_2_water_level')|float(2) %}
          {% set distance_abs = distance - 0.07 |float(2) %}
          {% set fullness = distance_abs / total_height|float(2) %}
          {{ '%.0f' | format((1-fullness)*100) | float(2)}}

binary_sensor:
  - platform: trend
    sensors:
      cell_charging:
        entity_id: sensor.hein_s21_battery_level
        sample_duration: 600
        max_samples: 2
        min_gradient: 10
        device_class: battery_charging

I still don’t see cell_charging under entities.

I assume you’ve reloaded your config file?

Also any reason you’re not setting it up via the UI as a helper? Might be easier plus they’re slowly shifting to the UI for everything anyway.

Yes, I have reloaded a few times. I’ll checkout the helper, thanks.

So I’ve created this helper now that is supposed to switch to “Charging” when my cell phone’s battery percentage increments by 1% or more.

New trend helper:

image

I edited the helper to set the following:

The value is definitely going up:

But the helper state stays Unknown:

Any obvious wrongs I’m doing here?

Looks like you’re tracking the state class (which obviously isn’t changing nor is it numeric) versus just the state of the entity itself. Never used the trend sensor, but I’m guessing you can just leave the attribute field blank to have it use the actual state of the entity.

Thanks, I was not sure what is supposed to go in that field. I’ve cleared it, nothing selected in attribute, but now the cell_is_charging state is “Unknown”.

It also looks like you’re only storing samples for 60 seconds, so unless your battery is changing really fast there won’t be enough samples for it to calculate a trend.

Thanks again, it’s charged 10% but it is still in a off state. I think there is more than just gui work here. Trend - Home Assistant I’ll read up and see if there’s a youtube about it.

Reading up on the docs is always wise. It also looks like you’re using a minimum rate of 1, which per the definition right beneath it means unless it’s charging 1%/sec, it’s always going to be off.

yea that part does not make sense to me. Very few things move that fast. My battery % (and tank level etc) is measured in 1% increments (whole numbers). I assumed I misunderstood it.

Yeah, I agree the timeframe seem unintuitive for most things, but I assume the intent is to use decimals. Never used that integration though, just reading/interpreting the docs.

1 Like