Add kWH cost to daily email

This commit is contained in:
Aart van Halteren
2022-09-22 22:02:28 +02:00
parent 5d86e65d8d
commit 9587277c65
2 changed files with 13 additions and 3 deletions

View File

@@ -25,6 +25,9 @@ class ReadingsMailer
# Fetch today's usage
usage_today = Reading.diff_on(Date.today)
c = Cost.new
oxxio_cost = c.oxxio_energy_cost(Date.today.to_s,usage_today[:total_kwh_consumed_high]-usage_today[:total_kwh_produced_high], usage_today[:total_kwh_consumed_low]-usage_today[:total_kwh_produced_low])
easy_cost = c.easy_energy_cost_barplot(Date.today) # side effect: generates a PNG
mail = Mail.new do
delivery_method :smtp, smtp_opts
@@ -37,7 +40,9 @@ class ReadingsMailer
-------------------------------\n\n
Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}\n
Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}\n
Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}\n
Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}\n\n
kWH cost (Oxxio): EUR #{ oxxio_cost }\n
kWH cost (EasyEnergy): EUR #{ easy_cost }\n
"
end
@@ -46,7 +51,10 @@ class ReadingsMailer
body "<h1>Summary for #{Date.today}</h1>" +
"<p>Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}</p>" +
"<p>Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}</p>" +
"<p>Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}</p>"
"<p>Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}</p>" +
"</br>" +
"<p>kWH cost (Oxxio): EUR #{ oxxio_cost} </p>" +
"<p>kWH cost (EasyEnergy): EUR #{ easy_cost} </p>"
end
end