I hope this is a super, super quick question. I have a modbus variable/readout that contains the current Power Grid Usage, in near-realtime. Sensor is sensor.e3dc_grid_power. This is…
a) Zero if total equilibrium is reached (this like, never happens).
b) positive number if I am TAKING power FROM the grid INTO my house or
c) negative number if I am PUTTING power FROM my HOUSE into the GRID.
For the energy dashboard I need two different sensors, one for “grid in” and the other “grid out”. So I created two new sensors:
- sensor:
- name: "Grid Power In"
unit_of_measurement: "W"
state_class: measurement
device_class: power
state: >
{% if states('sensor.e3dc_grid_power') | float(0) >= 0 %}
{% set gridin = states('sensor.e3dc_grid_power') | float(0) %}
{% else %}
{% set gridin = 0 %}
{% endif %}
{{ gridin }}
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
This works; I get 0 if the reading is below zero, else the readout of the variable. For the opposite direction I have this:
- sensor:
- name: "Grid Power Out"
unit_of_measurement: "W"
state_class: measurement
device_class: power
state: >
{% if states('sensor.e3dc_grid_power') | float(0) =< 0 %}
{% set gridout = (states('sensor.e3dc_grid_power') *-1) %}
{% else %}
{% set gridout = 0 %}
{% endif %}
{{ gridout }}
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
This… Does not work. If the reading is positive, zero is returned. But I need a positive reading so I wanted to add a “*-1”, so the negative value is converted to the positive value. Yields… nothing, tho. What am I doing wrong here?
After I got both sensors up, I can use the Riemann Sum Integral to get that into the Dashboard. Which already works in one direction. I am just missing the other way