Ris, ros och kommentarer mottages gärna.
Code: Select all
--[[
%% properties
15 power
%% events
%% globals
--]]
-- Name of the appliance and parameter that report watts
local idAppliance = 15
local applianceParameter = "power"
-- You need to change to this id and param in the trigger-section at the top
-- Max/Min values
local wattRunning = 200
local wattStandby = 10
-- Minimum seconds to be in standby-state before sending push
local minSeconds = 300
-- Predefined variable with two values (needs to be created)
local statusVarName = "Tvattmaskin"
local statusVarValRunning = "Startad"
local statusVarValDone = "Klar"
-- Push messages to phone (needs to be created)
local idPush = {4}
local pushMessageID = "TvattmaskinKlar"
-- Extra variable (for other Push-messages), set ExtraVariable to "" to disable
local ExtraVariable = "Pushover"
local ExtraString = "Tvättmaskinen är klar;iPhone;1;echo"
-- Show debug text or not
local doDebug = true
-- =============================================================================
msgDebug = function (color, message)
if doDebug then
fibaro:debug("<span style='color: " .. color .. "'>" .. message .. "</span>")
end
end
if (fibaro:countScenes() > 1) then
msgDebug("Red", "Allready running - Aborting!")
fibaro:abort()
end
local pwrAppliance = fibaro:getValue(idAppliance, applianceParameter)
local secondsSinceUpdate = os.time() - fibaro:getGlobalModificationTime(statusVarName)
msgDebug("Gray", "Using " .. pwrAppliance .. " watts, status is " .. fibaro:getGlobal(statusVarName) .. " the last " .. tostring(secondsSinceUpdate) .. " seconds")
if (tonumber(pwrAppliance) > wattRunning) then
msgDebug("Yellow", "Usage is " .. pwrAppliance .. " watts, settings status to " .. statusVarValRunning)
fibaro:setGlobal(statusVarName, statusVarValRunning);
elseif ( (tonumber(pwrAppliance) < wattStandby) and (fibaro:getGlobal(statusVarName) ~= statusVarValDone) ) then
if (secondsSinceUpdate > minSeconds) then
msgDebug("White", "Usage below " .. wattStandby .. " watts for " .. tostring(secondsSinceUpdate) .. " seconds")
if (fibaro:getGlobal(statusVarName) == statusVarValRunning) then
msgDebug("Green", "State is " .. statusVarValRunning .. " and usage is below " .. tostring(wattStandby) .. " for more than " .. tostring(minSeconds) .. " seconds")
for loop,Push in pairs(idPush) do
msgDebug("Green", "Sending push message " .. tostring(pushMessageID) .. " to devcie " .. tostring(Push))
fibaro:call(Push, "sendDefinedPushNotification", pushMessageID)
end
if (string.len(ExtraVariable) > 1) then
msgDebug("Green", "Setting variable '" .. ExtraVariable .. "' = '" .. ExtraString .. "'")
fibaro:setGlobal(ExtraVariable,ExtraString)
end
msgDebug("Yellow", "Setting state to " .. statusVarValDone)
fibaro:setGlobal(statusVarName, statusVarValDone);
end
else
msgDebug("Orange", "To few seconds (prevent flapping and spamming)")
end
end
-- =============================================================================