Hallo Valle,
welche Version der Szene setzt Du ein? Aktuell ist die v0.5. Dort habe ich an genau dieser Stelle noch Änderungen eingefügt.
Für alle Andere die es interessiert hier die Szene zur Änderung des Heizplanes an Feiertagen:
--[[
%% autostart
%% properties
%% globals
--]]
---------------------------------------------------
--------- Verwendung ------------------------------
--[[
Anpassung des Heizplanes wenn heute ein Feiertag ist
Die Heizpläne aller Räume werden manuell auf den Heizplan
für Sonntags gesetzt.
Trigger: Timer der alle x Minuten checkt ob ein Feiertag ist
--]]
---------------------------------------------------
--------- Schleifenschutz -------------------------
if (fibaro:countScenes()>1) then
fibaro:debug('Kill the second scene!');
fibaro:abort();
end
---------------------------------------------------
------------- Config ------------------------------
timer = 10 -- Zeitfenster in dem neu geprüft werden soll
gHoliday = 'holidayToday'
advDebug = true
advDebugTime = false
version = 'v0.5'
---------------------------------------------------
--------- Farbiges Debug --------------------------
function debug( color, message )
fibaro:debug(string.format('<%s style="color:%s;">%s<!--%s-->', "span", color, message, "span"));
end
---------------------------------------------------
------------- HTTP GET ----------------------------
-- GET zum Auslesen des Heizplanel
---------------------------------------------------
local function getMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
http:request(requestUrl, {
options = {
method = 'GET'
},
success = successCallback,
error = errorCallback
})
end
---------------------------------------------------
------------- HTTP PUT ----------------------------
-- PUT zum Senden an das Heizplanel
---------------------------------------------------
local function putMethod(requestUrl, data, successCallback, errorCallback)
local http = net.HTTPClient()
http:request(requestUrl, {
options = {
method = 'PUT',
data = json.encode(data)
},
success = successCallback,
error = errorCallback
})
end
---------------------------------------------------
------------- getHeatPlanIDs ---------------------
-- HTTP Befehle zum Abrufen der Heizplan IDs
---------------------------------------------------
function getHeatPlanIDs()
url = 'http://127.0.0.1:11111/api/panels/heating'
getMethod(url,
function(resp)
if resp.status == 200 then
debug('green','Abrufen der Heizplan IDs erfolgreich (HTTP Status ' .. resp.status .. ')')
local panel = json.decode(resp.data)
-- Heizplan IDs auslesen
heatingRooms = {}
for i = 1, #panel do
setHolidayHeatplan(panel[i].id)
end
else
debug('red','Verbindung konnte nicht hergestellt werden (HTTP Status ' .. resp.status .. ')')
end
end,
function(err)
debug('red','error ' .. err)
end
)
end
---------------------------------------------------
------------- setHandModeTrue ---------------------
-- HTTP Befehle zum aktivieren des manuellen Modus
---------------------------------------------------
local function setHandModeTrue(subjectToChange)
local url = 'http://127.0.0.1:11111/api/panels/heating/' .. subjectToChange.id
local handTime = os.time() + (timer * 60) + 10
getMethod(url, function(resp)
if resp.status == 200 then
debug('green','Verbindung zum Heizpanel erfolgreich (HTTP Status ' .. resp.status .. ')')
local panel = json.decode(resp.data)
if panel.properties.handTemperature ~= nil then
panel.properties.handTemperature = subjectToChange.manTemp
panel.properties.handTimestamp = handTime
putMethod(url, panel, function(resp)
end,
function(err)
debug('red','Error ' .. err)
end
)
else
debug('red','Panel nicht gefunden')
end
else
debug('red','Verbindung konnte nicht hergestellt werden (HTTP Status ' .. resp.status .. ')')
end
end,
function(err)
debug('red','error ' .. err)
end
)
end
---------------------------------------------------
------------- stime -------------------------------
-- Funktion zum Umrechnen von Uhrzeiten in Sekunden
-- seit 0 Uhr
---------------------------------------------------
function stime(s)
local pattern = "(%d+):(%d+)"
local hours, minutes, seconds = string.match(s, pattern)
return (hours*3600)+(minutes*60)
end
---------------------------------------------------
------------- getSundayHeatingTable ---------------------
-- Auslesen der Sollwerte aus dem Heizplan
-- Parameter 1: Array für Sonntag
-- Parameter 2: Array füt Samstag
---------------------------------------------------
function getSundayHeatingTable(heatingTable, heatingTableLast)
heatingPeriods = {}
heatingPeriods.beforeMorningTemp = heatingTableLast.night.temperature
heatingPeriods.startMorning = stime(tostring(heatingTable.morning.hour)..':'..tostring(heatingTable.morning.minute))
heatingPeriods.MorningTemp = heatingTable.morning.temperature
heatingPeriods.startDay = stime(tostring(heatingTable.day.hour)..':'..tostring(heatingTable.day.minute))
heatingPeriods.DayTemp = heatingTable.day.temperature
heatingPeriods.startEvening = stime(tostring(heatingTable.evening.hour)..':'..tostring(heatingTable.evening.minute))
heatingPeriods.EveningTemp = heatingTable.evening.temperature
heatingPeriods.startNight = stime(tostring(heatingTable.night.hour)..':'..tostring(heatingTable.night.minute))
heatingPeriods.NightTemp = heatingTable.night.temperature
currentSeconds = stime(tostring(currentDate.hour)..':'..tostring(currentDate.min)) + currentDate.sec
secondsUntilMidnight = stime('23:59:59') - currentSeconds
if currentSeconds <= heatingPeriods.startMorning then -- Vor Morning
heatingTarget = heatingPeriods.beforeMorningTemp
heatingPhase = 'Nacht'
heatingPhaseRem = heatingPeriods.startMorning - currentSeconds
if advDebugTime then debug('red',heatingPhase) end
if advDebugTime then debug('yellow',currentSeconds..'<'..heatingPeriods.startMorning) end
elseif currentSeconds <= heatingPeriods.startDay then -- Morning
heatingTarget = heatingPeriods.MorningTemp
heatingPhase = 'Morgen'
heatingPhaseRem = heatingPeriods.startDay - currentSeconds
if advDebugTime then debug('red',heatingPhase) end
if advDebugTime then debug('yellow',currentSeconds..'<='..heatingPeriods.startDay) end
elseif currentSeconds <= heatingPeriods.startEvening then -- Day
heatingTarget = heatingPeriods.DayTemp
heatingPhase = 'Tag'
heatingPhaseRem = heatingPeriods.startEvening - currentSeconds
if advDebugTime then debug('red',heatingPhase) end
if advDebugTime then debug('yellow',currentSeconds..'<='..heatingPeriods.startEvening) end
elseif currentSeconds <= heatingPeriods.startNight then -- Evening
heatingTarget = heatingPeriods.EveningTemp
heatingPhase = 'Abend'
if advDebugTime then debug('red',heatingPhase) end
if advDebugTime then debug('yellow',currentSeconds..'<='..heatingPeriods.startNight) end
elseif currentSeconds >= heatingPeriods.startNight then -- Night
heatingTarget = heatingPeriods.NightTemp
heatingPhase = 'Nacht'
heatingPhaseRem = secondsUntilMidnight
if advDebugTime then debug('red',heatingPhase) end
if advDebugTime then debug('yellow',currentSeconds..'>='..heatingPeriods.startNight) end
end
end
---------------------------------------------------
------------- setHolidayHeatplan -------------------
-- HTTP Befehle zum setzen des manuellen Feiertagplans
---------------------------------------------------
function setHolidayHeatplan(heatingRooms)
local url = 'http://127.0.0.1:11111/api/panels/heating/' .. heatingRooms
local currentTime = os.time()
getMethod(url,
function(resp)
if resp.status == 200 then
local panel = json.decode(resp.data)
heatingId = panel.id
heatingName = panel.name
heatingDetails = json.encode(panel.properties)
heatingDetailsSat = panel.properties.saturday
heatingDetailsSun = panel.properties.sunday
getSundayHeatingTable(heatingDetailsSun,heatingDetailsSat)
debug("yellow","Solltemperatur für Raum "..heatingName.." "..heatingTarget.."°C")
local setManual = {
id = heatingRooms,
manTemp = heatingTarget
}
--Set Handmode
--Keine Änderung wenn bereits eine andere manuelle Änderung vorgenommen wurde
if panel.properties.handTemperature ~= heatingTarget and panel.properties.handTimestamp > currentTime
then
fibaro:debug('Manuelle temperature eingestellt. Keine Änderung')
else
setHandModeTrue(setManual)
end
else
debug('red','Verbindung konnte nicht hergestellt werden (HTTP Status ' .. resp.status .. ')')
end
end,
function(err)
debug('red','error ' .. err)
end
)
end
function timerFunction()
currentDate = os.date("*t");
weekday = os.date("%A")
holidayToday = fibaro:getGlobal(gHoliday)
debug("green","------------ Prüfe Feiertagsvariable")
if ( holidayToday == '1') then
if (weekday == 'Sunday') then
debug('yellow','Heute ist zwar ein Feiertag, aber es ist Sonntag, daher erfolgt keine Änderung.')
else
debug('yellow','Heute ist ein Feiertag. Es wird der Heizplan für Sonntag übernommen')
getHeatPlanIDs()
end
else
debug('green','Heute ist kein Feiertag.')
end
setTimeout(timerFunction, timer*60*1000)
end
debug("green","--------------------START--------------------------------")
debug("green","------------ Heizpläne an Feiertagen ------------")
debug("green","------------------------------------------------------------")
timerFunction()