Daily Propane Usage

I have this code created by ChatGPT.

The automation part of the code works insofar as the variable “input_number.371_previous_propane_level” is populated with the value of “sensor.propane_tank_neevo_371_gallons”

But I don’t understand how the “sensor:” section gets updated daily.

Nor do I understand how this will keep a history of the daily usage.

input_number:
  371_previous_propane_level:
    name: "371 Previous Propane Level"
    min: 0
    max: 1000
    step: 0.1
    unit_of_measurement: "G"

sensor:
  - platform: template
    sensors:
      daily_propane_usage:
        friendly_name: "371 Daily Propane Usage"
        unit_of_measurement: "G"
        value_template: >
          {% set current_level_371 = states('sensor.propane_tank_neevo_371_gallons') | float %}
          {% set previous_level_371 = states('input_number.371_previous_propane_level') | float %}
          {% if current_level_371 < previous_level_371 %}
            {{ previous_level_371 - current_level_371 }}
          {% else %}
            0
          {% endif %}

automation:
  - alias: "371 Store Previous Propane Level"
    trigger:
      platform: time
      at: "23:59:00"  # Run at 11:59:00pm every day
    action:
      - service: input_number.set_value
        target:
          entity_id: input_number.371_previous_propane_level
        data:
          value: "{{ states('sensor.propane_tank_neevo_371_gallons') | float }}"


Thank you.

Stop using LLMs. They are trained on old out of date config and spout bullshit.

Stop using the legacy template platform.

Use the triggered template sensor integration. Use a time trigger for whatever time of day you want it updated. No need for an automation or input number.

I am 100% certain that you are right.

But, this is what ChatGPT provided and my skills are very limited so I was hoping to get it working.

So, I don’t know how to convert the ChatGPT code to use a triggered template sensor integration.

Spending endless hours doing that would get me right back to where I am now – with code that doesn’t work to solve my problem.

I asked ChatGPT to do the conversion and this is what it came up with:

input_number:
  371_previous_propane_level:
    name: "371 Previous Propane Level"
    min: 0
    max: 1000
    step: 0.1
    unit_of_measurement: "G"

sensor:
  - platform: triggered_template
    sensor:
      name: "371 Daily Propane Usage"
      unique_id: "daily_propane_usage_371"
      unit_of_measurement: "G"
      state: >
        {% set current_level_371 = states('sensor.propane_tank_neevo_371_gallons') | float %}
        {% set previous_level_371 = states('input_number.371_previous_propane_level') | float %}
        {% if current_level_371 < previous_level_371 %}
          {{ previous_level_371 - current_level_371 }}
        {% else %}
          0
        {% endif %}
    trigger:
      - platform: state
        entity_id: sensor.propane_tank_neevo_371_gallons

automation:
  - alias: "371 Store Previous Propane Level"
    trigger:
      platform: time
      at: "23:59:00"  # Run at 11:59:00pm every day
    action:
      - service: input_number.set_value
        target:
          entity_id: input_number.371_previous_propane_level
        data:
          value: "{{ states('sensor.propane_tank_neevo_371_gallons') | float }}"

Stop asking the LLM. It does not know about any Home Assitant features since it was trained ages ago.

Read the documentation link I provided. Try to configure it yourself based on the example and if you can’t then post what you tried here and we will help.

Most people here are happy to spend their free time helping you understand home assistant for free, but that requires you to make some effort and does not include digging through LLM bullshit (providing confident incorrect answers is bullshit, not hallucination).

I do recognize and appreciate the enormous generousity of people here.

And I really have put an enormous amount of effort into Home Assistant.

I might very well have hit my current limit for further comprehension.

I did not think tracking daily usage when I have daily on-hand amounts would be this difficult, but it is.

I also didn’t realize that LLM would be so poor at being able to help.

Thought I would follow up on my ongoing efforts to get a daily propane gas usage card.

First, though, thank you very much to tom_I

I only have it running for a day, so I’m not sure if it is working, but it looks good so far.

I was able to get this far the help of reading (and re-re-re-reading) the available docs, tom_I, other member’s posts/threads, and ClaudeAI (I know I’m not supposed to because LLM are “untrustworthy” – I feel like I have no choice).

I added the following to the end of configuration.yaml:

# Claude code to update the daily changes at midnight 371
# Store midnight value as before
# Input numbers used to store daily propane level 371
input_number:
  midnight_propane_level_371_claude:
    name: "Propane Level at Midnight 371 Claude"
    min: 0
    max: 1000
    step: 0.01
  propane_refill_amount_371_claude:
    name: "Propane Refill Amount Today 371 Claude"
    min: 0
    max: 1000
    step: 0.01

  # Claude code to update the daily changes at midnight 630
  # Store midnight value as before
  # Input numbers used to store daily propane level 371
  midnight_propane_level_630_claude:
    name: "Propane Level at Midnight 630 Claude"
    min: 0
    max: 1000
    step: 0.01
  propane_refill_amount_630_claude:
    name: "Propane Refill Amount Today 630 Claude"
    min: 0
    max: 1000
    step: 0.01

Above that (in configuration.yaml), in the template: section, I added:


  # This sensor calculates daily propane usage added 12-15-2024
  - sensor:
      - name: "Daily Propane Usage 371 Claude"
        unit_of_measurement: "gal"
        state: >
          {% set midnight = states('input_number.midnight_propane_level_371_claude') | float %}
          {% set current = states('sensor.propane_tank_neevo_371_gallons') | float %}
          {% set refill = states('input_number.propane_refill_amount_371_claude') | float %}
          {% if is_number(midnight) and is_number(current) and is_number(refill) %}
            {{ ((midnight - current) + refill) | round(2) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        state_class: measurement
        device_class: volume_storage

  # This sensor calculates daily propane usage added 12-15-2024
  - sensor:
      - name: "Daily Propane Usage 630 Claude"
        unit_of_measurement: "gal"
        state: >
          {% set midnight = states('input_number.midnight_propane_level_630_claude') | float %}
          {% set current = states('sensor.propane_tank_neevo_630_gallons') | float %}
          {% set refill = states('input_number.propane_refill_amount_630_claude') | float %}
          {% if is_number(midnight) and is_number(current) and is_number(refill) %}
            {{ ((midnight - current) + refill) | round(2) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        state_class: measurement
        device_class: volume_storage

Then, in automations.yaml, I added:


# Automation to store propane level at 11-30pm daily and reset refill counter 371
- id: "1734348637909"
  alias: "Store Midnight Propane Level and Reset Refill Counter 371 Claude"
  trigger:
    - platform: time
      at: "23:30:00"
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.midnight_propane_level_371_claude
      data:
        value: "{{ states('sensor.propane_tank_neevo_371_gallons') | float }}"
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_371_claude
      data:
        value: 0

- id: "1734348637919"
  alias: "Detect Propane Refill 371 Claude"
  trigger:
    - platform: state
      entity_id: sensor.propane_tank_neevo_371_gallons
  condition:
    # Only trigger if level increased by more than 10 gallons (adjust this threshold as needed)
    - condition: template
      value_template: >
        {% set current = states('sensor.propane_tank_neevo_371_gallons') | float %}
        {% set previous = trigger.from_state.state | float %}
        {{ (current - previous) > 0.1 }}
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_371_claude
      data:
        value: >
          {% set current_refill = states('input_number.propane_refill_amount_371_claude') | float %}
          {% set new_refill = trigger.to_state.state | float - trigger.from_state.state | float %}
          {{ current_refill + new_refill }}

# Automation to store propane level at 11-30pm daily and reset refill counter 630
- id: "1734348637929"
  alias: "Store Midnight Propane Level and Reset Refill Counter 630 Claude"
  trigger:
    - platform: time
      at: "23:30:00"
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.midnight_propane_level_630_claude
      data:
        value: "{{ states('sensor.propane_tank_neevo_630_gallons') | float }}"
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_630_claude
      data:
        value: 0

- id: "1734348637939"
  alias: "Detect Propane Refill 630 Claude"
  trigger:
    - platform: state
      entity_id: sensor.propane_tank_neevo_630_gallons
  condition:
    # Only trigger if level increased by more than 10 gallons (adjust this threshold as needed)
    - condition: template
      value_template: >
        {% set current = states('sensor.propane_tank_neevo_630_gallons') | float %}
        {% set previous = trigger.from_state.state | float %}
        {{ (current - previous) > 0.1 }}
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_630_claude
      data:
        value: >
          {% set current_refill = states('input_number.propane_refill_amount_630_claude') | float %}
          {% set new_refill = trigger.to_state.state | float - trigger.from_state.state | float %}
          {{ current_refill + new_refill }}

The result is the following:

Derived from:

This is a total failure.

I simply am incapable of doing this. Yes, I have tried. Yes, I have read, reread, and rereread. Docs and threads and examples.

Perhaps you all don’t realize how skilled and smart you are and that is the reason for the implied ‘anyone can do it if they just try’ approach here, but it is just not the case.

This is the past 72 hour graph of propone used:

image

Here is the past 72 graph of propane levels:

image

Using the propane amounts in the tank for 630 (yellow) as an example:

12/20/2024 1:39pm 57.6 gallons
12/19/2024 7:46am 62.4 gallons
12/18/2024 12:00pm 67.2 gallons
12/17/2024 2:54am 69.6 gallons
12/16/2024 1:00am 74.4 gallons

Here is the automomations.yaml code:


# Automation to store propane level at 11-30pm daily and reset refill counter 371
- id: "1734348637909"
  alias: "Store Midnight Propane Level and Reset Refill Counter 371 Claude"
  trigger:
    - platform: time
      at: "23:30:00"
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.midnight_propane_level_371_claude
      data:
        value: "{{ states('sensor.propane_tank_neevo_371_gallons') | float }}"
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_371_claude
      data:
        value: 0

- id: "1734348637919"
  alias: "Detect Propane Refill 371 Claude"
  trigger:
    - platform: state
      entity_id: sensor.propane_tank_neevo_371_gallons
  condition:
    # Only trigger if level increased by more than 10 gallons (adjust this threshold as needed)
    - condition: template
      value_template: >
        {% set current = states('sensor.propane_tank_neevo_371_gallons') | float %}
        {% set previous = trigger.from_state.state | float %}
        {{ (current - previous) > 10 }}
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_371_claude
      data:
        value: >
          {% set current_refill = states('input_number.propane_refill_amount_371_claude') | float %}
          {% set new_refill = trigger.to_state.state | float - trigger.from_state.state | float %}
          {{ current_refill + new_refill }}

# Automation to store propane level at 11-30pm daily and reset refill counter 630
- id: "1734348637929"
  alias: "Store Midnight Propane Level and Reset Refill Counter 630 Claude"
  trigger:
    - platform: time
      at: "23:30:00"
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.midnight_propane_level_630_claude
      data:
        value: "{{ states('sensor.propane_tank_neevo_630_gallons') | float }}"
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_630_claude
      data:
        value: 0

- id: "1734348637939"
  alias: "Detect Propane Refill 630 Claude"
  trigger:
    - platform: state
      entity_id: sensor.propane_tank_neevo_630_gallons
  condition:
    # Only trigger if level increased by more than 10 gallons (adjust this threshold as needed)
    - condition: template
      value_template: >
        {% set current = states('sensor.propane_tank_neevo_630_gallons') | float %}
        {% set previous = trigger.from_state.state | float %}
        {{ (current - previous) > 10 }}
  action:
    - service: input_number.set_value
      target:
        entity_id: input_number.propane_refill_amount_630_claude
      data:
        value: >
          {% set current_refill = states('input_number.propane_refill_amount_630_claude') | float %}
          {% set new_refill = trigger.to_state.state | float - trigger.from_state.state | float %}
          {{ current_refill + new_refill }}

Here is the configuration.yaml code:


  # This sensor calculates daily propane usage added 12-15-2024
  - sensor:
      - name: "Daily Propane Usage 371 Claude"
        unit_of_measurement: "gal"
        state: >
          {% set midnight = states('input_number.midnight_propane_level_371_claude') | float %}
          {% set current = states('sensor.propane_tank_neevo_371_gallons') | float %}
          {% set refill = states('input_number.propane_refill_amount_371_claude') | float(0) %}
          {% if is_number(midnight) and is_number(current) and is_number(refill) %}
            {{ ((midnight - current) + refill) | round(2) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        state_class: measurement
        device_class: volume_storage


  # This sensor calculates daily propane usage added 12-15-2024
  - sensor:
      - name: "Daily Propane Usage 630 Claude"
        unit_of_measurement: "gal"
        state: >
          {% set midnight = states('input_number.midnight_propane_level_630_claude') | float %}
          {% set current = states('sensor.propane_tank_neevo_630_gallons') | float %}
          {% set refill = states('input_number.propane_refill_amount_630_claude') | float(0) %}
          {% if is_number(midnight) and is_number(current) and is_number(refill) %}
            {{ ((midnight - current) + refill) | round(2) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        state_class: measurement
        device_class: volume_storage

And


# Claude code to update the daily changes at midnight 371
# Store midnight value as before
# Input numbers used to store daily propane level 371
input_number:
  midnight_propane_level_371_claude:
    name: "Propane Level at Midnight 371 Claude"
    min: 0
    max: 1000
    step: 0.01
  propane_refill_amount_371_claude:
    name: "Propane Refill Amount Today 371 Claude"
    min: 0
    max: 1000
    step: 0.01

  # Claude code to update the daily changes at midnight 630
  # Store midnight value as before
  # Input numbers used to store daily propane level 371
  midnight_propane_level_630_claude:
    name: "Propane Level at Midnight 630 Claude"
    min: 0
    max: 1000
    step: 0.01
  propane_refill_amount_630_claude:
    name: "Propane Refill Amount Today 630 Claude"
    min: 0
    max: 1000
    step: 0.01