Optimizing use of unused Solar Power to charge a Tesla

Wow. Thanks so much for this.
Looked for two hours yesterday why this didn’t work with me. The indentation was the answer.

Sidenote: what amazes me is that this is (more or less) the only place on Google or the internet where this topic is discussed. Which I find quite weird. And I’m pretty sure many people will try to do the same thing (in Belgium and the Netherlands, to begin with).

Sometime people just don’t know that this is possible, and could actually be done. :slight_smile:

Here’s to hope that more car manufacturers and more chargers/meters/inverter provider (and maybe even power companies who would publish real-time rate schedule) would actually open their APIs, to make things like this possible.

Yes, would be nice of Tesla had a defined open API as well, as this is all reverse engineered and not guaranteed to be supported going forward. :frowning:

Hi,
does somebody arrived to put this service call in Node Red?

Ok, so here is my version to optimize unused solar power to charge a Tesla:
prerequisite:

  • a tesla named tesla (change the car’s name in the script)
  • a solaredge inverter with a power meter
  • a tri-phase installation (single phase installation need to adapt the math in the formula in the script)

I have first created a script that will set the Amps deducting the power currently provided to the grid (converted to Amps) from the current charge rate the Tesla provides (in my case in km/h transformed to Amps)

alias: TeslaChargingSetAmps
sequence:
  - service: tesla_custom.api
    data:
      command: CHARGING_AMPS
      parameters:
        path_vars:
          vehicle_id: '{{ state_attr(''binary_sensor.tesla_online_sensor'', ''id'') }}'
        charging_amps: >-
          {{ (( states('sensor.tesla_charging_rate_sensor') | float /4.3) -
          (states('sensor.solaredge_grid_power')| float *1.4)) | round() }}
mode: queued
icon: mdi:car
max: 10

Once done, I have created an automation that checks if the car is home, charging, and every 15 minutes invokes the script that adjust the amps

alias: adjust charging car amps if charging switch is on
description: >-
  runs every 15 minutes, as SolarEdge API is invoked and is only refreshed every
  15 minutes. 

trigger:
  - minutes: /15
    platform: time_pattern
condition:
  - condition: device
    type: is_on
    device_id: xxxxxxxxxxx
    entity_id: switch.tesla_charger_switch
    domain: switch
  - condition: device
    device_id: xxxxxxxxxxxxxx
    domain: device_tracker
    entity_id: device_tracker.tesla_location_tracker
    type: is_home
action:
  - service: script.teslachargingsetamps
    data: {}

Now I still want to enable the charge at sunrise and stop at sunset. I add a 2 hours delay as the sun needs time to properly create power on my panels:

alias: Turn on car charging
description: Turn on car charging in the morning
trigger:
  - platform: sun
    event: sunrise
    offset: '02:00'
condition:
  - condition: state
    entity_id: binary_sensor.tesla_charger_sensor
    state: 'on'
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: turn_on
    device_id: xxxxxxxxxxxxxxxxxxxx
    entity_id: switch.tesla_charger_switch
    domain: switch
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: script.teslachargingsetamps
    data: {}
alias: Turn off car charging
description: Turn off car charging in the evening
trigger:
  - platform: sun
    event: sunset
    offset: '-02:00'
condition:
  - condition: state
    entity_id: switch.tesla_charger_switch
    state: 'on'
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: switch.tesla_charger_switch
    domain: switch

This still needs to be tested through properly over a couple of days.
This could be drastically improved if I would start to take the data from the Solaredge Modbus TCP connection, but I’ll keep that for future improvement.

2 Likes

Thanks! I was looking for the 15 min routine.

On top of that I will create an extra boolean “solar powered charging”, because of the fact I drive more than we have sunny hours (here in Belgium).

On my end, I plan to have a physical switch that enables those automations or completely disables them, so that I can either only charge with Solar excess or I can charge the car at full pace and override according to my needs.
A third switch position could be a trade-off of both situation with a target to charge to a certain level or something similar that I still need to figure out, but that’s optional.

Any recommendations for such a hardware, if possible not battery operated, that can fit on an existing plug? I had in mind to put a Shelly device in an unused light switch that already has a built -in led light. This could enable me to activate my automation and have a low cost low energy seamlessly built-in device with visual control…

Unsure of your need for a physical switch.

On my lovelace dashboard I have virtual switches to switch charging on/off, max charging (32A) and solar tracking (automation sets charging current based of excess solar)

If you wanted to physically switch these HA virtual buttons you could setup something like an NFC tag or a ZigBee physical button, which calls these automations.

Alternatively you could use something like a Shelly 1PM/ Kass/ MEROSS smart plug to switch charging on/off, but I would be worried about high current draw as you would be limited to 16-10 Amps, which would only give you around 2-3 kW of charging power. The Tesla HPWC can deliver 12 kW, and you wouldn’t have the excess solar option, unless you implement the earlier suggestions.

What sort of wall charger do you have?

Very nice cards!
I did not yet have time to work on that.
The reason behind a physical switch is that I’m not alone in my household and it’s quite nice to not depend too much on your screens for us. The switch with the led indicator to reassure my better half that the car is now charging at full power is a no-brainer. Now it just happen that I have an unused light switch at my kitchen-frontdoor which will perfectly fit this purpose.


Now let’s not worry, I will not set the load of the charger to à Shelly device. I want my Shelly device to just act as a trigger in HA. Mounted in such a wall-switch, the Shelly device will notice if it’s ON or OFF, which I should be able to connect to a Group switch in HA, at least that’s the plan.

As for my charger, it’s a whole different story: it’s a ABL EMH1 11kW (3-phase 16A) with an RS485 modbus module (DEFA HomeCLU) that reads the load and is able to “Peak-shave” to avoid to overpass the maximum household load. I had bought this 2 years ago (only just finished my PV-installation) to avoid upgrading my 20A installation (I live in a country where they charge you USD140/amps one-off for the upgrade). The code to communicate with it is not documented and I’m not in the mood to reverse engineer modbus.

Will see how that will work with the switch but will definitely as well create some cards at some point!

Update: found it. Missing space and replaced int by float.

I’m optimizing my “dynamic charging”, using a slightly different approach; my calculation is based on my P1 monitor value.
I’ll update an input number (tesla_current (in amps)) every 15 minutes, to run the script afterwards which sends the new values to my car (script is already working (manually)).
I’m messing with the syntax (the “value” is not correct), I’m sure:

Here’s my YAML code:

- id: '1648755281416'
  alias: Tesla - Update Tesla Amps (input number))
  description: ''
  trigger:
  - platform: time_pattern
    minutes: '15'
  condition: []
  action:
  - service: input_number.set_value
    data:
      value:'{{ (states(''input_number.tesla_current'') | int) - ((states(''sensor.p1_meter_3c39e724c5a2_active_power'') | int / 415) | round(0))}}'
    target:
      entity_id: input_number.tesla_current
  mode: single

Corrected code:

- id: '1648755281416'
  alias: Tesla - Update Tesla Amps (input number))
  description: ''
  trigger:
  - platform: time_pattern
    minutes: '15'
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: '{{ (states(''input_number.tesla_current'') | float) - ((states(''sensor.p1_meter_3c39e724c5a2_active_power'') | float / 415) | round(0))}}'
    target:
      entity_id: input_number.tesla_current
  mode: single

@bramdedaele nice, I did not know the “input_number”, great stuff.
Watch out your “time-pattern”. Your input:

minutes: '15' 

means your update will run every quarter past at every hour, hence once an hour.
If you wanted to have it run every 15 minutes (hence 4x per hour), in my understanding, you will need the backslash.

minutes: /15
1 Like

Thanks a lot for helping a newbie out @matfroh

Well, I use the “tesla_current” input_number to be able to

  • be able to adjust the amps manually when my other helper “Solar Charging” is disabled.
  • simply view what’s the current amps

PS: I stopped using the P1 meter as the value, I’ll use the solaredge current power as the value to play with. I simply didn’t get there with the code, and I want to avoid “advanced coding” (python e.g.). Still, ideally the calculation is based on the P1 meter value, when f.e. activating the laundry machine; based on the solar edge meter it won’t dynamically adjust the tesla charging.

If you read my code above, you will notice that I have a solaredge modbus energy meter, this enables me to effectively as well use only the solar excess power.
So if any other device is activated, the value changes accordingly.

Quick update here on my optimisation. In the meantime, I am now gathering the energy to the grid from the Solaredge TCP Modbus integration, in order to have live data without the slow 15 minutes interval over the solaredge API.
My worry is that now the delay comes from the Tesla API, which updates the charge rate only every 10 minutes.
2 solutions for me:

  • trigger a more frequent update of the charge rate from the API when the car is charging at home (unsure of the side effects of this)
  • get the exact rate from the charger (either by reverse engineering it’s modbus or through another cheap meter)

Nevertheless, I now run the script every 10 minutes (I could also systematically round down to avoid any step over the excess) and the picture looks nice:

Thanks for sharing @matfroh .

I’ll do mine - I’m sure it’s useful for the not-so-advanced HA-user. Although, like you, I’m not fully there yet.

I’m using the (cloud based and thus 15 min delayed) Solar Edge values to calculate my Tesla charging amps (can’t do the modbus thing, according to SolarEdge documentation).
Start charging based on P1 value, stop charging based on (almost) no more sun. Still a work in progress, but it’s working quite well already (for my requirements and skills).
All this is based on what’s been said in this thread, so many thanks for that, everyone!

Next up: using the P1 value for calculation, but I’m having a bit of trouble combining the code with the math :smiley: (plus time to look for it a bit more).
To be clear; I keep KISS high & mighty (I don’t want to copy paste large chunks of python code I don’t understand fully). These are all automations and 1 simple script (mentioned above).

Start Charging based on P1 excess

alias: Tesla - Start laden bij zon over en onder 90
description: ''
trigger:
  - platform: numeric_state
    below: '-300'
    for:
      hours: 0
      minutes: 3
      seconds: 0
    entity_id: sensor.p1_meter_3c39e724c5a2_active_power
condition:
  - condition: state
    entity_id: device_tracker.dikke_baby_location_tracker
    state: home
  - condition: state
    entity_id: binary_sensor.dikke_baby_charger_sensor
    state: 'on'
  - condition: state
    entity_id: switch.dikke_baby_charger_switch
    state: 'off'
  - condition: numeric_state
    entity_id: sensor.dikke_baby_battery_sensor
    below: '90'
action:
  - service: notify.notify
    data:
      message: Tesla begint te laden (veel zon over)
      title: Tesla automatisch laden!
  - service: switch.turn_on
    target:
      entity_id: switch.dikke_baby_charger_switch
    data: {}
  - service: script.tesla_laadsnelheid_test
    data: {}
mode: single

Calculate input_number based on SolardEdge generated power, every 15 minutes

alias: Tesla - Update Tesla Charge Amperage (input number)
description: ''
trigger:
  - platform: time_pattern
    minutes: /15
condition:
  - type: is_on
    condition: device
    device_id: d8b42c4c8cf5d20b8f9571f7dd28cbe1
    entity_id: binary_sensor.dikke_baby_charger_sensor
    domain: binary_sensor
  - condition: state
    state: home
    entity_id: device_tracker.dikke_baby_location_tracker
  - condition: state
    entity_id: switch.dikke_baby_charger_switch
    state: 'on'
  - condition: state
    entity_id: input_boolean.tesladynamiccharging
    state: 'on'
action:
  - service: input_number.set_value
    data:
      value: >
        {{ (states('sensor.solaredge_current_power') | float / 600) | round(0)
        }}
    target:
      entity_id: input_number.tesla_current
  - service: notify.notify
    data:
      message: Input number update "{{ states('input_number.tesla_current') }}"
      title: Tesla
  - service: script.tesla_laadsnelheid_test
    data: {}
mode: single

Stop Charging based on “no more sun”

alias: Tesla - Stop laden bij geen zon meer
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.solaredge_current_power
    below: '500'
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: state
    entity_id: binary_sensor.dikke_baby_charger_sensor
    state: 'on'
  - condition: state
    entity_id: device_tracker.dikke_baby_location_tracker
    state: home
  - condition: state
    entity_id: switch.dikke_baby_charger_switch
    state: 'on'
  - condition: state
    entity_id: input_boolean.teslaoverruleautostop
    state: 'off'
  - condition: numeric_state
    entity_id: sensor.dikke_baby_battery_sensor
    above: input_number.tesla_min_charge
action:
  - service: notify.notify
    data:
      message: Tesla gestopt met laden (zon weg)!
      title: Tesla
  - service: switch.turn_off
    data: {}
    target:
      device_id: d8b42c4c8cf5d20b8f9571f7dd28cbe1
  - type: turn_off
    device_id: d8b42c4c8cf5d20b8f9571f7dd28cbe1
    entity_id: switch.dikke_baby_charger_switch
    domain: switch
mode: single

Script

alias: Tesla Adust Charging Amps
sequence:
  - service: tesla_custom.api
    data:
      command: CHARGING_AMPS
      parameters:
        path_vars:
          vehicle_id: '{{ state_attr(''binary_sensor.dikke_baby_online_sensor'', ''id'') }}'
        charging_amps: '{{ states(''input_number.tesla_current'')|int }}'
mode: single
icon: mdi:battery-charging-20

What I’m working on to replace the solaredge calculated Amp value, but renders minus values, for now

alias: Tesla - TEST - Update Tesla Min Charge (P1 calc)
description: ''
trigger:
  - platform: time_pattern
    hours: /1
condition:
  - type: is_on
    condition: device
    device_id: d8b42c4c8cf5d20b8f9571f7dd28cbe1
    entity_id: binary_sensor.dikke_baby_charger_sensor
    domain: binary_sensor
  - condition: state
    state: home
    entity_id: device_tracker.dikke_baby_location_tracker
  - condition: state
    entity_id: switch.dikke_baby_charger_switch
    state: 'on'
  - condition: state
    entity_id: input_boolean.tesladynamiccharging
    state: 'on'
action:
  - service: input_number.set_value
    data:
      value: >-
        {{ (states('input_number.tesla_current_test') | float) -
        ((states('sensor.p1_meter_3c39e724c5a2_active_power') | float / 500) |
        round(0))}}
    target:
      entity_id: input_number.tesla_current_test
  - service: notify.notify
    data:
      message: >-
        Tesla - TEST P1-calculated "{{ states('input_number.tesla_current_test')
        }}"
      title: Tesla
mode: single

I’m pretty sure surrounding the code above by an “IF” ( calculation < 0, then GO, ELSE Charging Amps = 0) is a dirty solution, and that’s what I’m going for, for now.

I’m using a few helpers

And I also have a few other automations which I won’t share because of the fact they’re not relevant here (stop charging when plugged in, stop charging when no sun and < minimum charge,…)

I have SolarEdge MODBUS monitoring as well, had to switch from wifi to Ethernet. Which allows me to update every 5 seconds.

I have the Tesla API updating every 30 seconds and update the charging Amps request at twice that rate, IE every minute I set a new charging Amps.

You can make a service call from home assistant to change the Tesla API update rate, whilst charging for example.

1 Like

Modbus is definitely worth a try! All solaredge have it, although sometimes tricky to activate. You need to use the app + the mobile phone browser:

Sun is up, time to finally optimize the excess solar usage. Thanks for sharing the automation ideas, I have taken and customized a bit more.

I have a Huawei Solar inverter + Shelly EM3 energy monitor + 1-phase Tesla mobile charger.

As my Tesla battery is LFP, I can charge it to 100% but I charge it less to save some energy from regenerative braking. Don’t forget to turn off scheduled charging in the app.

Since I work from home, my plan is to charge up to 70% during the off-peak hours (or 60% when the predicted solar forecast is high). If I need a full battery, I’ll turn on the max range switch (or set it to 100% in the app) and these automations will not turn on.

These are the automations that should hopefully handle all of the cases (if not, I’ll update it):

- id: tesla_offpeak_charge
  alias: Tesla charge during offpeak hours
  description: During offpeak hours, turn on charging at max current to reach 70% battery limit
  trigger:
    - platform: homeassistant
      event: start
    - entity_id: binary_sensor.tesla_model_3_charger_sensor
      from: "off"
      platform: state
      to: "on"
    - entity_id: utility_meter.daily_house_energy
      platform: state
      to: "offpeak"
  condition:
    - alias: "Offpeak rate"
      condition: state
      entity_id: utility_meter.daily_house_energy
      state: "offpeak"
    - alias: "Charge Cable plugged in"
      condition: state
      entity_id: binary_sensor.tesla_model_3_charger_sensor
      state: "on"
    - alias: "Tesla at home"
      condition: state
      entity_id: device_tracker.tesla_location
      state: "home"
  action:
    - delay: 00:01:00
    - entity_id: switch.tesla_model_3_charger_switch
      service: switch.turn_on
    - service: tesla_custom.api
      alias: "Set Charge amps to max available at the charger"
      data:
        command: CHARGING_AMPS
        parameters:
          path_vars:
            vehicle_id: '{{ state_attr("binary_sensor.tesla_model_3_online_sensor", "id") }}'
          charging_amps: '{{ state_attr("sensor.tesla_model_3_charging_rate_sensor", "charge_current_request_max") }}'
    - service: tesla_custom.api
      alias: "Set charge limit to 70%"
      data:
        command: CHANGE_CHARGE_LIMIT
        parameters:
          path_vars:
            vehicle_id: '{{ state_attr("binary_sensor.tesla_model_3_online_sensor", "id") }}'
          percent: 70

- id: tesla_stop_peak_charge
  alias: Tesla Offpeak ended
  description: Stop charging when offpeak tariff ends and we don't need max range
  trigger:
    - entity_id: utility_meter.daily_house_energy
      platform: state
      from: "offpeak"
      to: "peak"
  condition:
    - alias: "Offpeak ended"
      condition: state
      entity_id: utility_meter.daily_house_energy
      state: "peak"
    - alias: "Not max range"
      condition: state
      entity_id: switch.tesla_model_3_maxrange_switch
      state: "off"
  action:
    - entity_id: switch.tesla_model_3_charger_switch
      service: switch.turn_off

- id: tesla_stop_peak_charge_early
  alias: Tesla Stop offpeak charge early
  description: If the predicted solar production is high, stop charging early and continue the charge (60% to 95%) later in the day.
  trigger:
    - entity_id: sensor.tesla_model_3_battery_sensor
      platform: numeric_state
      above: 59
      for:
        minutes: 1
  condition:
    - alias: "Offpeak rate"
      condition: state
      entity_id: utility_meter.daily_house_energy
      state: "offpeak"
    - alias: "Not max range"
      condition: state
      entity_id: switch.tesla_model_3_maxrange_switch
      state: "off"
    - alias: "Predicted high solar production today"
      condition: numeric_state
      entity_id: sensor.energy_production_today
      above: 50
  action:
    - entity_id: switch.tesla_model_3_charger_switch
      service: switch.turn_off

- alias: Smart Solar charging
  id: smart_solar_charge_tesla
  description: "To only use excess power from solar, limit the number of Amps Tesla charger use. We'll stop charging if it drops below 5A"
  trigger:
    - platform: time_pattern
      minutes: "/1"
      #  This will check every minute
    - platform: state
      entity_id: binary_sensor.tesla_model_3_charger_sensor
      to: "on"
      # or when we plug it in
  condition:
    - alias: "Is home"
      condition: state
      entity_id: device_tracker.tesla_location
      state: "home"
    - alias: "Is plugged in"
      condition: state
      entity_id: binary_sensor.tesla_model_3_charger_sensor
      state: "on"
    - alias: "Sun is shining"
      condition: numeric_state
      entity_id: sensor.elevation
      above: 5
    - alias: "Not fully charged"
      condition: numeric_state
      entity_id: sensor.tesla_model_3_battery_sensor
      below: 95
  variables:
    amps: '{{ [[((states("sensor.tesla_charger_actual_current")|int(0)) - ((states("sensor.shelly_channel_b_power")|float(0) + 200) / (states("sensor.shelly_channel_b_voltage")|int(0)))|int(0)),0]|max, state_attr("sensor.tesla_model_3_charging_rate_sensor", "charge_current_request_max") | int(0) ]|min }}'
    # Calculate excess amps, we should set the Tesla charger to:
    # Current charger amps - (current power usage (i.e. -2000W) + 200W overhead, converted to amps)
    # It should not be lower than 0 and not higher than charger max current.
  action:
    - choose:
        - alias: "Just in case we reached charging limit, override and increase to 90%"
          conditions: "{{ (states('sensor.tesla_charge_limit_soc') |int(0)) < 95 }}"
          # and (states('sensor.tesla_battery_level') | int(0) ) + 5 >= (states('sensor.tesla_charge_limit_soc') | int(0)) }}"
          sequence:
            - service: tesla_custom.api
              alias: "Set charge limit to 90%"
              data:
                command: CHANGE_CHARGE_LIMIT
                parameters:
                  path_vars:
                    vehicle_id: '{{ state_attr("binary_sensor.tesla_model_3_online_sensor", "id") }}'
                  percent: 90
    - choose:
        - alias: "Enough energy to charge"
          conditions: "{{ amps >= 5 }}"
          sequence:
            - choose:
                - alias: "Turn on charger if needed"
                  conditions:
                    - condition: state
                      entity_id: switch.tesla_model_3_charger_switch
                      state: "off"
                  sequence:
                    - entity_id: switch.tesla_model_3_charger_switch
                      service: switch.turn_on
            - choose:
                - alias: "Update AMPs if changed"
                  conditions:
                    - "{{ amps >= 5 and amps != (states('sensor.tesla_charger_actual_current')|int(0)) }}"
                  sequence:
                    - service: tesla_custom.api
                      alias: "Set charging amps"
                      data:
                        command: CHARGING_AMPS
                        parameters:
                          path_vars:
                            vehicle_id: '{{ state_attr("binary_sensor.tesla_model_3_online_sensor", "id") }}'
                          charging_amps: >-
                            {{ amps }}
      # ELSE (Turn off charging charging - it is ineffecive below 5A)
      default:
        - choose:
            - alias: "Turn off charger if it is ON"
              conditions:
                - condition: state
                  entity_id: switch.tesla_model_3_charger_switch
                  state: "on"
              sequence:
                - entity_id: switch.tesla_model_3_charger_switch
                  service: switch.turn_off


Also, when the car battery is full, a good idea to convert excess power to heated water, I use this automation to set the water boiler to heat up to 60C and restore the previous state when done.

- alias: Water Boiler on when excess solar power is high
  description: ""
  id: heat_water_from_solar
  trigger:
    - platform: numeric_state
      entity_id: sensor.shelly_channel_b_power
      below: -2000
      for:
        minutes: 5
  condition:
    - alias: "Sun up"
      condition: state # 'day' condition: from sunrise until sunset
      entity_id: sun.sun
      state: "above_horizon"
    - alias: "Not Vacation"
      condition: state
      entity_id: input_boolean.vacation_mode
      state: "off"
    - alias: "Low temperature"
      condition: numeric_state
      entity_id: sensor.boiler_temperature
      below: 60
    - "{{ state_attr('climate.water_boiler', 'hvac_action') != 'heating' and state_attr('climate.water_boiler', 'temperature') != 60 }}" # not already heating
    - alias: "Tesla not charging"
      condition: numeric_state
      entity_id: sensor.tesla_charger_power
      below: 1
    - "{{ states('sensor.tesla_battery_level') | int ) >= (states('sensor.tesla_charge_limit_soc') |int) or is_state('binary_sensor.tesla_model_3_charger_sensor', 'off') }}" # tesla is unplugged or reached the soc limit
  action:
    - service: scene.create
      data:
        scene_id: boiler
        snapshot_entities:
          - climate.water_boiler
    - service: climate.set_temperature
      data:
        hvac_mode: heat
        temperature: 60
      target:
        entity_id: climate.water_boiler

- alias: Water Boiler off when excess solar power is low or reach target temperature
  description: ""
  id: stop_heat_water_from_solar
  trigger:
    - platform: numeric_state
      entity_id: sensor.shelly_channel_b_power
      above: 100
    - platform: numeric_state
      entity_id: sensor.boiler_temperature
      above: 60
  condition:
    - alias: "Sun up"
      condition: state # 'day' condition: from sunrise until sunset
      entity_id: sun.sun
      state: "above_horizon"
    - alias: "Not Vacation"
      condition: state
      entity_id: input_boolean.vacation_mode
      state: "off"
    - alias: "High temperature"
      condition: numeric_state
      entity_id: sensor.boiler_temperature
      above: 60
    - "{{ state_attr('climate.water_boiler', 'hvac_action') == 'heating' and state_attr('climate.water_boiler', 'temperature') == 60 }}" # heating
  action:
    - service: scene.turn_on # Revert the state to original state
      target:
        entity_id: scene.boiler
1 Like

I guess you are using something similar to this Dynamic Polling Frequency · alandtse/tesla Wiki · GitHub

1 Like

See below some codes which I currently use and and may be helpful to you and may advance your thinking

I have charging based on solar generating working quite well, excess solar charging I believe I am missing a clean read from the charging station (the calculation route through tesla gives me a bit of a headache) so will install a shelly 3em in the fusebox to read the power Used by the charging station. I am happy to take any tips on the excess solar charging

Increase polling on the tesla

Automation

alias: AUT_TeslaPollingIntervalTo60
description: ''
trigger:
  - platform: state
    entity_id: switch.tesla_model_3_charger_switch
    to: 'on'
condition:
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: home
action:
  - service: script.teslaupdateintervalto60
    data: {}
mode: single

Script

alias: TeslaPollingIntervalTo60
sequence:
  - service: tesla_custom.polling_interval
    data:
      scan_interval: 60
mode: single

Polling interval to default
Automation

alias: AUT_TeslaPollingIntervalToDefault
description: ''
trigger:
  - platform: state
    entity_id: switch.tesla_model_3_charger_switch
    to: 'off'
condition:
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: home
action:
  - service: script.teslapollingintervaltodefault
    data: {}
mode: single

Script

alias: TeslaPollingIntervalToDefault
sequence:
  - service: tesla_custom.polling_interval
    data:
      scan_interval: 660
mode: single

charging based on total solar
Automations

alias: TeslaStartCharging@TotalSolar
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.p1_meter_3c39e7240372_active_power
    for:
      hours: 0
      minutes: 0
      seconds: 20
    below: '-500'
condition:
  - condition: state
    entity_id: binary_sensor.tesla_model_3_charger_sensor
    state: 'on'
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: home
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.tesla_model_3_charger_switch
  - service: automation.turn_on
    data: {}
    target:
      entity_id: automation.triggersolarchargingeveryminute
mode: single

alias: OnPluginCheckTotalSolar
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.tesla_model_3_charger_sensor
    to: 'on'
condition:
  - condition: numeric_state
    entity_id: sensor.p1_meter_3c39e7240372_active_power
    below: '-500'
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: home
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.tesla_model_3_charger_switch
  - service: automation.turn_on
    data: {}
    target:
      entity_id: automation.triggersolarchargingeveryminute
mode: single

alias: TriggerTotalSolarChargingEveryMinute
description: ''
trigger:
  - platform: time_pattern
    minutes: /1
condition:
  - condition: time
    after: '04:00:00'
    before: '23:00:00'
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: home
action:
  - service: script.teslachargingsetampslinktosemsportal
    data: {}
mode: single

alias: TeslaStopCharging
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.p1_meter_3c39e7240372_active_power
    for:
      hours: 0
      minutes: 1
      seconds: 0
    above: '5000'
  - platform: sun
    event: sunset
    offset: '0'
  - platform: numeric_state
    entity_id: sensor.tesla_model_3_range_sensor
    above: '415'
  - platform: state
    entity_id: switch.tesla_model_3_charger_switch
    to: 'Off'
condition:
  - condition: state
    entity_id: device_tracker.tesla_model_3_location_tracker
    state: home
  - condition: numeric_state
    entity_id: sensor.tesla_model_3_charging_rate_sensor
    above: '2'
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.tesla_model_3_charger_switch
  - service: automation.turn_off
    data: {}
    target:
      entity_id:
        - automation.triggersolarchargingeveryminute
        - automation.triggerexcesssolarchargingeveryminute
mode: single

Scripts

alias: TeslaChargingSetAmpsLinkToSemsportal
sequence:
  - service: tesla_custom.api
    data:
      email: REDACTED
      command: CHARGING_AMPS
      parameters:
        path_vars:
          vehicle_id: '{{ state_attr(''binary_sensor.tesla_model_3_online_sensor'', ''id'') }}'
        charging_amps: '{{ ((states(''sensor.psupply_2''))| float /1000*1.4)| int }}'
mode: single