Edit: Be sure to restart your gateway after adding your bulbs and before setting this up, as it will reorder them alphabetically at reboot.
Edit 2: Updated to match updated python script. It now uses the device ID, instead of list order.
Steps:
- Set up the script following pytradfri and moroen's instructions and confirm it's working.
- Copy pytradfri into the root python folder, otherwise it wont import it correctly:
Code: Select all
sudo cp -r /usr/local/lib/python3.4/site-packages/pytradfri /usr/lib/python3.4/
- Create a new Lua Device script under events and copy the script below into it (correct the python script path if you've placed it somewhere else).
- Create virtual selector switches for each of your bulbs.
- Go into their settings and change their type to dimmer.*
- Insert the switch names and ids into the hash at the top of the script.
Script:
Code: Select all
local lights = {
['Badeværelse'] = {id = 65538},
['Depot'] = {id = 65537},
['Køkken'] = {id = 65539},
['Kontor Spot 1'] = {id = 65540},
['Kontor Spot 2'] = {id = 65542},
['Kontor Spot 3'] = {id = 65541}
}
function setlight (id, command, val)
--print("tradfri.py "..id.." "..command.." "..val)
os.execute("/home/pi/domoticz/scripts/python/tradfri.py "..id.." "..command.." "..val.." &")
end
function mapvalue(inputValue)
inputValue = tonumber(inputValue)
normalizedCurVal = (inputValue - 1.0) / 99.0
rangedValue = (normalizedCurVal * 255.0) + 1.0
return math.ceil(rangedValue)
end
commandArray = {}
for deviceName,deviceValue in pairs(devicechanged) do
if (lights[deviceName]) then
if (deviceValue == 'Off') then
setlight(lights[deviceName]["id"], 'off', '')
elseif (deviceValue == 'On') then
setlight(lights[deviceName]["id"], 'on', '')
else
dvalue = mapvalue(otherdevices_svalues[deviceName])
setlight(lights[deviceName]["id"], 'level', dvalue)
end
end
end
return commandArray
Code: Select all
script:///home/pi/domoticz/scripts/python/tradfri.py 65538 whitetemp cold