-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathenergy_counter_theorical.yaml
67 lines (60 loc) · 1.89 KB
/
energy_counter_theorical.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
# ----------------------------------------------------------------------------------------------------
# Calculate daily energy diverted
# ----------------------------------------------------------------------------------------------------
# Define the power of load plugged on the solar router
number:
- platform: template
name: "Load power"
id: load_power
min_value: 0
max_value: 99999
step: 1
unit_of_measurement: "W"
optimistic: True
restore_value: true
# Script updating the power consumed counter
script:
- id: energy_diverted_counter
mode: single
then:
- lambda: |-
double diverted_energy = id(load_power).state*id(router_level).state / 100;
if (id(consumption).state >= diverted_energy or isnan(id(consumption).state))
{
// Power diverted is consumed (or we don't know the consumption)
id(power_divertion).publish_state(diverted_energy);
}
else
{
// Power diverted is not consumed
id(power_divertion).publish_state(0.0);
}
# Sensor showing the actual energy diverted consumption
sensor:
- id: energy_diverted
platform: total_daily_energy
name: 'Total energy diverted'
power_id: power_divertion
unit_of_measurement: 'kWh'
state_class: total_increasing
device_class: energy
accuracy_decimals: 3
filters:
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
- platform: template
name: Power divertion
id: power_divertion
unit_of_measurement: 'W'
# Enable time component to
# - Update energy diverted counter
# - Reset energy at midnight
time:
- platform: homeassistant
id: homeassistant_time_for_solar_router
- platform: sntp
on_time:
# Trigger action every second
- seconds: /1
then:
- script.execute: energy_diverted_counter