Skip to content

Instantly share code, notes, and snippets.

@peyanski
Last active June 4, 2025 12:47
Show Gist options
  • Save peyanski/86c57c1714fb1e9f74531cb826bf12f3 to your computer and use it in GitHub Desktop.
Save peyanski/86c57c1714fb1e9f74531cb826bf12f3 to your computer and use it in GitHub Desktop.
alias: Smart EV Charging - Night Tariff Focus
description: Adjust EV charging based on house load and night tariff window.
trigger:
- platform: time_pattern
minutes: "/3" # How often to check and adjust charging (every 3 minutes)
condition: []
action:
- variables:
current_hour: "{{ now().hour }}"
# CHANGE THIS: Replace with your actual load/consumption sensor entity
load_power: "{{ '%.2f' | format(states('sensor.shellyem3_c45bbe6c1698_channel_a_power') | float / 1000) }}" # CHANGE THIS: Use your total house load sensor entity
voltage: 230
max_allowed_amps: 32 # CHANGE THIS: Maximum charging current your setup supports
min_allowed_amps: 6 # CHANGE THIS: Minimum charging current
# CHANGE THIS: Adjust night tariff hours to match your electricity plan
# Current setting: 11 PM to 7 AM (23:00 to 07:00)
is_night_tariff: "{{ current_hour >= 23 or current_hour < 7 }}"
# Logic for determining charging current based on consumption and time
charge_amps: >
{% if is_night_tariff %}
{# During night tariff: always charge at maximum regardless of consumption #}
{% set target_amps = 32 %}
{% else %}
{# During day: adjust charging based on house consumption #}
{% if load_power > 5 %}
{% set target_amps = 0 %}
{% elif load_power < 3.5 %}
{% set target_amps = 10 %}
{% else %}
{% set target_amps = 6 %}
{% endif %}
{% endif %}
{{ [min_allowed_amps, [target_amps, max_allowed_amps] | min] | max if target_amps > 0 else 0 }}
- choose:
# START CHARGING: When we want to charge (amps > 0)
- conditions:
- condition: template
value_template: "{{ charge_amps > 0 }}"
sequence:
# First, make sure charging is enabled
- service: select.select_option
target:
entity_id: select.ev_charger_toggle_charging # CHANGE THIS: Your EV charger toggle entity
data:
option: "Start charging" # CHANGE THIS: Exact text for starting charging
# Then set the charging current
- service: number.set_value
target:
entity_id: number.ev_charger_set_charge_current # CHANGE THIS: Your EV charger current control entity
data:
value: "{{ charge_amps }}"
# STOP CHARGING: When consumption is above 4kW or we don't want to charge
- conditions:
- condition: template
value_template: "{{ charge_amps == 0 }}"
sequence:
# Stop charging completely
- service: select.select_option
target:
entity_id: select.ev_charger_toggle_charging # CHANGE THIS: Your EV charger toggle entity
data:
option: "Stop charging" # CHANGE THIS: Exact text for stopping charging
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment