The goal is to control all my lights with Domoticz and my wall switches.
A NodeMCU v3 will be used as the controller, a PCF8574 board to extand I/O, a 4 relays board to switch lights on/off and a mini AC-DC converter.
ESPeasy is the firmware of the main board and Domoticz the home automation manager.
Lights in the home are simple or 3-way switches. By the way, all cables from live, neutral and between switches and lights are gathered in a connecting box as the following:
The house is divided into two part, one for living rooms with 6 lights (2 are peers) and one for sleeping rooms with 7 independant lights. Thus there are two boxes.
The idea is to implement all the stuff in these boxes. The configuration will be the following one :
As NodeMCU as few GPIO pin available, PCF8574A boards will be used to expand I/O ports. For living rooms, one board is mandatory whereas in sleeping rooms two boards are mandatory.
GPIOs 4 (D1) and 5 (D2) will be used as SDA and SCL.
Lights have to :
- be controlled by Domoticz,
- be autonomous (manual switch in case of network lost) and report back the state of lights to Domoticz.
The rule is shared with the RollerShutter 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