I try to create a dashboard to have a dashboard with the consumption of different energy consumers and the produced power delivered back to the grid. I have a Tuya dual energy meter with the Tuya local integration.
The entity power_b shows the absolute energy, there is no difference between produced and consumed. See the graphic under. This Entity has an attribute direction. FORWARD and REVERSE, which refers to consumed and produced energy.
state_class: measurement
direction: REVERSE
calibration: 1
unit_of_measurement: W
device_class: power
friendly_name: xxxxxxxxxxxxx
In the graph under the total produced and the power_b.
How do I split power_b into produced and a consumed graph?
I have realized in a rather dirty way, by creating 2 sensors in configuration.yaml. I mean a dirty way, because these sensors copy the data from the original sensor under conditions. So the data will be saved multiple times and does not use the data source directly. I will appreciate if somebody know how to define the yaml in a graph using the original sensor.
template:
- sensor:
- name: “Electriteit teruggeleverd”
unique_id: energie_meterkast_power_reverse
unit_of_measurement: “W”
state: >
{% if state_attr(‘sensor.energie_meterkast_power_b’, ‘direction’) == ‘REVERSE’ %}
{{ states(‘sensor.energie_meterkast_power_b’) }}
{% else %}
0
{% endif %}
- name: “Electriteit afgenomen”
unique_id: energie_meterkast_power_forward
unit_of_measurement: “W”
state: >
{% if state_attr(‘sensor.energie_meterkast_power_b’, ‘direction’) == ‘FORWARD’ %}
{{ states(‘sensor.energie_meterkast_power_b’) }}
{% else %}
0
{% endif %}