DIY smart grid: EV (Tesla) charging on excess solar power production

And what switch.pv.dlm_button does in your case ?

1 Like

Hi Dick, I hope that I may pick your brain on your routines to charge Your/My Tesla with access PV power. I understand the logic behind your code, but as a newbee I am unsure if I took the right steps and how to "see"what is going on. Could you let me know if I am ontrack or not?

I took each of your code blocks seperately and copy and pasted them via File Editor into a new Yaml file. I changed all variables to reflect my environment. But now I struggleā€¦do I have to start them or do they launch automatically with HA boot sequence? You refer to ON of OFF status pop ups and iOS messages. When would I see those? Do I need to create an overview TAB and link that to your code? Any help would be greatly appreciated. As a background I am with Tibber for the energy and have the Tibber integration up- and running in HA. I use the Tibber sensor.power_production which is the net of production minus usage.

Thanks for this automation. Nicely done. Iā€™m trying it on my Tesla named Noir.
When I plug the Tesla, I get the demand to enable or not Smart Charging. I answer and I see the action automation being received. But for some reason the charging doesnā€™t start. It seems like my HA doesnā€™t want to talk to my Tesla. Iā€™m using the Tessie integration and the Tesla one too. (Iā€™m transitioning from the Tesla one to the Tessie one right now). When I do a switch.on service call, I get an error.


This should work right?

By the way, it also doesnā€™t work when using the Tesla variable switch.noir_charge
(without the r)

Semantically speaking, this should work. This error seems unrelated to the automation. Check your core logging.

Hi Axel, itā€™s been a while since you posted your question. Did you progress? Your questions seem to be quite basic ones in regard to how automations and iOS callbacks work. I donā€™t think this kind of automation is for the faint of heart, but I do encourage you to dig deep and get this to work!

As soon as you add or edit an automation, all you have to do is restart the automation through the developer tools menu and they are up and running. The iOS notification callback function is not for beginners, so Iā€™lld encourage you to experiment with this a bit more at first with a simpler automation (for instance with a button and a light, where the button triggers the iOS question ā€œDo you want to turn on the light?ā€ and a yes/no reaction triggers the action. You could start your research here: Introduction | Home Assistant Companion Docs (home-assistant.io)

Good luck, days are getting longer over here so now is as good a time as ever to get this up and running! :wink: Let me know how youā€™re progressing.

There is indeed errors in the log. Iā€™m quite useless in reading these, I have to admit.
Thanks

Could this be because Iā€™m running both he Tesla and the Tessie integration?

And also this one, longer

Both errors show that the integration isnā€™t connecting tot the Tesla API. Dit you manage to authenticate correctly? I would strongly advise you to use only one, preferably the (HACS) Tesla Custom Integration. You connect to the Tessie platform using itā€™s own API, which in turn is connected to the Tesla API. This introduces not only a new ā€˜point of failureā€™ but itā€™s also abstracting/obscuring whatā€™s really happening and hard to debug. First get the Tesla integration working, then make the switch to the Tessie platform.

1 Like

Yeah I figured it out. It was indeed Tessie who needed a second authentication for access to my virtual key apparently. Somehow I missed it. I didnā€™t try it yet but Iā€™m guessing itā€™ll work now. Canā€™t wait til tomorrow morning. :joy::joy:.

As for using the Tesla integration, thatā€™s what Iā€™ve had for a while but itā€™s not been responding well with a lot of unknown values on my entities.

Apparently Tesla is about to close it up and I read that Tessie is a more sure way to go from now on. That why Iā€™m still using both. I didnā€™t get to turn the other off and change all my entities names

Thanks for guiding me in the right direction. :pray:t2:

Hi,

I have change the code to suit my sensor. I am using tessie to communicate with my tesla. But I canā€™t find what to write instead of :
max_charging_amps: ā€œ{{ state_attr(ā€˜number.charging_ampsā€™, ā€˜maxā€™) | int }}ā€

since I have no number.charging_amps, I presume itā€™s created from the old tesla integration. But donā€™t find the equivalent with tessie.

EDIT :
I think that I found it :

max_charging_amps: "{{ state_attr('number.mycarname_courant_de_recharge', 'max') | int }}"

yep, itā€™s in french :wink:
But now, the Tesla UMC can set 13A max but my power socket canā€™t handle that much, 8A is the max it can do. So How can I set it up to get only 8A max ? changing like the first post ? Like :

max_charging_amps: 8

I donā€™t understand why you would speak of the ā€˜old Tesla integrationā€™, as it is just the direct implementation of Teslaā€™s API. In sharp contrast to Tessieā€™s API, which is an API which in turn addresses that exact same Tesla API. Enfin, thereā€™s that. :wink:

Indeed.

Tessie is working fine for me, the other tesla integration return the stat of the car but I canā€™t interract with the car. As tesla shutdown on january something regarding the wzy to communicate with the car, I was thinking thatā€™s why I canā€™t use the ā€œoldā€ integration of tesla in Home Assistant.
Perhaps itā€™s finally just a setting that I miss :sweat_smile:

@dikkertjedap, hi is this nice automation available in blueprint?

Iā€™ve thought about creating one, but when thinking this over, thereā€™s quite a few considerations and choices for every individual situation. So my conclusion was to leave it as it is: a nice and complete write-up of how I did it.

Hey guys, I am wanting to do a similar to spread excess solar into my Tesla with the use of SMA solar and energy meter, Tesla wall connect 3 and tessie.

I have come up with this using the UI options as I am new to ymal.
If anyone could assist in merging to a ymal in this thread or make some recommendations to change that would be great.

The issue I have with my code is it only accounts for the excess turns on the charge but the start of sequence doesnā€™t no itā€™s already charging and drops down the charge.
Some how I need to run checks in a loop if itā€™s already charging and than step up or down based on excess or overdrawn.

Please help

Many thanks

alias: Tesla Auto Charge
description: Test
trigger:
  - platform: time_pattern
    seconds: "10"
condition:
  - condition: state
    entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
    state: "on"
    enabled: true
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
                state: "on"
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_absorbed
                below: sensor.sn_3009010635_metering_power_supplied
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_supplied
                above: 0
                below: 3000
        sequence:
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 0
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
                state: "on"
              - condition: numeric_state
                entity_id: number.thunder_charge_current
                above: 5
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_absorbed
                below: sensor.sn_3009010635_metering_power_supplied
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_supplied
                above: 3000
                below: 4000
        sequence:
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 5
          - type: turn_on
            device_id: e20bff6e893d4daed32f519ee7ca50ba
            entity_id: fd0034d4f594ed89d4b5177c14c1c860
            domain: switch
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
                state: "on"
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_absorbed
                below: sensor.sn_3009010635_metering_power_supplied
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_supplied
                above: 4000
                below: 5000
        sequence:
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 6
          - type: turn_on
            device_id: e20bff6e893d4daed32f519ee7ca50ba
            entity_id: fd0034d4f594ed89d4b5177c14c1c860
            domain: switch
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
                state: "on"
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_absorbed
                below: sensor.sn_3009010635_metering_power_supplied
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_supplied
                below: 6000
                above: 5000
        sequence:
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 7
          - type: turn_on
            device_id: e20bff6e893d4daed32f519ee7ca50ba
            entity_id: fd0034d4f594ed89d4b5177c14c1c860
            domain: switch
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
                state: "on"
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_absorbed
                below: sensor.sn_3009010635_metering_power_supplied
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_supplied
                below: 7000
                above: 6000
        sequence:
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 8
          - type: turn_on
            device_id: e20bff6e893d4daed32f519ee7ca50ba
            entity_id: fd0034d4f594ed89d4b5177c14c1c860
            domain: switch
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
                state: "on"
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_absorbed
                below: sensor.sn_3009010635_metering_power_supplied
              - condition: numeric_state
                entity_id: sensor.sn_3009010635_metering_power_supplied
                above: 7000
                below: 8000
        sequence:
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 10
          - type: turn_on
            device_id: e20bff6e893d4daed32f519ee7ca50ba
            entity_id: fd0034d4f594ed89d4b5177c14c1c860
            domain: switch
      - conditions:
          - condition: state
            entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
            state: "on"
          - condition: time
            after: "17:00:00"
            before: "08:00:00"
        sequence:
          - type: turn_off
            device_id: e20bff6e893d4daed32f519ee7ca50ba
            entity_id: fd0034d4f594ed89d4b5177c14c1c860
            domain: switch
      - conditions:
          - condition: state
            entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
            state: "on"
          - condition: time
            before: "17:00:00"
            after: "08:00:00"
        sequence:
          - type: turn_on
            device_id: e20bff6e893d4daed32f519ee7ca50ba
            entity_id: fd0034d4f594ed89d4b5177c14c1c860
            domain: switch
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 0
      - conditions:
          - type: is_not_plugged_in
            condition: device
            device_id: 778a5d086b864d124094f016e8933490
            entity_id: d3501082b649e259b7ccda846f00fc95
            domain: binary_sensor
        sequence:
          - device_id: e20bff6e893d4daed32f519ee7ca50ba
            domain: number
            entity_id: 5ab2772349f8b59a17f58a4cb2031530
            type: set_value
            value: 16
mode: restart

Hi, iā€™m using your code since yesterday.
Iā€™m having a 3 phase grid connection so iā€™ve changed some things here and there.
My amps where wiggling very strong to the highā€™s and lowā€™s.

One thing i donā€™t understand is, why do you take the grid_usage + charger_power_draw? When i do so, iā€™m getting, by example: 4000W + 3000W = 7000W / grid_voltage and thatā€™s the new set value in Ampā€™s, so thatā€™s way too high in my situation.

When i deleted that charger_power_draw and letting it change ampā€™s only based on grid_usage / grid_voltage it doesā€™nt wiggle so much anymore.

Hi Richard,

you should keep in mind that when using a 3 phase charger, the multiplication of the set number of amps and the voltage is threefold. That causes the big swings in power draw.

Try this code, which adjusts for a 3-phase situation:

data:
  value: >
    {% set charger_power_draw_per_phase = (states('number.charging_amps') | int * grid_voltage) / 3 %}
    {% set total_charger_power_draw = charger_power_draw_per_phase * 3 %}
    {% set new_grid_usage = grid_usage + total_charger_power_draw %}
    {% set charging_amps_per_phase = ((new_grid_usage / 3) / grid_voltage) | round(0, 'floor') | int %}
    {% set total_charging_amps = charging_amps_per_phase * 3 %}
    {{ [max_charging_amps, total_charging_amps] | min }}
1 Like

While Iā€™m flattered that my code inspired you to create one yourself, your code is fundamentally different from mine. To be honest I donā€™t feel inclined to fully analyze whatā€™s going on here, but what seems to be a fundamental problem is that nowhere inside the automation there is the calculation of what part of the grid power usage is ACTUALLY drawn by the charger itself when recalculating the adjusted charger draw. Not sure if going about this solely by the automation UI is sufficient to achieve the desired outcome.

Hi @dikkertjedap Thanks for posting this! Iā€™ve been reviewing the post, config, comments, etc. to figure out whether I can adapt this for myself but Iā€™m stuck at the beginning as I do not have a smart power meter. But I DO have a Sense monitor w/Solar capability as well as a SolarEdge inverter & accounts. Iā€™ve added both Sense and SolarEdge to my HA setup. SolarEdge doesnā€™t seem to provide very much detail and my inverter doesnā€™t know about my power usage, only what my solar system is generating (current power) and lifetime generation. The Sense HA integration documentation indicates it should include active sensors for usage and production, both in watts. But these appear to be per device detected in Sense and not a total.

I also donā€™t have a Tesla wall charger, but the mobile charger.

Can you give me an idea whether I can still adapt your automation with these differences?

Since I was planning a much less complex automation that would charge my Tesla based on a certain solar power production (at least over fixed value), not taking into account other usage in my house, maybe I can still make it work?

Thoughts? Thanks!

Hi Tim,

thank you for the appreciation! Iā€™m not familiar with Sense or SolarEdge, but the automation does something as simple as calculating the power produced minus the power drawn, and then set the charger to the correct amount of amps to be used for charging the car. If you are able to do so with the Sense and SolarEdge integrations, you are on your way! Furthermore Iā€™m not familiar with the posibility to set the charging amps while using the mobile charger, but as you set the power draw on the car settings, this might not be any problem.

The simpler concept you are proposing is in fact a suitable alternative, so if the above fails, I would certainly give that a go! Good luck!

Hi again @dikkertjedap! I have configured the sensor.power_grid_usage, including debugging what I had wrong with the Developer Tools > Template. I had removed the | float * 1000 per another suggestion in this thread because my sensor is already in Watts, but it doesnā€™t happy performing the >= operation between str and int. So I restored | float and itā€™s working in the Dev Tools. It outputs the value Iā€™m expecting with Result type: string at the top.

I figured out the sensors I needed from my Sense energy monitor are sensor.energy_production and sensor.energy_usage.

However, the sensor.power_grid_usage sensor is still showing a state of unavailable under Dev Tools > States and shows no value/change on the history screen. How can I verify this sensor is working via my written configuration? I wanted to make sure it was working before moving on to the automations. Thanks for any advice.