This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Easee EV Charger
#10
Here is a script I use at a client's company to visualize the current charging power at each charging point in their company parking lot. Thank you tomnord for the earlier scrips Smile


Code:
-- Load required libraries once
require('json')
require('ssl.https')
require('ltn12')
-- Your configuration
local API_Token = storage.get('EaseeAPI_Token')
-- Define all 8 charging stations with placeholder names, IDs and KNX group addresses
local chargingStations = {
  { name = 'charger 1', id = 'charger 1 id', ga = '55/1/1' },
  { name = 'charger 2', id = 'charger 2 id', ga = '55/1/2' },
  { name = 'charger 3', id = 'charger 3 id', ga = '55/1/3' },
  { name = 'charger 4', id = 'charger 4 id', ga = '55/1/4' },
  { name = 'charger 5', id = 'charger 5 id', ga = '55/1/5' },
  { name = 'charger 6', id = 'charger 6 id', ga = '55/1/6' },
  { name = 'charger 7', id = 'charger 7 id', ga = '55/1/7' },
  { name = 'charger 8', id = 'charger 8 id', ga = '55/1/8' },
}
-- Function for making a GET request to the Easee API
local function RequestFromEasee(endpoint)
  local url      = 'https://api.easee.cloud/api/' .. endpoint
  local response = {}
  local _, code  = ssl.https.request{
    url    = url,
    method  = "GET",
    headers = {
      ["Content-Type"]  = "application/json",
      ["Authorization"] = "Bearer " .. API_Token,
    },
    sink = ltn12.sink.table(response),
  }
  if code == 200 then
    return json.pdecode(table.concat(response))
  else
    log('Easee API error (' .. endpoint .. '): ' .. tostring(code))
    return nil
  end
end
-- Parameters for power calculation
local voltage = 230    -- V per phase
local phases  = 3      -- three-phase
local cosFi  = 0.95  -- power factor, adjust if needed
-- Loop over all charging stations
for _, station in ipairs(chargingStations) do
  -- Fetch status
  local state = RequestFromEasee('chargers/' .. station.id .. '/state')
  if state then
    -- Try to use totalPower directly
    local power = state.totalPower
    if not power or power == 0 then
      -- Fallback: calculate using I × U × √3 × cosφ
      local current = state.outputCurrent or 0
      power = (current * voltage * phases * cosFi) / 1000  -- in kW
    end
    -- Send power (kW) to the configured KNX group address
    grp.write(station.ga, power)
  else
    log('Could not retrieve status for ' .. station.name .. ' (' .. station.id .. ')')
  end
end
Reply


Messages In This Thread
Easee EV Charger - by tomnord - 15.04.2021, 06:31
RE: Easee EV Charger - by admin - 15.04.2021, 13:04
RE: Easee EV Charger - by tomnord - 15.04.2021, 19:56
RE: Easee EV Charger - by P3774n - 11.01.2022, 19:47
RE: Easee EV Charger - by admin - 16.04.2021, 05:15
RE: Easee EV Charger - by Habib - 14.01.2022, 08:31
RE: Easee EV Charger - by tomnord - 28.01.2022, 16:28
RE: Easee EV Charger - by P3774n - 20.09.2022, 15:16
RE: Easee EV Charger - by tomnord - 07.10.2022, 16:51
RE: Easee EV Charger - by johan84 - 29.06.2025, 19:38

Forum Jump: