Roller shutter with Electrodragon SPDT and HLW8012

After modding the Electrodragon SPDT, it is time to use it.

The goal is to make a roller shutter switch. A HLW8012 breakout board (energy meter) made also by Electrodragon will be used as a calibration system to handle percentage opening.

ESPeasy is the firmware of the main board and Domoticz the home automation manager.

Hardware

For security reasons and to avoid both UP and DOWN power lines powered in the same time, one relay is the power relay where as the other one is the direction relay.

Following the modding of the SPDT board: - GPIO4 and GPIO5 are input switches for buttons, internal pull-up is active and buttons are connected to GND, - GPIO14 (DHT) is power consumption line input from the HLW8012.

Other connections: - Relay (1) on GPIO12 is the ON/OFF switch, - Relay (2) on GPIO13 is the UP/DOWN switch, - HWL8012 SEL pin is connected to GND even if only CF pin is used (SEL is voltage/current selection on CF1 pin), - HLW8012 input line is connected between relays 1 and 2.

Software

The roller shutter switch have to : - be controlled by Domoticz and report his state, - be autonomous (manual switch in case of network lost), - handle percentage opening,

ESPeasy

Devices
Rules
Wireless switch
Manual switch
Calibration
Percentage opening

Domoticz

Device
Events

The rule is shared with the Lights control.

commandArray = {}

local relaisPav = { ["entrée"] = 65, ["salon"] = 66, ["salle à manger / cuisine"] = 67 }
local relaisCha = { ["WC"] = 66, ["salle de bain"] = 68, ["couloir"] = 70, ["Jaouen"] = 72, ["Leonie"] = 74, ["parents"] = 76 }

-- Normalize a given string
function stripChars(str)
    local tableAccents = {}
        tableAccents["à"] = "a"
        tableAccents["ç"] = "c"
        tableAccents["è"] = "e"
        tableAccents["é"] = "e"
        tableAccents["ê"] = "e"
        tableAccents["ù"] = "u"
    local normalizedString = ''

    for strChar in string.gmatch(str, "([%z\1-\127\194-\244][\128-\191]*)") do
        if tableAccents[strChar] ~= nil then
            normalizedString = normalizedString..tableAccents[strChar]
        else
            normalizedString = normalizedString..strChar
        end
    end
 return normalizedString
end

for i, v in pairs(devicechanged) do
    --print("i : "..i)
    --print("v : "..tostring(v))
    if (i:sub(1,5) == 'Volet') then
        i=tostring(i)
        addr=i:gsub('Volet ','VR_')
        espURL = "http://"..addr.."/control?cmd="
        if otherdevices[i] == 'Open' then
            pourcentage = 0
        elseif otherdevices[i] == 'Closed' then
            pourcentage = 100
        else
            pourcentage = tonumber(otherdevices_svalues[i])
        end
        -- print("Valeur d'ouverture du volet :"..pourcentage)
        commandArray[1] = {['OpenURL'] = espURL..'event,move='..pourcentage}
    end

    if (stripChars(i):sub(1,7) == "Lumiere") then
            --print("i : "..stripChars(i))
            --print("v : "..tostring(v))
            if relaisPav[i:gsub('Lumière ','')] then
                commandArray[1] = {['OpenURL'] = 'http://Relais_PaV/control?cmd=event,Toggle='..relaisPav[i:gsub('Lumière ','')]}
            elseif relaisCha[i:gsub('Lumière ','')] then
                commandArray[1] = {['OpenURL'] = 'http://Relais_Cha/control?cmd=event,Toggle='..relaisCha[i:gsub('Lumière ','')]}
            end
    end
end

return commandArray
Switches

Révisions