-- Script to update X10 dimmer switch using Heyu -- Adjust the value assigned to NAME to reflect the dimmer switch name in Domoticz -- Adjust the value assigned to ADDR to reflect the X10 house and device code of the dimmer switch -- Adjust VERBOSE to control messages to Domoticz' log commandArray = {} NAME = 'Lampe sur pied' ADDR = 'B1' VERBOSE = 0 -- 0 = quiet, 1 = logs os.execute commands, 2 = debugs if devicechanged[NAME] then cmd = string.lower(string.sub(devicechanged[NAME], 1, 9)) if (VERBOSE > 1) then print('NAME: ' .. NAME) print('devicechanged[NAME]: '..devicechanged[NAME]) print('otherdevices_svalue[NAME]: ' .. otherdevices_svalues[NAME]) print('cmd: ' .. cmd) end if (cmd == 'on') or (cmd == 'off') then cmd = 'sudo -u pi /usr/local/bin/heyu ' .. cmd .. " " .. ADDR os.execute(cmd) if (VERBOSE > 0) then print(cmd) end elseif (cmd == 'set level') then name_level_var = 'Bright_Level_'..ADDR wanted_level = math.ceil(tonumber(otherdevices_svalues[NAME]) * 0.22) current_level = math.ceil(uservariables[name_level_var] * 0.22) commandArray['Variable:'..name_level_var] = otherdevices_svalues[NAME] delta = wanted_level - current_level if (VERBOSE > 1) then print('otherdevices_svalues[NAME]: '..otherdevices_svalues[NAME]) print('name of internal variable (name_level_var): ' .. name_level_var) print('wanted heyu dim level (0..22): ' .. wanted_level) print('current heyu dim level (0..22): ' .. current_level) print('delta (-22..22): ' .. delta) end if delta > 0 then action = 'bright ' elseif delta < 0 then action = 'dim ' delta = -delta end if delta ~= 0 then cmd = 'sudo -u pi /usr/local/bin/heyu '..action.." "..ADDR.." ".. delta os.execute(cmd) if (VERBOSE > 0) then print(cmd) end end end end return commandArray