Created
May 5, 2023 07:14
-
-
Save ohadlevy/84d1c8536b983875539d27d5f67c4ee2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Template sensor for values of power import (active_power > 0) | |
charging_amps: | |
friendly_name: "desired charging amps " | |
unit_of_measurement: 'A' | |
value_template: >- | |
{%- set min = 0 -%} | |
{%- set amps = min -%} | |
{%- set max = 13 -%} | |
{%- set voltage = ((states('sensor.tesla_charger_voltage') |float )) -%} | |
{%- set export = ((states('sensor.power_export') |float) / voltage ) -%} | |
{%- set import = ((states('sensor.power_import') |float) / voltage ) -%} | |
{%- set charging = ((states('sensor.tesla_state') == 'charging')) -%} | |
{%- set charging_amps = ((states('sensor.tesla_charger_actual_current'))|float) -%} | |
{%- if not charging -%} | |
{%- if import > 0 -%} | |
{%- set amps = min -%} | |
{%- elif export > 0 -%} | |
{%- set amps = export -%} | |
{%- endif %} | |
{%- endif %} | |
{%- if charging -%} | |
{%- if import > 0 -%} | |
{%- set amps = charging_amps - import -%} | |
{%- elif export > 0 -%} | |
{%- set amps = charging_amps + export -%} | |
{%- endif %} | |
{%- endif %} | |
{%- if amps > max -%} | |
{%- set amps = max -%} | |
{%- elif amps < min -%} | |
{%- set amps = min -%} | |
{%- endif %} | |
{{ amps |round}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment