esp32-evse icon indicating copy to clipboard operation
esp32-evse copied to clipboard

Available switch vs. Emergency STOP

Open nagyrobi opened this issue 7 months ago • 3 comments

Setting the charger available switch to off will reset itself back to on almost immediately:

I (11:42:55.171) evse: Set available 0
I (11:42:55.202) evse: Enter F state
I (11:42:55.203) pilot: Set level 0
I (11:42:55.204) ac_relay: Set relay: 0
I (11:42:55.829) evse: Set available 1
I (11:42:55.882) evse: Enter A state
I (11:42:55.883) pilot: Set level 1
I (11:42:55.884) ac_relay: Set relay: 0

Seeing this behavior either triggered from web UI or through AT commands.

Not sure if it interferes or not with the emergency stop lua script:

local evse = require("evse")
local aux = require("aux")
local boardconfig = require("boardconfig")

function contains(table, value)
    for _, v in ipairs(table) do
        if v == value then
            return true
        end
    end
    return false
end

return {
    id = "stopbutton",
    name = "Stop button",
    description = "Set charger not available when AUX input has targeted value",
    params = {
        aux = { type = "string", name = "Input name", default = "IN1" },
        activehigh = { type = "boolean", name = "Active high", default = true }
    },
    start = function(params)
        print("Starting stopbutton...")

        if not contains(boardconfig.auxinputs, params.aux) then
            error("Unknown aux input")
        end

        return coroutine.create(function()
            while true do
                local value = aux.read(params.aux)
--                print("Input read: ".. tostring(value))
                if (not params.activehigh) then
                    value = not value
                end
                if not value ~= evse.getavailable() then
                    print("Stop button pressed: ".. tostring(value))
--                    evse.setenabled(0)
                    evse.setavailable(not value)
                end
                coroutine.yield(1000)
            end
        end)
    end
}

nagyrobi avatar Sep 25 '25 09:09 nagyrobi

Hi @nagyrobi I have no similar issue. All on/off done manually via UI and LCD. But also I have no any LUA scripts.


I (19:45:30.831) evse: Set enabled 0
I (19:45:37.920) evse: Enter B1 state
I (19:45:37.920) ac_relay: Set relay: 0
I (19:45:37.921) socket_lock: Set locked 1
I (19:45:37.922) proximity: Max current: 20A
I (19:45:37.923) energy_meter: Start session
I (19:45:39.716) socket_lock: Lock OK
I (19:45:45.566) evse: Set enabled 1
I (19:45:45.660) evse: Enter B2 state
I (19:45:45.661) pilot: Set amp 195A*10 duty 323/1023
I (19:45:45.662) ac_relay: Set relay: 0
I (19:45:49.812) evse: Set enabled 0
I (19:45:49.902) evse: Enter B1 state
I (19:45:49.903) pilot: Set level 1
I (19:45:49.903) ac_relay: Set relay: 0
I (19:45:49.904) proximity: Max current: 20A
I (19:46:13.416) evse: Set enabled 1
I (19:46:13.460) evse: Enter B2 state
I (19:46:13.461) pilot: Set amp 195A*10 duty 323/1023
I (19:46:13.461) ac_relay: Set relay: 0
I (19:46:22.230) evse: Enter C2 state
I (19:46:22.231) ac_relay: Set relay: 1
I (19:46:28.812) evse: Set enabled 0
I (19:46:28.892) evse: Enter C1 state
I (19:46:28.893) pilot: Set level 1
W (19:46:34.950) evse: Force switch off ac relay
I (19:46:34.950) ac_relay: Set relay: 0
I (19:47:15.256) evse: Set enabled 1
I (19:47:15.300) evse: Enter C2 state
I (19:47:15.301) pilot: Set amp 195A*10 duty 323/1023
I (19:47:15.301) ac_relay: Set relay: 1
I (19:47:27.856) evse: Set enabled 0
I (19:47:27.940) evse: Enter C1 state
I (19:47:27.940) pilot: Set level 1
W (19:47:33.969) evse: Force switch off ac relay
I (19:47:33.970) ac_relay: Set relay: 0
I (19:47:42.380) evse: Enter A state
I (19:47:42.380) ac_relay: Set relay: 0
I (19:47:42.381) socket_lock: Set locked 0
I (19:47:42.382) energy_meter: Stop session

dekamilv avatar Sep 26 '25 16:09 dekamilv

The stopbutton lua script is from: https://github.com/dzurikmiroslav/esp32-evse/wiki/Lua#complex-example is incorrect because it ties the Available switch solely to the emergency stop button, making use of it from Web UI or display impossible.

Corrected the stopbutton.lua script to this:

local evse = require("evse")
local aux = require("aux")
local boardconfig = require("boardconfig")
local stopped_by_button = false

function contains(table, value)
    for _, v in ipairs(table) do
        if v == value then
            return true
        end
    end
    return false
end

return {
    id = "stopbutton",
    name = "Emergency stop button",
    description = "Set charger to not available when AUX input has targeted value",
    params = {
        aux = { type = "string", name = "Input name", default = "IN1" },
        activehigh = { type = "boolean", name = "Active high", default = true }
    },
    start = function(params)
        print("starting stopbutton...")

        if not contains(boardconfig.auxinputs, params.aux) then
            error("unknown aux input")
        end

        return coroutine.create(function()
            while true do
                local value = aux.read(params.aux)
--                print("Input read: ".. tostring(value))
                if (not params.activehigh) then
                    value = not value
                end
                if not value ~= true then
                    if not evse.getavailable() == false then
                        evse.setavailable(false)
                        stopped_by_button = true
                    end
                end
                if not value ~= false then
                    if stopped_by_button == true then
                        evse.setavailable(true)
                        stopped_by_button = false
                    end
                end
                coroutine.yield(1000)
            end
        end)
    end
}

This will comply with the following:

  • the emergency button pressed, will turn off the Available switch on EVSE (connected between +12V and IN1)
  • it will force the Available switch off as long as the button is pressed down
  • after the emergency has been solved, the disengage of the button will turn back on the Available switch
  • usage of the the Available switch through the display or the web UI can be independent from the emergency button as long as it's not pressed (eg. can be used to make it "out of order" etc.)
  • if the Available switch was turned off through the display or the web UI, it's not possible to turn it back on by pressing and releasing the emergency button.

nagyrobi avatar Sep 26 '25 19:09 nagyrobi

Use it with a single lined init.lua executor:

component.register(require("stopbutton"))

nagyrobi avatar Sep 26 '25 20:09 nagyrobi

Updated the Wiki with the correction above.

nagyrobi avatar Nov 26 '25 18:11 nagyrobi