Hint on Improving My Tesla EV Charging Power Calculation

Hi Folks,
I’m trying to use the sampled data from the Tesla EV Integration to derive power usage numbers. You would think that the integration would output power usage as a state, but it doesn’t. There is a energy_added sensor but that measures “cumulative power” (energy), and I want to see energy.

Right now I have things almost working with the sensor.yaml file below. But I need a way to only use this calculation when my Teslas are at home. I don’t want to log power when I’m charging at other locations.


platform: template
sensors:
     model_3_power:
        friendly_name: Model 3 Charging Power
        unit_of_measurement: 'W'
        value_template: "{{ state_attr('sensor.blue_comet_charging_rate_sensor', 'charger_actual_current') | float * state_attr('sensor.blue_comet_charging_rate_sensor', 'charger_voltage') | float}}"
     model_s_power:
        friendly_name: Model S Charging Power
        unit_of_measurement: 'W'
        value_template: "{{ state_attr('sensor.white_lightning_charging_rate_sensor', 'charger_actual_current') | float * state_attr('sensor.white_lightning_charging_rate_sensor', 'charger_voltage') | float}}"

I should be able to use the WiFi / Ubiqiti state info to tell when the car is at home (or maybe I use the Tesla binary_sensor) in the if statement below, but I’m not sure how to combine. Any hints ?


            {% if is_state('device_tracker.tesla_blue_comet', 'home') %}
              use voltage x current expression above
            {% else %}
               0
            {% endif %}