LUA - Scener

Hjälp varandra att vara kreativa för att göra hemmet mer bekvämt.
Post Reply
jompa68
Proffsmedlem
Posts: 735
Joined: 12 Aug 2012, 08:53
12
Location: Hofors

Här kommer ni hitta LUA scener som jag använder i mitt system.

Fibaro wallplug som slås av om effekt förbrukningen är mindre än 30watt

Code: Select all

--[[ 
%% properties 
56 valueSensor --(change to your ID)
%% globals 
--]] 
local id = 56 --wallplugg ID(change to your ID)
local wallplug1 = fibaro:getValue(id, "valueSensor") 
local value = 30;  -- 30watt 
local timer = 30 -- seconds

fibaro:debug ("Wallplug consums now: " ..wallplug1.. " watt"); 
if tonumber(wallplug1) < tonumber(value) then 
--protection before autoturn off on start (wait 2s before will check again power and will turn off it) 
fibaro:sleep(2*1000);
  while timer > 0 do 
      timer = timer - 1
    fibaro:debug(timer)
    fibaro:sleep(1000)
   end
  if (timer ==0) then
  	if (tonumber(fibaro:getValue(id, "value")) == 1  and  tonumber(fibaro:getValue(id, "valueSensor")) < tonumber(value)) then 
      fibaro:call(id, "turnOff") 
      fibaro:debug("Low power consumption, turn off wallplug") 
  	end
  end

end
Startar badrumsfläkt om fuktighet är mer än XX %

Code: Select all

--[[
%% autostart
%% properties 
87 value
%% globals 
--]] 
-- Create variable "timerFan"
--87 value = ID of humidity sensor

--Scene purpose 
--IF humidity is over 60%, turnON fan and set it to run in 10minutes

local sceneId = 62 --ID of this scene, used to detect number of instances run 
local timerEndTime = 10 --Minutes to keep the fan turned on after PIR detects movement 

local timer = "timerFan" --Name of global variabel to control the timer 
local timerValue = fibaro:getGlobalValue(timer) --Current value of global variabel for timer 
local humidity = fibaro:getValue(87, "value")
local humValue = "60" -- Humidity threshold in %
local fan = 89 --fan to be controlled by this scene

fibaro:debug("Check of humidity, right now: "..humidity.."%.")
if (humidity > humValue) then --If humidity is over 60, turnON fan
    fibaro:call(fan, "turnOn") --TurnON fan 
    fibaro:setGlobal(timer, timerEndTime) --Set global variabel for timer 
  

  	  while (fibaro:getGlobalValue(timer) ~= "0") do 
      --Loop used to control timer, each loop 1 minute and continues 
      --as long as timer variabel isn't 0 
      timerValue = tonumber(fibaro:getGlobalValue(timer)) --Get current value of global variabel timer 
      fibaro:setGlobal(timer, timerValue-1) --Decrease global variabel for timer with 1 minute 
      fibaro:debug("Fan is on. Timervalue: ".. fibaro:getGlobalValue("timerFan"))   
      fibaro:sleep(60*1000) --Wait 1 minute 
    end 
    fibaro:call(fan, "turnOff") --Turn off 
elseif fibaro:countScenes(sceneId) > 1 then 
    --if scene is already running the set timer to 30 minutes
  fibaro:debug("Already running, sets timer to 10")
  fibaro:setGlobal(timer, timerEndTime) --set global variabel for timer to 5 minutes
  fibaro:debug("Humidity is now: "..humidity.."%")
  fibaro:debug("New instance, totalt = " .. fibaro:countScenes(sceneId)) 
end 
fibaro:debug("End, instances = " .. fibaro:countScenes(sceneId))
fibaro:setGlobal(timer, "0")

Tänder lite lampor om någon kommer hem och det är skymning
Skärmbild som visar variabel
Skärmavbild 2014-01-16 kl. 20.27.47.png
Skärmavbild 2014-01-16 kl. 20.27.47.png (38.93 KiB) Viewed 13042 times

Code: Select all

--[[
%% autostart
%% properties
%% globals
PresentState
TimeOfDay
--]]
-- Skapa fördefinerade variabler PresentState and TimeOfDay
if ( fibaro:getGlobalValue("PresentState") == "Hemma"  and  fibaro:getGlobalValue("TimeOfDay") == "Skymning" ) then
	fibaro:call(137, "turnOn");
	fibaro:call(56, "turnOn");
	fibaro:call(58, "turnOn");
	fibaro:call(200, "turnOn");
	fibaro:call(75, "turnOn");
	fibaro:call(186, "turnOn");
  	fibaro:call(200, "turnOn")

  fibaro:debug("Någon hemma så tänder lite lampor")
else fibaro:debug("Ingen hemma!")
end

Trigga aktivitet på utgång S2 på en dimmer FGD211

Code: Select all

--[[ 
%% properties 
246 sceneActivation 

%% globals 
--]] 

-- Config ------------------------------------------------ 

local hall = {id = 246, virtDev = 214} 

---------------------------------------------------------- 

local trigger = fibaro:getSourceTrigger(); 
if (trigger['type'] ~= "property") then 
  fibaro:debug ("Unexpected source trigger '" .. trigger['type'] .. "'"); 
  fibaro:abort (); 
end 

local id = tonumber (trigger['deviceID']); 
local scene = tonumber (fibaro:getValue (id, "sceneActivation")); 
---------------------------------------------------------- 
if ((id == hall['id']) and (scene == 26)) then -- 1 click
  		fibaro:setGlobal("Hemma", "1") 
		fibaro:debug("S2 -1 click - Hemma")
  
elseif ((id == hall['id']) and (scene == 24)) then -- 2 click
  		fibaro:setGlobal("SleepState", "Sova") 
		fibaro:setGlobal("TimeOfDay", "Natt")
    	        fibaro:debug("S2 -2 click - Sova")
  
elseif ((id == hall['id']) and (scene == 25)) then -- 3 click
  		fibaro:setGlobal("Hemma", "0")
                fibaro:call(hall['virtDev'], "pressButton", "3"); --Skickar push
    	        fibaro:debug("S2 -3 click - Går hemifrån")
end 
---------------------------------------------------------- 


Om någon öppnar ytter dörren och går ut eller närmar sig entredörren utifrån, tänd ytterbelysning

Scene #1

Code: Select all

--[[ 
%% properties 
130 value
98 value
%% globals
--]]

--[[
PIR/DoorSensor Timer
original by jompa68
Modified by jompa68, robmac

 
HISTORY:
1.0.0   original  					                                                        28-07-2013
1.0.1   major improvments, fixes and comments                                        29-07-2013

TO USE:
If PIR or door sensor activites by movement or open doors lights will turnOn
for XX minutes, if movement or doors reopen within clockTimer it will kill running 
scenes and start a new instance of same scene and clockTimer will start from 5
Needs to have a resetScene defined in your HC2 system
--]]

local sceneId = 88 --ID of this scene, used to detect number of instances run
local cancelSceneId = 136 --ID of the cancel scene, 
local resetSceneId = 138 --ID of the reset scene, 
local varValue = fibaro:getGlobalValue("TimeOfDay") -- check variable status. Needs to be created.
local triggerValue = fibaro:getValue(130, "value") --PIR value that activated this scene 
local triggerDoor = fibaro:getValue(98, "value") -- Door sensor
local lights = 134 --light to be controlled by this scene
local clockTimer = 5 --Minutes to keep lights on


 if (fibaro:countScenes(sceneId) > 1) then 
    if (triggerDoor == "1" or triggerValue == "1" and varValue == "Natt") or (triggerDoor == "1" or triggerValue == "1" and varValue == "Morgon") or (triggerDoor == "1" or triggerValue == "1" and varValue == "Skymning") then
      fibaro:debug("Triggered again, will reset timer")
      fibaro:startScene(resetSceneId); -- kill the running instance that is sleeping
      	end 
     -- should not get here but if we do just quit
      fibaro:abort() 
elseif varValue == "Morgon" or varValue == "Skymning" or varValue == "Natt" then
	if triggerDoor == "1" or triggerValue == "1" then 
  		--Announce start 
		fibaro:debug(" -|- Start: "..os.date("%Y-%m-%d %H:%M:%S",os.time())) 
		fibaro:call(lights, "turnOn") 
    	fibaro:debug(" -|- Sensor activated:  clockTimer = " .. clockTimer.."min") 
    	fibaro:sleep(60 * 1000 * clockTimer) -- Wait so variable is set 
  		fibaro:call(lights, "turnOff")
    	fibaro:debug(" -|- Nothing triggered, turnOff lights")
    	fibaro:debug(" -|- End: "..os.date("%Y-%m-%d %H:%M:%S",os.time())) 
 	end
end 

Scene #2

Code: Select all

--[[
%% properties

%% globals
--]]
local sceneControlID = 88
while (fibaro:countScenes(sceneControlID) > 0) do 
 
    fibaro:killScenes(sceneControlID); -- Does this kill the running instance that is sleeping?

end; 
--restart the main scene that will run for 5 more minutes
fibaro:startScene(sceneControlID);
Väder prognos som Push meddelande

Code: Select all

Kommer visas här
Hämta värde ur RSS och visa på virtuell enhet

Code: Select all

Kommer visas här
Visa elförbruknings info från en Aeon Labs Energy Meter
Skärmavbild 2014-01-17 kl. 06.11.00.png
Skärmavbild 2014-01-17 kl. 06.11.00.png (33.49 KiB) Viewed 13010 times

Code: Select all

Kommer visas här
Varna vid låg batteri nivå på alla enheter med batteri källa
Använder ikonerna som finns här: viewtopic.php?f=21&t=4134

Code: Select all

--[[
%% properties
%% globals
--]]

function getIcon(lowest)
  if (lowest >= 90) then return 1070
  elseif (lowest >= 40) then return 1071
  elseif (lowest >= 20) then return 1072
  else return 1073 end
end

local isBatteryOperated = "1"
local minbattLevel = 15 --alarm level!
local i = 0 
local maxNodeID = 500
local lowest = 100
local name

local flag = 0


for i = 0, maxNodeID do 
local type = fibaro:get (i, 'isBatteryOperated'); 
      x , y = string.find (type, isBatteryOperated ) 
        if x ~= nill 
            then 
            name = fibaro:getName(i)
    		batterylevel = fibaro:getValue (i, 'batteryLevel')
    		    if tonumber(batterylevel) == 255 then 
        			batterylevel = 10
        		end
    			if lowest > tonumber(batterylevel) then
        			lowest = tonumber(batterylevel)
         		end
            fibaro:debug("ID = "..i..", Namn:"..name.."\t - \t batteri nivå: "..batterylevel.."%") 
	
    		if tonumber(batterylevel) <= minbattLevel then

      			flag = 1
       			fibaro:call(240, 'setProperty', 'ui.Battery.value',"Lågt batteri: " ..name.." "..batterylevel.."%")
        		fibaro:debug("Låg batteri nivå på ID:"..i.." Namn:"..name.." "..batterylevel.."%")
      			--fibaro:call(229, "sendPush", "Låg batteri nivå på \n "..name.." ID:"..i.." - "..batterylevel.."%")
    			elseif flag == 0 then
      				fibaro:call(240, 'setProperty', 'ui.Battery.value',"Allt ok. Lägsta: " ..lowest .."%")  
					fibaro:call(240, "setProperty", "currentIcon", getIcon(lowest));
    		end

    		fibaro:call(240, "setProperty", "currentIcon", getIcon(lowest));
    	end 
end 
Post Reply