Skip to content

Instantly share code, notes, and snippets.

@ndbroadbent
Created September 21, 2023 08:40
Show Gist options
  • Save ndbroadbent/95aaeebbd35cd02745b2d33628574e04 to your computer and use it in GitHub Desktop.
Save ndbroadbent/95aaeebbd35cd02745b2d33628574e04 to your computer and use it in GitHub Desktop.
lpg_bottles.yaml
# https://www.elgas.co.nz/resources/elgas-blog/138-nz-lpg-conversion-values-kg-litres-mj-a-kwh/
# Convert LPG litres to kWh: 1 L = 7.4 kWh of energy from LPG# https://www.elgas.com.au/for-home/gas-cylinder-sizes
# Gas bottle is about 1m tall, filled to 75% of capacity (750mm)
# 45 kg LPG cylinder capacity = 88 litres
# 88L * 0.75 = 66L
# 66L * 7.4 kWh/L = 488.4 kWh
# https://www.elgas.co.nz/resources/elgas-blog/275-how-is-lpg-measured-weight-liquid-gaseous-volume-energy-content-pressure
# LPG (propane) expands at 1.5% per 5.55°C temperature increase.
lpg_bottles:
sensor:
- platform: filter
unique_id: filtered_lpg_bottle_sensor_distance
name: "Filtered LPG Bottle Sensor Distance"
entity_id: sensor.garage_gas_bottle_receiver_lpg_bottle_sensor_distance
filters:
- filter: outlier
window_size: 4
radius: 10
- filter: lowpass
time_constant: 10
- filter: time_simple_moving_average
window_size: "00:30"
precision: 2
- platform: template
sensors:
lpg_percentage_remaining:
unique_id: lpg_percentage_remaining
friendly_name: "LPG Percentage Remaining"
unit_of_measurement: "%"
value_template: >
{% if has_value('sensor.filtered_lpg_bottle_sensor_distance') %}
{{ (((states('sensor.filtered_lpg_bottle_sensor_distance') | float) / 750.0) * 100) | round }}
{% endif %}
total_lpg_use_litres:
unique_id: total_lpg_use_litres
friendly_name: "Total LPG Use Litres"
unit_of_measurement: "L"
value_template: >
{% if has_value('sensor.filtered_lpg_bottle_sensor_distance') %}
{{ ((1 - ((states('sensor.filtered_lpg_bottle_sensor_distance') | float) / 750.0)) * 66) | round(2) }}
{% endif %}
lpg_remaining_litres:
unique_id: lpg_remaining_litres
friendly_name: "LPG Remaining Litres"
unit_of_measurement: "L"
value_template: >
{% if has_value('sensor.total_lpg_use_litres') %}
{{ (66.0 - (states('sensor.total_lpg_use_litres') | float)) | round(2) }}
{% endif %}
total_lpg_use_kwh:
unique_id: total_lpg_use_kwh
friendly_name: "Total LPG Use"
unit_of_measurement: "kWh"
value_template: >
{% if has_value('sensor.total_lpg_use_litres') %}
{{ ((states('sensor.total_lpg_use_litres') | float) * 7.4) | round(2) }}
{% endif %}
lpg_remaining_kwh:
unique_id: lpg_remaining_kwh
friendly_name: "LPG Remaining"
unit_of_measurement: "kWh"
value_template: >
{% if has_value('sensor.lpg_remaining_litres') %}
{{ ((states('sensor.lpg_remaining_litres') | float) * 7.4) | round(2) }}
{% endif %}
lpg_days_remaining:
unique_id: lpg_days_remaining
friendly_name: "LPG Days Remaining"
unit_of_measurement: "days"
value_template: >
{% if has_value('sensor.lpg_remaining_kwh') and has_value('sensor.average_daily_lpg_kwh_use') and (states('sensor.average_daily_lpg_kwh_use') | float) > 0 %}
{{ ((states('sensor.lpg_remaining_kwh') | float) / (states('sensor.average_daily_lpg_kwh_use') | float)) | round(2) }}
{% endif %}
- platform: statistics
name: "Average Daily LPG kWh Use"
entity_id: sensor.daily_lpg_kwh_use_max
state_characteristic: mean
max_age:
days: 14
utility_meter:
daily_lpg_kwh_use:
source: sensor.total_lpg_use_kwh
name: Daily LPG kWh Use
cycle: daily
weekly_lpg_kwh_use:
source: sensor.total_lpg_use_kwh
name: Weekly LPG kWh Use
cycle: weekly
monthly_lpg_kwh_use:
source: sensor.total_lpg_use_kwh
name: Monthly LPG kWh Use
cycle: monthly
yearly_lpg_kwh_use:
source: sensor.total_lpg_use_kwh
name: Yearly LPG kWh Use
cycle: yearly
template:
- trigger:
- platform: time
at: "23:59:59"
sensor:
- name: "Daily LPG kWh Use Max"
unit_of_measurement: "kWh"
state: "{{ states('sensor.daily_lpg_kwh_use') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment