-
Notifications
You must be signed in to change notification settings - Fork 0
/
example HomeAssistant package - propane_scale_fireplace.yaml
234 lines (210 loc) · 8.31 KB
/
example HomeAssistant package - propane_scale_fireplace.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# Home Assistant interfacing for propane tank scale operation
# Selection for size of tank
input_select:
fireplace_propane_tank_size:
name: Fireplace Propane Tank Size
options:
- 20lb Tank
- 40lb Tank
initial: 40lb Tank
icon: mdi:propane-tank-outline
# scale zero offset for calibration
input_number:
fireplace_propane_scale_zero_offset:
name: Fireplace Propane Scale Zero Offset
min: -9
max: 9
step: 0.1
unit_of_measurement: "lb"
template:
- sensor:
# Sensor for scale zero weight offset
- name: "Fireplace Propane Weight Corrected"
unit_of_measurement: "lb"
icon: "mdi:scale"
device_class: "weight"
state_class: "measurement"
state: >
{{ states('sensor.fireplace_propane_weight') | float(default="unknown") - states('input_number.fireplace_propane_scale_zero_offset') | float(default="unknown") }}
# Sensor for tank empty weight
- name: "Fireplace Propane Tank Empty Weight"
unit_of_measurement: "lb"
icon: "mdi:weight-pound"
device_class: "weight"
state_class: "measurement"
state: >-
{% if states('input_select.fireplace_propane_tank_size') == "20lb Tank" %}
{# My actual tanks TW: 17.7, 18 #}
18
{% elif states('input_select.fireplace_propane_tank_size') == "40lb Tank" %}
{# My actual tanks TW: 29.9, 31.3 #}
31
{% else %}
unknown
{% endif %}
# Sensor for tank capacity
- name: "Fireplace Propane Tank Fuel Capacity"
unit_of_measurement: "lb"
icon: "mdi:weight-pound"
device_class: "weight"
state_class: "measurement"
state: >-
{% if states('input_select.fireplace_propane_tank_size') == "20lb Tank" %}
20
{% elif states('input_select.fireplace_propane_tank_size') == "40lb Tank" %}
40
{% else %}
unknown
{% endif %}
# Sensor for remaining fuel lb
- name: "Fireplace Propane Fuel Remaining"
unit_of_measurement: "lb"
icon: >-
{% set fuel = states('sensor.fireplace_propane_fuel_remaining') | float(default="unknown") %}
{% set capacity = states('sensor.fireplace_propane_tank_fuel_capacity') | float(default="unknown") %}
{# Verify data is numeric #}
{% if fuel == "unknown" or capacity == "unknown" %}
mdi:alert
{% else %}
{% set fuel_percent = (fuel/capacity)*100 %}
{% if fuel <= 3 %}{# 3lb is empty, regardless of capacity #}
mdi:gauge-empty
{% elif fuel_percent > 60 %}{# "full" #}
mdi:gauge-full
{% elif fuel_percent > 30 %}{# "slightly over half" #}
mdi:gauge
{% elif fuel_percent <= 30 %}{# "slightly under half" #}
mdi:gauge-low
{% endif %}
{% endif %}
device_class: "weight"
state_class: "measurement"
state: >
{{ states('sensor.fireplace_propane_weight_corrected') | float(default="unknown") - states('sensor.fireplace_propane_tank_empty_weight') | float(default="unknown") }}
# Sensor for burn rate hourly
- name: "Fireplace Propane Fuel Consumption Hourly"
unit_of_measurement: "lb/hr"
icon: "mdi:gas-burner"
device_class: "weight"
state_class: "measurement"
state: >
{% set short_rate = -1 * (states('sensor.fireplace_propane_fuel_burn_rate_change_short_seconds') | float(default="unknown") * 3600) %}
{% set long_rate = -1 * (states('sensor.fireplace_propane_fuel_burn_rate_change_long_seconds') | float(default="unknown") * 3600) %}
{% set worst_rate = [short_rate,long_rate] | max | round(2,default="unknown") %}
{% if worst_rate < 0 %}{# Burn rate can not be increasing #}
{{ states("sensor.fireplace_propane_fuel_consumption_hourly") }}
{% else %}
{{ worst_rate }}
{% endif %}
# Sensor for burn rate daily
- name: "Fireplace Propane Fuel Consumption Daily"
unit_of_measurement: "lb/day"
icon: "mdi:gas-burner"
device_class: "weight"
state_class: "measurement"
state: >
{% set short_rate = -1 * (states('sensor.fireplace_propane_fuel_burn_rate_change_short_seconds') | float(default="unknown") * 3600 * 24) %}
{% set long_rate = -1 * (states('sensor.fireplace_propane_fuel_burn_rate_change_long_seconds') | float(default="unknown") * 3600 * 24) %}
{% set worst_rate = [short_rate,long_rate] | max | round(2,default="unknown") %}
{% if worst_rate < 0 %}{# Burn rate can not be increasing #}
{{ states("sensor.fireplace_propane_fuel_consumption_daily") }}
{% else %}
{{ worst_rate }}
{% endif %}
# Sensor for est days remaining
- name: "Fireplace Propane Fuel Est Days Remaining"
unit_of_measurement: "days"
icon: "mdi:clock-outline"
state_class: "measurement"
state: >
{% set remain = states("sensor.fireplace_propane_fuel_remaining") | float(0) %}
{% set rate = states("sensor.fireplace_propane_fuel_consumption_daily") | float(0) %}
{% if rate <= 0 %}
Off/Invalid
{% else %}
{{ (remain / rate) | int(0) }}
{% endif %}
# Sensor for est days remaining
- name: "Fireplace Propane Weight Age"
unit_of_measurement: "Seconds"
state: >
{{ (now() - states.sensor.fireplace_propane_weight.last_updated).total_seconds() | round(0,default=0) }}
sensor:
- platform: statistics
name: "Fireplace Propane Fuel Burn Rate Change Long Seconds"
entity_id: sensor.fireplace_propane_fuel_remaining
state_characteristic: change_second
precision: 20
sampling_size: 75
max_age:
hours: 24
- platform: statistics
name: "Fireplace Propane Fuel Burn Rate Change Short Seconds"
entity_id: sensor.fireplace_propane_fuel_remaining
state_characteristic: change_second
precision: 20
sampling_size: 25
max_age:
hours: 3
automation:
# Automation to force-sleep immediately after value update
- alias: "Deep Sleep ESPHome fireplace_propane"
trigger:
- platform: state
entity_id:
- sensor.fireplace_propane_weight
# Condition to skip if scale appears to be empty
condition:
condition: numeric_state
entity_id: sensor.fireplace_propane_weight
above: 10
action:
- delay: "00:00:01"
- service: switch.turn_on
entity_id: switch.fireplace_propane_deep_sleep_now
# Automation to auto-zero scale input_number when empty
- alias: "Auto Zero fireplace_propane empty-scale offset"
trigger:
- platform: state
entity_id:
- sensor.fireplace_propane_weight
# Condition only if scale appears to be empty
condition:
condition: numeric_state
entity_id: sensor.fireplace_propane_weight
below: 9
above: -9
action:
service: input_number.set_value
data:
entity_id: input_number.fireplace_propane_scale_zero_offset
value: >-
{{ states('sensor.fireplace_propane_weight') | float(default="unknown") }}
# Automation to auto-change tank size by weight
- alias: "Auto Change fireplace_propane tank size selection"
trigger:
- platform: numeric_state
entity_id: sensor.fireplace_propane_weight_corrected
below: 25
above: 10
- platform: numeric_state
entity_id: sensor.fireplace_propane_weight_corrected
above: 40
# Condition only if scale appears to be empty
condition:
condition: numeric_state
entity_id: sensor.fireplace_propane_weight_corrected
above: 10
action:
service: input_select.select_option
data:
entity_id: input_select.fireplace_propane_tank_size
option: >-
{% set weight = states('sensor.fireplace_propane_weight_corrected') | float(default="unknown") %}
{% if weight > 40 %} {# If too high, must be bigger tank #}
40lb Tank
{% elif weight < 25 and weight > 10 %}{# If not empty and too low, must be small tank #}
20lb Tank
{% else %}
Unknown
{% endif %}