Splitting sensor to two other

Hi,

Templates are a bit new field in HomeAssistant for me and I do not understand them yet. I heavily count on someones help with start in this matter.

I have a sensor (sensor.saj_grid_load_power) that can get negatives and positives numeric values (power exchange with grid). I would like to split it into import and export sensors with template.

import sensor would be easier as it only should copy main sensor value from range 0 to say 14000W and nothing else.

Export sensor is a bit more complex, as it must copy main sensor value from o to -1600W (as here in Western Downunder we do have power export limit to 1500W) and then changing it from negative value to regular one.

If that help I have another sensor (sensor.saj_direction_grid) that have 3 states - -1 when exporting, 0 when idle here and 1 when importing power from the grid.

I use these two templates to split ‘Grid Power’ my sensor into these two sensors:

Power From Grid:

{% if states('sensor.tesla_pw2_grid_power_w') | int > 0 %}
  {{ states('sensor.tesla_pw2_grid_power_w') | int }}
{% else %}
  0
{% endif %}

Power To Grid:

{% if states('sensor.tesla_pw2_grid_power_w') | int < 0 %}
  {{ (-1) * states('sensor.tesla_pw2_grid_power_w') | int }}
{% else %}
  0
{% endif %}

Works perfectly - thank you for this :slight_smile: