From 2d2b15d1bc378742f17081ce7212ba31583c8c73 Mon Sep 17 00:00:00 2001 From: Dominik Polakovics Date: Thu, 9 Apr 2026 09:31:32 +0200 Subject: [PATCH] feat: add anker solix --- .../fw/modules/home-assistant/anker-solix.nix | 135 ++++++++++++++++++ hosts/fw/modules/home-assistant/default.nix | 1 + 2 files changed, 136 insertions(+) create mode 100644 hosts/fw/modules/home-assistant/anker-solix.nix diff --git a/hosts/fw/modules/home-assistant/anker-solix.nix b/hosts/fw/modules/home-assistant/anker-solix.nix new file mode 100644 index 0000000..ae414e5 --- /dev/null +++ b/hosts/fw/modules/home-assistant/anker-solix.nix @@ -0,0 +1,135 @@ +{ 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 }}"; + } + ]; + } + ]; + } + ]; + }; + }; +} diff --git a/hosts/fw/modules/home-assistant/default.nix b/hosts/fw/modules/home-assistant/default.nix index 4f70b8f..cea1f56 100644 --- a/hosts/fw/modules/home-assistant/default.nix +++ b/hosts/fw/modules/home-assistant/default.nix @@ -81,6 +81,7 @@ in ./3dprinter.nix ./ac.nix # ./aeg.nix + ./anker-solix.nix ./battery.nix ./electricity.nix ./enocean.nix