Skip to content

Commit

Permalink
adjusting energy entities and cards
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatik committed Mar 12, 2024
1 parent e96a2b2 commit 9853358
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,29 @@ card_energy_daily_graph:
card_monthly_statistics:
variables:
ulm_card_monthly_statistics_name: ''
ulm_card_monthly_statistics_time: ''
ulm_card_monthly_statistics_time: null
ulm_card_monthly_statistics_cost: ''
template: card_generic
name: "[[[ return variables.ulm_card_monthly_statistics_name; ]]]"
icon: mdi:lightning-bolt
label: |
[[[
var sec_num = states[variables.ulm_card_monthly_statistics_time].state * 3600;
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = Math.floor(sec_num - (hours * 3600) - (minutes * 60));
var response = '';
if (hours > 0) { response += hours + 'h'; }
if (hours > 0 || minutes > 0) { response += ' ' + minutes + 'm'; }
if (seconds > 0) { response += ' ' + seconds + 's'; }
if (hours == 0 && minutes == 0 && seconds == 0) { response = '0s' }
if (variables.ulm_card_monthly_statistics_time != null) {
var sec_num = states[variables.ulm_card_monthly_statistics_time].state * 3600;
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = Math.floor(sec_num - (hours * 3600) - (minutes * 60));
if (hours > 0) { response += hours + 'h'; }
if (hours > 0 || minutes > 0) { response += ' ' + minutes + 'm'; }
if (seconds > 0) { response += ' ' + seconds + 's'; }
if (hours == 0 && minutes == 0 && seconds == 0) { response = '0s' }
response += ' • ';
}
response += ' • ' + parseFloat(entity.state).toFixed(2) + ' kWh' + ' • ₪ ' + states[variables.ulm_card_monthly_statistics_cost].state;
response += parseFloat(entity.state).toFixed(2) + ' kWh' + ' • ₪ ' + parseFloat(states[variables.ulm_card_monthly_statistics_cost].state).toFixed(2);
return response;
]]]
Expand Down
79 changes: 76 additions & 3 deletions homeassistant/config/lovelace_tiles/views/view_energy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,79 @@ cards:
cards:



############################################################################
# #
# General #
# #
############################################################################

- type: horizontal-stack
cards:

- type: custom:button-card
template: title
name: Electricity

- type: "custom:mod-card"
style:
.: |
ha-card {
margin: var(--grid-layout-margins) !important;
}
card:

type: custom:layout-card
layout_type: grid
layout_options:
grid-template-columns: 1fr 1fr
grid-template-rows: auto
grid-gap: 0px 2px
mediaquery:
"(max-width: 450px)":
grid-template-columns: 1fr
cards:

# Daily
- type: 'custom:button-card'
template: card_energy_daily_graph
variables:
ulm_card_energy_name: Daily
ulm_card_energy_entity: sensor.iec_today_electric_consumption
ulm_card_energy_cost_entity: sensor.electricity_cost_today
ulm_card_energy_type: bar
ulm_card_energy_show_extrema: false
ulm_card_energy_show_average: false
ulm_card_energy_hours: 168
view_layout:
grid-row-start: span 3

# Current Month
- type: 'custom:button-card'
template: card_monthly_statistics
entity: sensor.iec_this_month_electric_consumption
variables:
ulm_card_monthly_statistics_name: Current Month
ulm_card_monthly_statistics_cost: sensor.electricity_cost_curr_month

# Current Bill
- type: 'custom:button-card'
template: card_monthly_statistics
entity: sensor.next_bill_electric_forecasted_usage
variables:
ulm_card_monthly_statistics_name: Current Bill
ulm_card_monthly_statistics_cost: sensor.next_bill_electric_forecasted_cost

# Previous Bill
- type: 'custom:button-card'
template: card_monthly_statistics
entity: sensor.last_iec_bill_electric_usage_to_date
variables:
ulm_card_monthly_statistics_name: Previous Bill
ulm_card_monthly_statistics_cost: sensor.last_iec_bill_electric_cost



############################################################################
# #
# Boiler #
Expand Down Expand Up @@ -112,7 +185,7 @@ cards:
# Previous Month
- type: 'custom:button-card'
template: card_monthly_statistics
entity: sensor.switcher_boiler_monthly_energy
entity: sensor.switcher_boiler_prev_month_energy
variables:
ulm_card_monthly_statistics_name: Previous Month
ulm_card_monthly_statistics_time: sensor.boiler_running_time_prev_month
Expand Down Expand Up @@ -178,7 +251,7 @@ cards:
# Previous Month
- type: 'custom:button-card'
template: card_monthly_statistics
entity: sensor.bathroom_heater_monthly_energy
entity: sensor.bathroom_heater_prev_month_energy
variables:
ulm_card_monthly_statistics_name: Previous Month
ulm_card_monthly_statistics_time: sensor.bathroom_heater_running_time_prev_month
Expand Down Expand Up @@ -244,7 +317,7 @@ cards:
# Previous Month
- type: 'custom:button-card'
template: card_monthly_statistics
entity: sensor.parents_bathroom_heater_monthly_energy
entity: sensor.parents_bathroom_heater_prev_month_energy
variables:
ulm_card_monthly_statistics_name: Previous Month
ulm_card_monthly_statistics_time: sensor.parents_bathroom_heater_running_time_prev_month
Expand Down
36 changes: 35 additions & 1 deletion homeassistant/config/packages/energy/sensors_energy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,38 @@ template:
unique_id: electricity_current_price
icon: mdi:cash
unit_of_measurement: "ILS/kWh"
state: 0.625
#state: 0.625
state: >-
{% set price = states('sensor.iec_kwh_tariff')|float * 1 %}
{{ price }}
############################################################################
# #
# Cost Count #
# #
############################################################################

# Today Cost
- name: "electricity_cost_today"
unique_id: electricity_cost_today
unit_of_measurement: ""
state_class: total
device_class: monetary
state: "{{ ( states('sensor.iec_today_electric_consumption') | float(0) * states('sensor.electricity_current_price') | float(0) ) | round(2) }}"

# Yesterday Cost
- name: "electricity_cost_yesterday"
unique_id: electricity_cost_yesterday
unit_of_measurement: ""
state_class: total
device_class: monetary
state: "{{ ( states('sensor.iec_yesterday_electric_consumption') | float(0) * states('sensor.electricity_current_price') | float(0) ) | round(2) }}"

# Curr Month Cost
- name: "electricity_cost_curr_month"
unique_id: electricity_cost_curr_month
unit_of_measurement: ""
state_class: total
device_class: monetary
state: "{{ ( states('sensor.iec_this_month_electric_consumption') | float(0) * states('sensor.electricity_current_price') | float(0) ) | round(2) }}"
18 changes: 18 additions & 0 deletions homeassistant/config/packages/heaters/sensors_heaters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ template:
device_class: monetary
state: "{{ ( state_attr('sensor.bathroom_heater_monthly_energy', 'last_period') | float(0) * states('sensor.electricity_current_price') | float(0) ) | round(2) }}"

# Bathroom Heater Previous Month Energy
- name: "bathroom_heater_prev_month_energy"
unique_id: bathroom_heater_prev_month_energy
unit_of_measurement: kWh
device_class: "energy"
state: >-
{{ state_attr('sensor.bathroom_heater_monthly_energy', 'last_period') }}
############################################################################
Expand Down Expand Up @@ -181,6 +189,16 @@ template:
device_class: monetary
state: "{{ ( state_attr('sensor.parents_bathroom_heater_monthly_energy', 'last_period') | float(0) * states('sensor.electricity_current_price') | float(0) ) | round(2) }}"

# Parents Bathroom Heater Previous Month Energy
- name: "parents_bathroom_heater_prev_month_energy"
unique_id: parents_bathroom_heater_prev_month_energy
unit_of_measurement: kWh
device_class: "energy"
state: >-
{{ state_attr('sensor.parents_bathroom_heater_monthly_energy', 'last_period') }}
############################################################################
# #
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ template:
off
{% endif %}
# Previous Month Energy
- name: "switcher_boiler_prev_month_energy"
unique_id: switcher_boiler_prev_month_energy
unit_of_measurement: kWh
device_class: "energy"
state: >-
{{ state_attr('sensor.switcher_boiler_monthly_energy', 'last_period') }}
############################################################################
Expand Down

0 comments on commit 9853358

Please sign in to comment.