LogicMachine Forum
Easee EV Charger - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Easee EV Charger (/showthread.php?tid=3301)



Easee EV Charger - tomnord - 15.04.2021

Hello, any ideas on how to integrate this? 

https://api.easee.cloud/index.html



I've found a Python script on github, is it possible to convert this in any way?

https://github.com/fondberg/pyeasee



Regards..


RE: Easee EV Charger - admin - 15.04.2021

This is a similar API: https://forum.logicmachine.net/showthread.php?tid=1786
There's a difference in login procedure (GetToken function). You need to set the 'content-type' header to 'application/json' and send username/password as json string:
Code:
request_body= json.encode({   userName = 'aaa',   password = 'bbb', })



RE: Easee EV Charger - tomnord - 15.04.2021

Thanks, it works.

What would be the best way if i wanted the connection to the API to stay active, and then run seperate scripts for various commands?
It's not best practise to request new tokens for every command.


RE: Easee EV Charger - admin - 16.04.2021

Create a scheduled script that will call GetToken() periodically and save the token into storage. All other scripts will use this token to make requests.
Check the expiresIn field that /api/accounts/token returns. It will tell for how many seconds the token is valid. Adjust scheduled script execution period accordingly.


RE: Easee EV Charger - P3774n - 11.01.2022

(15.04.2021, 19:56)tomnord Wrote: Thanks, it works.

What would be the best way if i wanted the connection to the API to stay active, and then run seperate scripts for various commands?
It's not best practise to request new tokens for every command.

Did you get your script to work?

Are you willing to share your script and the commands for the Easee charger?


RE: Easee EV Charger - Habib - 14.01.2022

that would be very nice and would save me a lot of time :-)


RE: Easee EV Charger - tomnord - 28.01.2022

Works like a charm. I'll post when I have access to my LM again.


RE: Easee EV Charger - P3774n - 20.09.2022

(28.01.2022, 16:28)tomnord Wrote: Works like a charm. I'll post when I have access to my LM again.

Hi soo exaited about this!

Will you post it? Or sent it on PM?

Thanks


RE: Easee EV Charger - tomnord - 07.10.2022

Code:
-- Load modules require('json') require('ssl.https') require('ltn12') -- Set credentials for Easee API ChargerID = storage.get('EaseeAPI_ChargerID') API_Token = storage.get('EaseeAPI_Token')  --reads API Token from storage, The token is fetched from scheduled script: "Easee_Authenticate" --log(ChargerID) function RequestFromEasee(request)   request_url = 'https://api.easee.cloud/api/' .. request   local response_body = {}   local request_body = ""   local body, code, hdrs, stat = ssl.https.request{     url = request_url;     method = "GET";     headers =     {       ["Content-Type"] = "application/json";       ["Authorization"] = "Bearer " .. API_Token;     };     source = ltn12.source.string(request_body);     sink = ltn12.sink.table(response_body);   }   log(code)   if code == 200 then     ret = table.concat(response_body)     ret = json.pdecode(ret)     return ret   else     --API_Token = GetToken() -- request a new token   end end -- Get products, run once to get charger ID if ChargerID == nil then chargers = RequestFromEasee('chargers') Easee_ChargerID = chargers[1]["id"] --log(Easee_ChargerID, 'ID') -- Check here for your charger ID storage.set('EaseeAPI_ChargerID', Easee_ChargerID) end ChargerState = RequestFromEasee('chargers/' .. ChargerID  .. '/state') log(ChargerState) currentChargePower = ChargerState["totalPower"] currentCableRating = ChargerState["cableRating"] currentMaxPower = ChargerState["outputCurrent"] chargerOnline = ChargerState["isOnline"] currentChargeEnergy = ChargerState["sessionEnergy"] log(currentChargePower, currentCableRating, currentMaxPower, chargerOnline, currentChargeEnergy) function WriteToEasee(request, request_body)   request_url = 'https://api.easee.cloud/api/' .. request   local response_body = {}   local content_length   if type(request_body) == "string" then     content_length = #request_body   else     request_body = ""   end   local body, code, hdrs, stat = ssl.https.request{     url = request_url;     method = "POST";     headers =     {       ["Content-Type"] = "application/json";       ["Authorization"] = "Bearer " .. API_Token;       ["Content-Length"] = content_length;     };     source = ltn12.source.string(request_body);     sink = ltn12.sink.table(response_body);   }   log(code)   if code == 200 then     ret = table.concat(response_body)     ret = json.pdecode(ret)     return ret   else     API_Token = GetToken() -- request a new token   end end

Code:
require('json') require('ssl.https') require('ltn12') -- Set credentials for Easee API email ='****************' password ='*************' function GetToken()   request_token_url = 'https://api.easee.cloud/api/accounts/login'   local response_body = {}   local request_body = json.encode({       userName = email,       password = password, })   local body, code, hdrs, stat = ssl.https.request{     url = request_token_url;     method = "POST";     headers =     {       ["Content-Type"] = "application/json";       ["Content-Length"] = #request_body;     };     source = ltn12.source.string(request_body);     sink = ltn12.sink.table(response_body);   }   log(code)   if code == 200 then     ret = table.concat(response_body)     ret = json.pdecode(ret)     log(ret)     return ret.accessToken   end end -- Request token if not API_Token then     API_Token = GetToken()       log(API_Token, 'api_token') end --Store API Token to memory storage.set('EaseeAPI_Token', API_Token)



RE: Easee EV Charger - johan84 - 29.06.2025

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



RE: Easee EV Charger - Mr.D - 17.02.2026

Hi,

I am trying to write a certain setting to my Easee charger. I am monitoring my energy consumption and if the consumption in my house goes above a certain threshold, I would like to reduce the maxchargercurrent on my Easee chargers.
To stop, pause, resume and start charging I can send following comand:
"WriteToEasee('chargers/CHARGERID/commands/pause_charging"

However to change settings this does not work, as example:
WriteToEasee('chargers/CHARGERID/settings?maxChargerCurrent=10')
I assume this is linked to some APPLICATION/JSON... that goes above my level of skillset...

Anyone know who to send changes in settings?
This is the API descriptions
https://developer.easee.com/reference/charger_setchargersetting

Help is very much appreciated Big Grin


RE: Easee EV Charger - admin - 17.02.2026

Try this:
Code:
WriteToEasee('chargers/CHARGERID/settings', '{"maxChargerCurrent":10}')

If it does not work then add more logging to WriteToEasee(). Replace log(code) with log(body, code, hdrs, stat, response_body)


RE: Easee EV Charger - Mr.D - 17.02.2026

(17.02.2026, 11:59)admin Wrote: Try this:
Code:
WriteToEasee('chargers/CHARGERID/settings', '{"maxChargerCurrent":10}')

If it does not work then add more logging to WriteToEasee(). Replace log(code) with log(body, code, hdrs, stat, response_body)

Thanks Smile It worked!