Skip to main content

Energy Load Control Based on Available Excess PV Power

What We Control?​

This is very common case when we need to power on controlable device when we have enough power. In our case we want to run pool pump from solar.

Objective of Automation​

Operate the pump only when there is an excess of power available. It is important to avoid running the pump if the batteries have not yet been charged - we don't want to have no power at night.

Requirements​

It is necessary to have at least two devices: one that can switch the power on or off for the controlled device (pump), and another device that provides information on the amount of available photovoltaic (PV) power and battery SOC (state of charge).

For this recipe, we will use a hybrid solar inverter that provides two specific parameters:

  1. total_pv_input_power - this refers to the total amount of power that is available from the solar panels.
  2. battery_capacity - this parameter indicates the state of charge of the battery.

A water pump which will be powered via a Sonoff 4 channel smart relay connected to second channel.

Rule​

-- define devices by using UCM ID
local inverter = enapter.device('A21D1F00E16CB9A75BAE11EB16D001E7')
local switch = enapter.device('B9B9B8D86D10C0B24C0EB40C1E903F99')

-- define controller (state machine) with default no_pv_power state
local ctrl = controller('load_control', { initial = 'no_pv_power' })

-- methods names must begin with run_ prefix
function ctrl:run_no_pv_power()

-- in order to avoid flapping of the pump when power
-- disappear / appear, we put set grace period of 15 min
if self:time_in_state() > 15*60 then
-- when we have more than 2000W of available PV power and
-- battery charged 85% we go to next state - available_pv_power
if inverter.telemetry.now('total_pv_input_power') > 2000
and inverter.telemetry.now('battery_capacity') > 85 then

self:next_state('available_pv_power')
end
end

-- switch count starts from 0. when swith On we execute command switch_off_1
if switch.telemetry.now('switch1') == 'On' then
switch.commands.execute('switch_off_1')
end
end

function ctrl:run_available_pv_power()
-- grace period is good practice, don't underestimate it.
if self:time_in_state() > 15*60 then
-- when we have less or equal to 2000W of available PV power or battery charged
-- less or equal than 85% we go to next state - no_pv_power
if inverter.telemetry.now('total_pv_input_power') <= 2000
or inverter.telemetry.now('battery_capacity') <= 85 then

self:next_state('no_pv_power')
end
end

-- switch count starts from 0. when swith Off we execute command switch_off_1
if switch.telemetry.now('switch1') == 'Off' then
switch.commands.execute('switch_on_1')
end
end

-- start state machine
ctrl:run()
Hardware diversity is welcome. Integrate any device into a unified energy network.
© 2022 Enapter
Developer toolkit
DocumentationReference