Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

## [Unreleased]

### easee_cloud 1.4.2

The driver re-sends its current limit as a charger command. Easee puts the
limit back at its maximum when charging resumes (32 A reported, #225). The
settings write reaches the charger only when the cloud's stored value
changes, so re-sending the same order never undid that. On a 16 A fuse a
7 A order drew 16 A for about 10 s.

- 3 s after a resume or start, and after a phaseMode write, the order goes
out as `set_dynamic_charger_current` with `minutes: 0`.
- When the charger reports a higher limit than ordered, or draws more than
2 A over the order, the order is re-sent as a command, at most every 10 s.
- `minutes: 0` holds the limit until the next one, as Easee documents. A 0 A
order goes out as a 0 A command too, the limit a pause sets.
- A failed re-send is retried every 10 s, not on every poll.
- When a lower order's settings write fails, re-sends use that lower order,
not the earlier, higher one.

### easee_cloud 1.4.1

The driver says its session energy is coarse, with `session_wh_coarse`. Easee
Expand Down
4 changes: 2 additions & 2 deletions SUPPORT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ Catalog source is not proof that a target can install or run a driver.
| deye | 2.1.1 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| easee | 1.0.4 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| easee | 1.0.4 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| easee_cloud | 1.4.1 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| easee_cloud | 1.4.1 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| easee_cloud | 1.4.2 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| easee_cloud | 1.4.2 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| esphome_dsmr | 1.0.7 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| esphome_dsmr | 1.0.7 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| etrel | 1.0.3 | ftw-core | not_assessed | — | not_recorded | not_assessed |
Expand Down
2 changes: 1 addition & 1 deletion devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ manufacturers:
protocols:
- protocol: http
driver: "easee_cloud"
version: "1.4.1"
version: "1.4.2"
ders: [ev]
control: true
firmware_versions: ""
Expand Down
68 changes: 60 additions & 8 deletions drivers/lua/easee_cloud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DRIVER = {
id = "easee_cloud",
name = "Easee Cloud",
manufacturer = "Easee",
version = "1.4.1",
version = "1.4.2",
protocols = { "http" },
capabilities = { "ev" },
description = "Easee Home/Charge via Cloud REST API. No local protocol needed.",
Expand Down Expand Up @@ -65,6 +65,8 @@ local last_phase_change_ms = 0 -- monotonic ms of the last phase flip (hysteresi
-- when an operator config field requests it (see driver_init below).
local pending_amp_resend = false
local pending_amp_resend_at_ms = 0
local last_reassert_ms = -1e12 -- when a poll last re-sent the order as a command
local REASSERT_MS = 10000
local last_amps_set = nil

-- paused_state tracks whether the LAST command we successfully sent was
Expand Down Expand Up @@ -801,6 +803,34 @@ local function write_setting(serial, body_table)
return err
end

-- command_current sends the current limit as a charger command. The settings
-- write reaches the charger only when the cloud's stored value changes ("Will
-- only forward commands to device if new value != old value",
-- developer.easee.com/reference/charger_setchargersetting). A resume or a
-- phaseMode write puts the charger back at its maximum (32 A reported, #225)
-- while the cloud still stores our order, so re-sending that order as a
-- setting never reaches the charger. A command always does. minutes = 0
-- "results in a limit being applied until another one is set"
-- (developer.easee.com/reference/charger_set_dynamic_charger_current).
-- amps = 0 sets the limit a pause sets ("Limits dynamic charger current to
-- 0", charger_pausesession); Easee accepted every 0 A command on a real
-- charger.
local function command_current(serial, amps)
local _, err = host.http_post(
BASE_URL .. "/chargers/" .. serial .. "/commands/set_dynamic_charger_current",
host.json_encode({amps = amps, minutes = 0}), auth_headers())
return err
end

-- resend_after_resume schedules the order as a command once Easee has had
-- time to apply the resume's reset.
local function resend_after_resume()
if last_amps_set ~= nil then
pending_amp_resend = true
pending_amp_resend_at_ms = host.millis() + 3000
end
end

-- start_boost_fits: 7 A per phase fits when Core's cap for this charger
-- (cap_amps_per_phase: its room below the fuse and the import limit, after
-- other chargers' share), the order's max_amps_per_phase and the charger's
Expand Down Expand Up @@ -1141,22 +1171,39 @@ function driver_poll()
-- as the controller would issue on its next 5 s tick, just earlier.
--
-- Only clear the flag on success. A transient network failure or
-- 5xx leaves it pending so the NEXT poll retries instead of
-- silently leaving the charger pinned at maxChargerCurrent. The
-- 5xx leaves it pending, retried every REASSERT_MS instead of on
-- every poll, so the charger is not left pinned at
-- maxChargerCurrent and the cloud is not hammered. The
-- controller's own 5 s tick is the safety floor; this just
-- accelerates convergence in the common case.
if pending_amp_resend and last_amps_set ~= nil and host.millis() >= pending_amp_resend_at_ms then
local werr = write_setting(charger_serial, {dynamicChargerCurrent = last_amps_set})
local werr = command_current(charger_serial, last_amps_set)
if werr == nil then
host.log("info", "Easee: re-asserted dynamicChargerCurrent=" .. tostring(last_amps_set) ..
" A after phaseMode reset")
" A as a command after a phaseMode write or resume")
pending_amp_resend = false
else
host.log("warn", "Easee: dynamicChargerCurrent re-assert failed (will retry next poll): " ..
pending_amp_resend_at_ms = host.millis() + REASSERT_MS
host.log("warn", "Easee: dynamicChargerCurrent re-assert failed (will retry in 10 s): " ..
redact_http_err(werr))
end
end

-- A charger that allows more than we ordered gets the order again as a
-- command, at most every REASSERT_MS: Easee resets its limit by itself
-- (see command_current). On a 16 A fuse a 7 A order drew 16 A for 10 s.
local current_a = obs[OBS_CURRENT]
if connected and last_amps_set ~= nil and now - last_reassert_ms >= REASSERT_MS and
((dyn_current and dyn_current > last_amps_set + 0.5) or
(charging and current_a and current_a > last_amps_set + 2)) then
last_reassert_ms = now
local cerr = command_current(charger_serial, last_amps_set)
host.log("warn", string.format(
"Easee: charger allows %s A / draws %s A over our %s A order; re-sent it as a command%s",
tostring(dyn_current), tostring(current_a), tostring(last_amps_set),
cerr and (" (failed: " .. redact_http_err(cerr) .. ")") or ""))
end

-- 6 A start boost: step down to the ordered 6 A as soon as the charger
-- reports charging. The timeout is checked above, before observations.
if boost_until_ms ~= nil and charging then
Expand Down Expand Up @@ -1207,7 +1254,7 @@ function driver_command(action, power_w, cmd)

if action == "ev_start" then
local ok = post_command("/commands/start_charging")
if ok then paused_state = false end
if ok then paused_state = false; resend_after_resume() end
return ok
elseif action == "ev_pause" then
local ok = post_command("/commands/pause_charging")
Expand All @@ -1220,7 +1267,7 @@ function driver_command(action, power_w, cmd)
return ok
elseif action == "ev_resume" then
local ok = post_command("/commands/resume_charging")
if ok then paused_state = false end
if ok then paused_state = false; resend_after_resume() end
return ok
elseif action == "ev_set_current" then
-- Driver-level phase decision: read the operator's preferences
Expand Down Expand Up @@ -1342,10 +1389,15 @@ function driver_command(action, power_w, cmd)
if amps > 0 and paused_state then
if post_command("/commands/resume_charging") then
paused_state = false
resend_after_resume()
host.log("info", "Easee: auto-resumed after pause (offer=" ..
tostring(amps) .. " A)")
end
end
elseif last_amps_set ~= nil and write_a < last_amps_set then
-- A failed cut is still the order: re-sending the earlier,
-- higher one would undo it.
last_amps_set = write_a
end
return err == nil
end
Expand Down
141 changes: 141 additions & 0 deletions drivers/tests/lua_harness/test_easee_cloud_resend.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
-- Easee puts its limit back at its maximum on a resume (32 A reported, #225),
-- and a settings write of an unchanged value never reaches the charger. The
-- driver re-sends its order as a command after a resume and whenever the
-- charger allows or draws more than the order.
dofile("drivers/tests/lua_harness/host_mock.lua")
local driver = "drivers/lua/easee_cloud.lua"

-- POSTs to a URL containing fail_url fail like a 503, after being recorded.
local fail_url
local real_post = host.http_post
host.http_post = function(url, body, headers)
local resp = real_post(url, body, headers)
if fail_url and url:find(fail_url, 1, true) then return nil, "HTTP 503" end
return resp
end

local function boot()
host.reset()
fail_url = nil
host._http_responses["/accounts/login"] = '{"accessToken":"test","expiresIn":3600}'
host._http_responses["/config"] = '{"maxChargerCurrent":16}'
host._http_responses["/settings"] = '{}'
host._http_responses["/commands/"] = '{}'
host._http_responses["/sessions/ongoing"] = '{}'
dofile(driver)
driver_init({email="test@example.invalid", password="test", serial="TEST123"})
end

local function commands()
local out = {}
for _, call in ipairs(host._calls) do
if call.func == "http_post" and call.args[1]:find("/commands/set_dynamic_charger_current", 1, true) then
local body = host.json_decode(call.args[2])
assert(body.minutes == 0, "minutes must be 0: Easee holds that limit until the next one")
table.insert(out, body.amps)
end
end
return out
end

local function poll(mode, dyn, cur)
local obs = {{id=109,value=mode}, {id=120,value=0}, {id=121,value=1}, {id=124,value=100}}
if dyn then table.insert(obs, {id=48,value=dyn}) end
if cur then table.insert(obs, {id=183,value=cur}) end
host._http_responses["/observations?ids="] = host.json_encode(obs)
driver_poll()
end
local function later(ms) host._millis_counter = host._millis_counter + ms end

-- 7 A per phase, below the 16 A fuse; not a 6 A start, so no start boost.
local SEVEN = {phase_mode="3p", voltage=230, max_amps_per_phase=16, cap_amps_per_phase=7}

-- 1. A resume is followed by the order as a command.
boot()
poll(2, 7)
assert(driver_command("ev_set_current", 4830, SEVEN))
later(6000); poll(2, 7) -- the startup phaseMode re-assert
local before = #commands()
assert(driver_command("ev_resume", 0, {}))
poll(2, 7)
assert(#commands() == before, "re-sent before Easee applied the resume")
later(3000); poll(2, 7)
local c = commands()
assert(#c == before + 1 and c[#c] == 7, "no 7 A command after a resume")

-- 2. A charger that allows more than the order gets it again, rate-limited.
boot()
poll(2, 7)
assert(driver_command("ev_set_current", 4830, SEVEN))
later(6000); poll(2, 7)
before = #commands()
poll(3, 32, 7)
c = commands()
assert(#c == before + 1 and c[#c] == 7, "32 A on the charger did not re-send 7 A")
poll(3, 32, 7)
assert(#commands() == before + 1, "re-sent again within 10 s")
later(10000); poll(3, 32, 7)
assert(#commands() == before + 2, "no retry after 10 s")

-- 3. A car drawing well over the order re-sends it even when the reported
-- limit still reads the order.
later(10000); before = #commands()
poll(3, 7, 16)
assert(#commands() == before + 1, "16 A drawn against 7 A did not re-send")

-- 4. Within the order nothing is sent.
later(10000); before = #commands()
poll(3, 7, 7.4)
poll(3, 6, 6)
assert(#commands() == before, "re-sent although the charger kept the order")

-- 5. A disconnected charger is left alone.
later(10000); before = #commands()
poll(1, 32)
assert(#commands() == before, "re-sent to a charger with no car")

-- 6. A failed re-send after a resume is retried every 10 s, not every poll.
boot()
poll(2, 7)
assert(driver_command("ev_set_current", 4830, SEVEN))
later(6000); poll(2, 7)
fail_url = "/commands/set_dynamic_charger_current"
assert(driver_command("ev_resume", 0, {}))
later(3000); poll(2, 7)
before = #commands()
later(5000); poll(2, 7)
assert(#commands() == before, "retried a failed re-send within 10 s")
later(5000); poll(2, 7)
assert(#commands() == before + 1, "no retry 10 s after a failed re-send")
fail_url = nil
later(10000); poll(2, 7)
later(10000); poll(2, 7)
assert(#commands() == before + 2, "kept re-sending after one went through")

-- 7. A 0 A order is held as a 0 A command too: Easee accepts it, as its
-- pause does.
boot()
poll(2, 7)
driver_default_mode()
before = #commands()
poll(2, 32)
c = commands()
assert(#c == before + 1 and c[#c] == 0, "32 A on the charger did not re-send 0 A")
poll(2, 32)
later(10000); poll(2, 0)
assert(#commands() == before + 1, "re-sent 0 A within 10 s or to a charger at 0 A")

-- 8. A cut whose settings write failed is the order to re-send, not the
-- earlier, higher one.
local TWELVE = {phase_mode="3p", voltage=230, max_amps_per_phase=16, cap_amps_per_phase=12}
boot()
poll(2, 12)
assert(driver_command("ev_set_current", 8280, TWELVE))
later(6000); poll(2, 12)
fail_url = "/settings"
assert(not driver_command("ev_set_current", 5520, TWELVE))
poll(3, 12, 12)
c = commands()
assert(c[#c] == 8, "a failed cut to 8 A re-sent " .. tostring(c[#c]) .. " A")

print("easee_cloud resend: ok")
2 changes: 2 additions & 0 deletions drivers/tests/lua_harness/test_easee_cloud_start_boost.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ local function amps_writes()
if call.func == "http_post" and call.args[1]:find("/settings", 1, true) then
local body = host.json_decode(call.args[2])
if body.dynamicChargerCurrent ~= nil then table.insert(out, body.dynamicChargerCurrent) end
elseif call.func == "http_post" and call.args[1]:find("/commands/set_dynamic_charger_current", 1, true) then
table.insert(out, host.json_decode(call.args[2]).amps)
end
end
return out
Expand Down
12 changes: 12 additions & 0 deletions drivers/tests/test_easee_cloud_resend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Easee's own limit reset is undone by re-sending the order as a command."""
from pathlib import Path
import subprocess


def test_easee_cloud_resend():
root = Path(__file__).resolve().parents[2]
result = subprocess.run(
[str(root / "lua55"), "drivers/tests/lua_harness/test_easee_cloud_resend.lua"],
cwd=root, text=True, capture_output=True, check=False,
)
assert result.returncode == 0, result.stdout + result.stderr
6 changes: 3 additions & 3 deletions index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ drivers:
size_bytes: 4054
sha256: "4a2cd1efb4a5583468ce897ebd88a000e348917295c40210e86ecf834c0ba543"
- name: "easee_cloud"
version: "1.4.1"
version: "1.4.2"
tier: core
protocol: http
connectivity: cloud
setup: [vendor_portal]
ders: [ev]
control: true
size_bytes: 64392
sha256: "de954b416dcab6d9d7af06075056dce30a1e9d8dbba80223d78a1cdb806101cd"
size_bytes: 67183
sha256: "8660b09c8f96b22621660b655ce2c22b849178437beef37b6c937a052fd2ab68"
- name: "esphome_dsmr"
version: "1.0.7"
tier: core
Expand Down
6 changes: 3 additions & 3 deletions manifests/easee_cloud.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "easee_cloud"
version: "1.4.1"
version: "1.4.2"
tier: core
author: "Sourceful Labs AB"
protocol: http
Expand All @@ -16,9 +16,9 @@ tested_devices:
notes: "Easee Home/Charge via Cloud REST API. No local protocol needed."
min_driver_version: "1.0.1"
min_host_version: "2.0.0"
size_bytes: 64392
size_bytes: 67183
dkb_id: "easee_cloud"
sha256: "de954b416dcab6d9d7af06075056dce30a1e9d8dbba80223d78a1cdb806101cd"
sha256: "8660b09c8f96b22621660b655ce2c22b849178437beef37b6c937a052fd2ab68"
signature: ""

bytecode_sha256: ""
Expand Down
2 changes: 1 addition & 1 deletion support-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@
},
{
"catalog_source": true,
"catalog_version": "1.4.1",
"catalog_version": "1.4.2",
"driver_id": "easee_cloud",
"targets": {
"blixt-l1": {
Expand Down