↓Skip to main content

Virtual Solar: Multi-instance, Grid Export, Discharge Control, and Community-Driven Changes

·1565 words·8 mins
Virtual Solar update: a yellow sun above a solar panel and lightning bolt on dark green, with an Update banner

I published Simulate Solar & Battery in Home Assistant about ha-virtual-solar, a Home Assistant custom integration that estimates solar output from a lux sensor and simulates a virtual battery. Since then a few people have installed it, a few of them opened issues or dropped Reddit comments, and the integration has grown in four meaningful ways as a result. Here’s what shipped, along with the bug fixes in the two most recent releases.

Bigger arrays (v0.5.3) #

Reddit user Western_Employer_513 asked whether the 20-panel cap could go higher. The 20 came from an inherited assumption about balcony-solar kits, but for anyone modelling a rooftop system it was arbitrarily low.

Raised to 60 panels in v0.5.3, which comfortably covers a 30 kW residential array at 500 W per panel. Anyone who was already using values 1 to 20 sees no difference. This was a five-line change plus a docs update, fixed the same day as the request.

Grid Export Sensor (v0.6.0) #

The battery ticker clamps net flow at max_charge_rate and clamps the level at capacity. When solar exceeds either limit, the surplus is silently discarded. In a real system that energy would either flow back to the grid (if your inverter and metering support export) or be lost. Either way, it’s meaningful: it tells you whether more panels would generate more usable energy or just more overflow.

v0.6.0 adds sensor.virtual_solar_grid_export (W) that reports the surplus in real time:

raw_net = solar - house
if raw_net > 0:
    headroom_w = (capacity - level) × 3.6M / tick_seconds
    actual_charge = min(raw_net, max_charge_rate, headroom_w)
    grid_export = raw_net - actual_charge
else:
    grid_export = 0

Two scenarios where it fires:

  • Battery full: solar 600 W, house 100 W, battery at capacity. grid_export = 500 W.
  • Solar exceeds charge rate: solar 2000 W, house 200 W, max charge rate 1200 W, battery half-full. grid_export = 600 W.

Practical use: leave the sensor visible on your dashboard for a couple of weeks and watch when it’s non-zero. If it sits at 0 all day, your array is sized well for your storage. If it spends hours pinned at high values, you have surplus generation that a bigger battery, an export tariff, or a scheduled load (car charger, immersion heater) could capture. That’s a much more concrete answer to “should I buy a bigger battery?” than a vendor calculator will give you.

The sensor is included in the auto-generated dashboard’s Current Status card.

Multiple Setups in Parallel (v0.7.0) #

The biggest change, and the one that turned the integration from “estimator” into “sizing tool”. Someone asked on Reddit whether they could run two configurations at the same time to compare them.

The original design was single-instance: one Virtual Solar entry per Home Assistant install. That’s fine if you already know what you want to buy. It’s less useful if you’re weighing “1 panel + 2.68 kWh” against “3 panels + 5 kWh” and want to see both timelines against the same actual weather and household load.

v0.7.0 lets you add the integration multiple times. Each setup gets:

  • Its own name (used as device title and entity ID prefix)
  • Its own panel count, wattage, battery capacity, max rates, and efficiency
  • Its own independent battery-level ticker and derived sensors

Two setups pointing at the same lux and house sensors produce two parallel timelines. You can put them side by side on a dashboard, or overlay the battery levels on the same history graph, and watch which one actually covers your evening consumption on a typical Tuesday.

The setup wizard picked up a new field #

The first step of the wizard now asks for a Setup name in addition to the profile:

  • Type 1 panel baseline (or whatever)
  • Pick a profile
  • Same lux + house sensors
  • Different panel count / battery size
  • Repeat

Behind the scenes, sensors and number entities look up their sibling entity IDs per config entry via the entity registry, so a second setup’s battery_level doesn’t get confused with the first’s. Existing installs migrate transparently: they keep their existing entity IDs and values.

The dashboard service now handles multiple setups #

virtual_solar.get_dashboard used to return a single view. Now, with multiple setups, it returns a dashboard with one view (tab) per setup, each titled with the setup name. Copy the entire response into a new dashboard’s raw editor, and you get a two-tab (or more) comparison view for free.

If you want just one setup’s YAML, pass an entry_id field to the service call.

Discharge Control (v0.8.0, fixed in v0.8.1) #

Update, 18 November: v0.8.0 shipped this switch, but a bug meant the other entities never found it, so turning it off did nothing. v0.8.1 fixes that. If you’re on 0.8.0, upgrade, and note that a switch you left off will start holding the battery’s charge straight away.

GitHub user @scriven33 opened an issue asking for a switch to control when the virtual battery discharges. Their scenario: overnight electricity is cheap and tomorrow will be cloudy plus expensive, so a smart owner would let the grid cover the cheap overnight period and preserve the battery for the expensive daytime. The simulator, until then, unconditionally drained the battery whenever house demand exceeded solar.

v0.8.0 adds switch.virtual_solar_discharge_enabled (default on). When off, the battery holds its charge and the house is served entirely from the grid. Charging from solar surplus still works normally, so a sunny afternoon still tops the battery up even while discharge is disabled.

The ticker change is tiny:

net_w = solar - house
if net_w < 0 and not discharge_enabled:
    net_w = 0            # hold instead of drain

Concrete automations:

  • Time-of-use tariff: turn discharge off between the cheap overnight hours, back on in the morning.
  • EV charging: a scenario scriven33 mentioned as a bonus. An EV pulls a lot (7 kW plus). You don’t want your 2.68 kWh house battery draining alongside the car. Turn discharge off while the car is on the wall.

To keep the battery status meaningful, sensor.virtual_solar_battery_status gains a new Holding value for the case where the switch is off and the house is drawing more than solar produces. sensor.virtual_solar_battery_charge_rate reads 0 in that state, reflecting the actual (not desired) battery flow.

The next companion piece, a sensor.virtual_solar_grid_import counterpart to the existing grid_export, is open as a follow-up. Without it, you can see the battery holding but not the actual grid draw during the hold.

Two Fixes (v0.8.1) #

The latest release is all bug fixes.

The discharge switch now works. The lookup that lets each entity find its siblings only searched number and sensor entities, so the switch was never found. In 0.8.0 that meant the battery kept discharging when the switch was off, sensor.virtual_solar_battery_status never showed Holding, and the generated dashboard pointed at the wrong switch for any setup not named “Virtual Solar”. All three are fixed.

The charge rate respects the battery level. GitHub user cmhoodor-ui reported that sensor.virtual_solar_battery_charge_rate stayed negative after the battery was empty. The sensor only looked at solar minus house consumption and ignored how much was in the battery. It now takes the level into account, so it reads 0 W when the battery can’t supply or absorb any more energy, whether it’s empty or full. That matches what the battery level itself does.

Four More Fixes (v0.8.2) #

After v0.8.1 I went back through the whole codebase looking for anything else that was quietly wrong. That turned up four more bugs, all fixed in v0.8.2.

kW power sensors are converted to W. The setup wizard accepts any power sensor, and plenty of smart meters report in kW, but the value was always treated as watts. A house drawing 1.5 kW was simulated as drawing 1.5 W, so the battery charged as if nothing was running and grid export was far too high. The integration now reads the sensor’s unit and converts it.

The Configure dialog no longer offers settings it ignored. Battery capacity and system efficiency could be changed in Configure, but the change never took effect, because the dashboard sliders for those values restore their own last value when the integration reloads. Configure now only covers the sensors and the max charge and discharge rates. The sliders are the place to change capacity and efficiency.

The generated dashboard follows the sliders. The solar output gauge was sized from the panel wattage and count entered at setup, so after dragging the panel count from 1 to 4, regenerating the dashboard still gave a gauge that maxed out at one panel’s worth. It now uses the current slider values.

A clearer message for duplicate setup names. Adding a second setup with a name that’s already taken used to say “Virtual Solar is already configured”, which reads as if only one setup is allowed. It now says a setup with that name already exists.

What’s next #

The grid-import sensor above is still open as issue #6. I’d also like to add cumulative energy sensors, so solar output and grid flow show up in Home Assistant’s Energy dashboard. Another open request is using the integration without a power meter when all you have is a lux sensor.

If you hit a bug or want something added, open an issue on the issue tracker. Commenting on an existing one is the fastest way to bump its priority.

Source at virtuallytd/ha-virtual-solar, with the full feature list on the project page. Available through HACS by adding the repository as a custom integration.