blueprint: name: Tesla Solar Charger - script actions description: Tesla charging current guided by solar output to grid domain: script input: tesla_button_wake_up: name: Tesla button Wake UP description: Entity to wake up your Tesla selector: entity: domain: button tesla_binary_sensor_pluggedin: name: Tesla Binary Sensor Charger description: This sensor checks if your car is plugged in or not selector: entity: domain: binary_sensor tesla_button_forceupdate: name: Tesla button force update description: Entity to force updating HA data on your Tesla selector: entity: domain: button tesla_switch_charger: name: Tesla Switch Charger on description: Entity to turn charging on selector: entity: domain: switch tesla_number_charging_amps: name: Tesla Charging amps description: Entity that dictates what current the car should charge with in Amperes selector: entity: domain: number tesla_number_charge_limit: name: Tesla charge limit description: Entity that controls what percentage the car should stop charging at selector: entity: domain: number inverter_sensor_total_grid_power: name: Total grid power description: Choose the sensor that reads the import power from the grid in Watts. selector: entity: domain: sensor home_battery_power: name: Home Battery Output Power description: Choose the sensor that reads the discharge power from the battery in Watts. selector: entity: domain: sensor tesla_sensor_battery: name: Tesla Sensor Battery description: This sensor checks the current battery charge level selector: entity: domain: sensor update_interval: name: Update Interval Integer description: Define the update interval of the script in "seconds" - i.e how often should it check and change your power draw. Please provide an integer. timer_stop_abs: name: Absolute script ending description: This will set an "absolut" time at which the script will end. If you want to use a relative time, input "22:59:00" without quotes. Ensure correct formatting! timer_stop_rel: name: Relative script ending description: This will set a "relative" time, defined as time relative to sunset. Insert "-01:00:00" without quotes, if you wish it to end 1 hour before sunset. sequence: - service: scene.create data: scene_id: amps_and_limit snapshot_entities: - !input tesla_number_charge_limit - !input tesla_number_charging_amps - service: button.press data: {} target: entity_id: !input tesla_button_wake_up - delay: hours: 0 minutes: 0 seconds: 40 milliseconds: 0 - service: button.press data: {} target: entity_id: !input tesla_button_forceupdate - delay: hours: 0 minutes: 0 seconds: 5 milliseconds: 0 - service: number.set_value data: value: "90" target: entity_id: !input tesla_number_charge_limit - service: switch.turn_on data: {} target: entity_id: !input tesla_switch_charger - service: number.set_value data: value: "6" target: entity_id: !input tesla_number_charging_amps - delay: hours: 0 minutes: 0 seconds: 5 milliseconds: 0 - repeat: until: - condition: or conditions: - condition: time after: !input timer_stop_abs - condition: sun before: sunrise after: sunset after_offset: !input timer_stop_rel - condition: state entity_id: !input tesla_binary_sensor_pluggedin state: "off" - condition: numeric_state entity_id: !input tesla_sensor_battery above: 89 sequence: - service: button.press data: {} target: entity_id: !input tesla_button_forceupdate - variables: amps: !input tesla_number_charging_amps batt_consum: !input home_battery_power grid_consum: !input inverter_sensor_total_grid_power overconsumption: >- {% if states(batt_consum) | float(0) > 0 %} {{states(grid_consum) | float(0) + states(batt_consum) | float(0) + 280}} {% else %} {{ states(grid_consum) }} {% endif %} - choose: - conditions: - condition: template value_template: "{{ overconsumption < -280 }}" sequence: - service: switch.turn_on data: {} target: entity_id: !input tesla_switch_charger - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps below: 16 then: - choose: - conditions: - condition: template value_template: "{{overconsumption < -970 }}" sequence: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ -1670 < overconsumption < -971 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps below: 15 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 2 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ -2360 < overconsumption < -1671 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps below: 14 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 3 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ -3050 < overconsumption < -2361 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps below: 13 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 4 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ -3740 < overconsumption < -3051 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps below: 12 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 5 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{overconsumption < -3741 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps below: 11 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 6 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) + 1 }}" target: entity_id: !input tesla_number_charging_amps else: - delay: hours: 0 minutes: 0 seconds: 1 milliseconds: 0 - conditions: - condition: template value_template: "{{ overconsumption > 500 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps above: 0 then: - choose: - conditions: - condition: template value_template: "{{ overconsumption > 3950 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps above: 5 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 6 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ 3951 > overconsumption > 3260 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps above: 4 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 5 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ 3261 > overconsumption > 2570 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps above: 3 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 4 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ 2571 > overconsumption > 1880 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps above: 2 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 3 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ 2571 > overconsumption > 1190 }}" sequence: - if: - condition: numeric_state entity_id: !input tesla_number_charging_amps above: 1 then: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 2 }}" target: entity_id: !input tesla_number_charging_amps else: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 1 }}" target: entity_id: !input tesla_number_charging_amps - conditions: - condition: template value_template: "{{ 1191 > overconsumption }}" sequence: - service: number.set_value data_template: value: "{{ (states(amps) | int ) - 1 }}" target: entity_id: !input tesla_number_charging_amps else: - delay: hours: 0 minutes: 0 seconds: 1 milliseconds: 0 - conditions: - condition: template value_template: "{{ 501 > overconsumption > -281 }}" sequence: - delay: hours: 0 minutes: 0 seconds: 1 milliseconds: 0 - delay: hours: 0 minutes: 0 seconds: !input update_interval milliseconds: 0 - service: scene.turn_on target: entity_id: scene.amps_and_limit - service: switch.turn_off data: {} target: entity_id: !input tesla_switch_charger mode: single