{ pkgs, ... }: { # Install the community Anker Solix integration (thomluther) # TODO: migrate to official local Modbus integration once E2700 Pro is supported systemd.services.install-anker-solix = { description = "Install Anker Solix Integration"; wantedBy = [ "multi-user.target" ]; after = [ "network-online.target" ]; wants = [ "network-online.target" ]; serviceConfig = { Type = "oneshot"; }; script = '' set -e VERSION="3.5.4" DIR="/var/lib/hass/custom_components/anker_solix" mkdir -p "$DIR" ${pkgs.curl}/bin/curl -fL --retry 3 --retry-delay 5 "https://github.com/thomluther/ha-anker-solix/releases/download/$VERSION/anker_solix.zip" -o /tmp/anker_solix.zip ${pkgs.unzip}/bin/unzip -o /tmp/anker_solix.zip -d "$DIR" rm /tmp/anker_solix.zip chown -R hass:hass "$DIR" ''; }; services.home-assistant.extraComponents = [ "integration" ]; services.home-assistant.config = { # Riemann sum integration sensors to convert W → kWh for the energy dashboard sensor = [ { platform = "integration"; source = "sensor.solarbank_3_e2700_pro_solar_power"; name = "Solarbank Solar Energy"; unit_prefix = "k"; round = 2; method = "left"; } { platform = "integration"; source = "sensor.solarbank_3_e2700_pro_charge_power"; name = "Solarbank Charge Energy"; unit_prefix = "k"; round = 2; method = "left"; } { platform = "integration"; source = "sensor.solarbank_3_e2700_pro_discharge_power"; name = "Solarbank Discharge Energy"; unit_prefix = "k"; round = 2; method = "left"; } ]; # Dashboard helper: shows current target output, allows manual override input_number.solarbank_target_output = { name = "Solarbank Target Output"; min = 0; max = 800; step = 10; unit_of_measurement = "W"; icon = "mdi:solar-power"; }; # Zero-export grid balancing automation # Adjusts Solarbank output every 30s to drive grid import on phase C toward 0W "automation solarbank zero export" = { alias = "Solarbank Zero Export"; mode = "single"; trigger = { platform = "state"; entity_id = "sensor.shellyem3_485519d792a7_channel_c_power"; }; condition = [ { condition = "not"; conditions = [ { condition = "state"; entity_id = "number.solarbank_3_e2700_pro_system_output_preset"; state = "unavailable"; } ]; } { condition = "not"; conditions = [ { condition = "state"; entity_id = "number.solarbank_3_e2700_pro_system_output_preset"; state = "unknown"; } ]; } ]; action = [ { variables = { grid_power = "{{ states('sensor.shellyem3_485519d792a7_channel_c_power') | float(0) }}"; current_output = "{{ states('number.solarbank_3_e2700_pro_system_output_preset') | float(0) }}"; }; } { variables = { desired_output = "{{ [([current_output + grid_power, 0] | max), 800] | min }}"; rounded_output = "{{ (desired_output / 10) | round(0) * 10 }}"; }; } { choose = [ { conditions = [ "{{ (rounded_output - current_output) | abs >= 10 }}" ]; sequence = [ { service = "input_number.set_value"; target.entity_id = "input_number.solarbank_target_output"; data.value = "{{ rounded_output }}"; } { service = "number.set_value"; target.entity_id = "number.solarbank_3_e2700_pro_system_output_preset"; data.value = "{{ rounded_output }}"; } ]; } ]; } ]; }; }; }