-
Notifications
You must be signed in to change notification settings - Fork 9
/
owl_intuition.yaml
58 lines (56 loc) · 2.8 KB
/
owl_intuition.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
####################################################
# Owl Intuition - Energy Sensor #
####################################################
template:
# State ensures:
# - value is not set until both solar and electricity readings have been received and are no longer unknown
# - reads the values in simple variables for elec and solar, to make if statements easier to read
# - protects value going negative if one sensor resets to zero before the other at around midnight
- trigger:
- platform: state
entity_id: sensor.owl_intuition_electricity_power
sensor:
- name: "Owl Grid Power Now"
unit_of_measurement: "W"
state_class: measurement
device_class: power
state: >
{% if is_state('sensor.owl_intuition_electricity_power', 'unknown') or is_state('sensor.owl_intuition_solar_generating', 'unknown') %}
nan
{% else %}
{% set elec = states('sensor.owl_intuition_electricity_power') | float %}
{% set solar = states('sensor.owl_intuition_solar_generating') | float %}
{% if (float(elec) - float(solar)) < 0 %}
0
{% elif (float(elec) - float(solar)) > 0 %}
{{ float(elec) - float(solar) }}
{% endif %}
{% endif %}
# State ensures:
# - value is not set until both solar and electricity readings have been received and are no longer unknown
# - reads the values in simple variables for elec, solar and last_grid_today, to make if statements easier to read
# - protects value going negative if one sensor resets to zero before the other at around midnight
# - if elec - solar would be negative it uses the last value from the sensor, stored in last_grid_today
- trigger:
- platform: state
entity_id: sensor.owl_intuition_electricity_today
sensor:
- name: "Owl Grid Energy Today"
unit_of_measurement: "kWh"
state_class: total_increasing
device_class: energy
state: >
{% if is_state('sensor.owl_intuition_electricity_today', 'unknown') or is_state('sensor.owl_intuition_solar_generated_today', 'unknown') %}
nan
{% else %}
{% set elec = states('sensor.owl_intuition_electricity_today') | float %}
{% set solar = states('sensor.owl_intuition_solar_generated_today') | float %}
{% set last_grid_today = states('sensor.owl_grid_energy_today') | float(default=0) %}
{% if (float(elec) - float(solar)) >= 0 %}
{% if ((float(elec) - float(solar)) > float(last_grid_today)) or ((float(elec) - float(solar)) < 1 ) %}
{{ float(elec) - float(solar) }}
{% else %}
{{ float(last_grid_today) }}
{% endif %}
{% endif %}
{% endif %}