- Din varukorg är tom!
- H-Support
Fibaro - KeyFob LUA mot ZNet Lite V2
- Publicerat: 2017-03-10
- Kategori:
- ▸ Wiki
- ▸ Hemautomation
- ▸ Z-Wave
Här tänkte vi gå igenom lite LUA kod för att använda den otroligt snygga Fibaro KeyFob mot en ZNet!
Fibaro KeyFob är en fjärrkontroll med otroligt mycket kompetens. Den kan ta upp till 24 olika funktioner, 1/2/3 tryck och hålla in och går att nyttja till i stort sett vad som helst när det gäller Z-Wave eller 433MHz enheter via ZNeten.
Om ni inte har någon kunskap alls om LUA mot ZNet så kan ni följa början på denna guide Fibaro – The Button LUA mot Telldus ZNet
Snabbmeny
Skapa grupp med enheter Telldus Live
Vänster sida = på / Höger sida = av
Ett klick = på / Håll in = av
Ett klick = på / Två klick = av
Momentan användning av knapp
För att förklara vad ni behöver ändra i dessa koder så är det enhet eller grupp 1/2/3 osv som ni ska ändra benämningen på för att match era enheter i Telldus Live.
Skapa grupp med enheter
Om ni vill påverka flera enheter på en och samma knapp så behöver ni bara skapa en grupp i Telldus Live och markera de enheter som ska startas/stängas av.
För att skapa en grupp av enheter så går ni till "Enheter"

Klicka sedan på namnet till er ZNet och sedan gå in på "Grupp"

Sen är det bara att markera de enheter som ni önskar påverka
Namnet på er grupp är alltså det ni kommer skriva under enhet eller grupp 1/2/3 osv. i vår LUA-kod.
KOD
Vänster sida = på / höger sida = av
-- VÄNSTRA SIDAN AV DOSAN STARTAR, HÖGRA STÄNGER AV.
-- NAMN PÅ DINA ENHETER DU VILL PÅVERKA::
local remotecontrol = "KeyFob" -- FJÄRR
local device1 = "enhet eller grupp 1" -- FYRKANT/CIRKEL
local device2 = "enhet eller grupp 2" -- X/TRIANGEL
local device3 = "enhet eller grupp 3" -- MINUS/PLUS
debug = false
-- DO NOT EDIT BELOW THIS LINE --
KEY_PRESS = 128
KEY_HOLD = 130
KEY_RELEASE = 129
COMMAND_CLASS_CENTRAL_SCENE = 0x5B
CENTRAL_SCENE_NOTIFICATION = 0x03
local deviceManager = require "telldus.DeviceManager"
function scene1(action)
if action == KEY_PRESS then
local control = deviceManager:findByName(device1)
if control == nil then
print("Could not find device: %s", device1)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
end
function scene2(action)
if action == KEY_PRESS then
local control = deviceManager:findByName(device1)
if control == nil then
print("Could not find device: %s", device1)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function scene3(action)
if action == KEY_PRESS then
local control = deviceManager:findByName(device2)
if control == nil then
print("Could not find device: %s", device2)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
end
function scene4(action)
if action == KEY_PRESS then
local control = deviceManager:findByName(device2)
if control == nil then
print("Could not find device: %s", device2)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function scene5(action)
if action == KEY_PRESS then
local control = deviceManager:findByName(device3)
if control == nil then
print("Could not find device: %s", device3)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
end
function scene6(action)
if action == KEY_PRESS then
local control = deviceManager:findByName(device3)
if control == nil then
print("Could not find device: %s", device3)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function onZwaveMessageReceived(device, flags, cmdClass, cmd, data)
if device:name() ~= remotecontrol then
return
end
if cmdClass ~= COMMAND_CLASS_CENTRAL_SCENE or cmd ~= CENTRAL_SCENE_NOTIFICATION then
return
end
if list.len(data) < 3 then
return
end
local sequence = data[0]
local action = data[1]
local scene = data[2]
if debug == true then
print("CENTRAL_SCENE_NOTIFICATION from: %s, Scene: %s, Action: %s", device:name(), scene, action)
end
if scene == 1 then
scene1(action)
elseif scene == 2 then
scene2(action)
elseif scene == 3 then
scene3(action)
elseif scene == 4 then
scene4(action)
elseif scene == 5 then
scene5(action)
elseif scene == 6 then
scene6(action)
end
end
Ett klick = på / Håll in = av
Här har vi en lite smidigare kod som gör att ett klick startar och håller du in samma knapp så stänger den av enheterna.
-- ETT KLICK ÄR PÅ, HÅLL IN KNAPP FÖR ATT STÄNGA AV
-- NAMN PÅ DINA ENHETER DU VILL PÅVERKA:
local remotecontrol = "KeyFob" -- FJÄRR
local device1 = "enhet eller grupp 1" -- FYRKANT
local device2 = "enhet eller grupp 2" -- CIRKEL
local device3 = "enhet eller grupp 3" -- X
local device4 = "enhet eller grupp 4" -- TRIANGEL
local device5 = "enhet eller grupp 5" -- MINUS
local device6 = "enhet eller grupp 6" -- PLUS
debug = false
-- DO NOT EDIT BELOW THIS LINE --
KEY_PRESS = 128
KEY_HOLD = 130
KEY_RELEASE = 129
COMMAND_CLASS_CENTRAL_SCENE = 0x5B
CENTRAL_SCENE_NOTIFICATION = 0x03
local deviceManager = require "telldus.DeviceManager"
function scene1(action)
-- FYRKANT START
if action == KEY_PRESS then
local control = deviceManager:findByName(device1)
if control == nil then
print("Could not find device: %s", device1)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
-- FYRKANT STÄNG AV
if action == KEY_HOLD then
local control = deviceManager:findByName(device1)
if control == nil then
print("Could not find device: %s", device1)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function scene2(action)
-- CIRKEL START
if action == KEY_PRESS then
local control = deviceManager:findByName(device2)
if control == nil then
print("Could not find device: %s", device2)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
-- CIRKEL STÄNG AV
if action == KEY_HOLD then
local control = deviceManager:findByName(device2)
if control == nil then
print("Could not find device: %s", device2)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function scene3(action)
-- X START
if action == KEY_PRESS then
local control = deviceManager:findByName(device3)
if control == nil then
print("Could not find device: %s", device3)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
-- X STÄNG AV
if action == KEY_HOLD then
local control = deviceManager:findByName(device3)
if control == nil then
print("Could not find device: %s", device3)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function scene4(action)
-- TRIANGEL START
if action == KEY_PRESS then
local control = deviceManager:findByName(device4)
if control == nil then
print("Could not find device: %s", device4)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
-- STIANGEL STÄNG AV
if action == KEY_HOLD then
local control = deviceManager:findByName(device4)
if control == nil then
print("Could not find device: %s", device4)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function scene5(action)
-- MINUS START
if action == KEY_PRESS then
local control = deviceManager:findByName(device5)
if control == nil then
print("Could not find device: %s", device5)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
-- MINUS STÄNG AV
if action == KEY_HOLD then
local control = deviceManager:findByName(device5)
if control == nil then
print("Could not find device: %s", device5)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
end
function scene6(action)
-- PLUS START
if action == KEY_PRESS then
local control = deviceManager:findByName(device6)
if control == nil then
print("Could not find device: %s", device6)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
-- PLUS STÄNG AV
if action == KEY_HOLD then
local control = deviceManager:findByName(device6)
if control == nil then
print("Could not find device: %s", device6)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end
function onZwaveMessageReceived(device, flags, cmdClass, cmd, data)
if device:name() ~= remotecontrol then
return
end
if cmdClass ~= COMMAND_CLASS_CENTRAL_SCENE or cmd ~= CENTRAL_SCENE_NOTIFICATION then
return
end
if list.len(data) < 3 then
return
end
local sequence = data[0]
local action = data[1]
local scene = data[2]
if debug == true then
print("CENTRAL_SCENE_NOTIFICATION from: %s, Scene: %s, Action: %s", device:name(), scene, action)
end
if scene == 1 then
scene1(action)
elseif scene == 2 then
scene2(action)
elseif scene == 3 then
scene3(action)
elseif scene == 4 then
scene4(action)
elseif scene == 5 then
scene5(action)
elseif scene == 6 then
scene6(action)
end
end
Ett klick = på / två klick = av
-- One click turns on a device, double click turns it off.
-- Please note that configuration 21-26 has to be set to handle double-click.
-- Define the names on your devices here:
local remotecontrol = "KeyFob"
devices = {}
devices[1] = "enhet eller grupp 1" -- FYRKANT
devices[2] = "enhet eller grupp 2" -- CIRKEL
devices[3] = "enhet eller grupp 3" -- X
devices[4] = "enhet eller grupp 4" -- TRIANGEL
devices[5] = "enhet eller grupp 5" -- MINUS
devices[6] = "enhet eller grupp 6" -- PLUS
debug = false
-- DO NOT EDIT BELOW THIS LINE --
KEY_PRESS = 128
KEY_DOUBLE = 131
KEY_TRIPPLE = 132
KEY_HOLD = 130
KEY_RELEASE = 129
COMMAND_CLASS_CENTRAL_SCENE = 0x5B
CENTRAL_SCENE_NOTIFICATION = 0x03
local deviceManager = require "telldus.DeviceManager"
function control(device_to_control, action)
if action == KEY_PRESS then
local control = deviceManager:findByName(device_to_control)
if control == nil then
print("Could not find device: %s", device_to_control)
return
end
control:command("turnon", nil, "SceneMaster")
print("Turning on device: %s", control:name())
elseif action == KEY_DOUBLE then
local control = deviceManager:findByName(device_to_control)
if control == nil then
print("Could not find device: %s", device_to_control)
return
end
control:command("turnoff", nil, "SceneMaster")
print("Turning off device: %s", control:name())
end
end
function onZwaveMessageReceived(device, flags, cmdClass, cmd, data)
if device:name() ~= remotecontrol then
return
end
if cmdClass ~= COMMAND_CLASS_CENTRAL_SCENE or cmd ~= CENTRAL_SCENE_NOTIFICATION then
return
end
if list.len(data) < 3 then
return
end
local sequence = data[0]
local action = data[1]
local scene = data[2]
if debug == true then
print("CENTRAL_SCENE_NOTIFICATION from: %s, Scene: %s, Action: %s", device:name(), scene, action)
end
control(devices[scene], action)
end
Momentan användning av knapp
function scene1(action)
-- FYRKANT START MOMENTAN
if action == KEY_HOLD then
local control = deviceManager:findByName(device1)
if control == nil then
print("Could not find device: %s", device1)
return
end
control:command("turnon", nil, "KeyFob")
print("Turning on device: %s", control:name())
end
-- FYRKANT AVBRYT MOMENTAN
if action == KEY_RELEASE then
local control = deviceManager:findByName(device1)
if control == nil then
print("Could not find device: %s", device1)
return
end
control:command("turnoff", nil, "KeyFob")
print("Turning off device: %s", control:name())
end
end











