LUA Fehler beim Debuggen - Rollladensteuerung lichtabhängig

Moin allerseits,
ich hoffe, ich finde hier die Experten, die einem Neuling in Lua auf die Sprünge helfen können. Meine bisherige Steuerung basiert auf HC2, auf welches ich über einen Mac zugreife. Es handelt sich um ein Einfamilienhaus mit allerhand Sensoren und Aktuatoren, für welche ich die Szenen bisher nur über magic und/oder grafik erstellt habe.
Nun will ich die Rollläden schließen, wenn die Lichtintensität zu hoch ist und habe dafür eine entsprechende Szene gesucht und hoffentlich auch gefunden. Leider kommt es zu Fehlermeldungen, wenn ich den Lua Code stumpf von der Quelle kopiere und die Anweisungen aber befolgt habe. Vllt hat ja jemand Tips hier…
Der code stammt von einer Internetseite über Drohnen, siehe:

Die Idee / der Plan:
** die Rollos sollen automatisch herunterfahren, wenn die Sonne zu stark scheint. Und wieder hoch, wenn die Sonne weg ist

** damit dies nicht andauernd passiert, müssen die Zustände (zu hell – oder lang genug wieder dunkel) mindestens für eine Gewisse Zeit anliegen. In unserem Beispiel: Die Sonne muss mindestens 5 Minuten hell genug scheinen, damit die Jalousien runter fahren – und mindestens 20 Minuten genügend abgedunkelt bleiben, damit diese wieder hoch fahren*
** das Runterfahren oder Hochfahren soll nicht nachts passieren, wenn die Rollos sowieso unten sind*

Hier der LUA-Code dazu – einige kleine Anpassungen (besonders die Geräte IDs) müssen individuell vorgenommen werden. Nötige Anpassungen:

  • Zeile 22 und Zeile 4 muss die 7 gegen die ID des eigenen Helligkeitssensors (Fibaro Motion Sensor) ausgetauscht werden.
  • Es müssen die beiden globalen Variablen SunFirstMax und SunFirstMin mit dem Wert 0 angelegt werden. Diese beinhalten den Zeitstempel, an dem oben genannte Bedingungen erstmals eingetreten sind
  • Es muss eine globale Variable RolloNightDown angelegt werden, die den Wert 1 bekommt, wenn die Rollos nachts heruntergefahren wurden und 0, wenn die Rollos für den Tag hochgefahren wurden
  • Die Zeiten 12-15 können angepasst werden auf Wunsch (Schwellwerte und Zeiten)
  • In Zeile 94-108 müssen noch die IDs der Rolläden-Module sowie die gewünschten Werte für die Position der Beschattung eingetragen werden
    –[[
    %% autostart
    %% properties
    7 value
    %% globals
    –]]local startSource = fibaro:getSourceTrigger();function tempFunc()
    if (tonumber(fibaro:getGlobalValue(„RolloNightDown“)) ~= tonumber(„1“) ) then
    local startSunLux = 25000; — über 10.000 Lux für zu
    local startSunDelay = 300; — 5 Min bis zu
    local endSunLux = 8000; — unter 8000 Lux für auf
    local endSunDelay = 1200; — 20 Min bis auf
    local gSunFirstMax = (fibaro:getGlobal(„SunFirstMax“));
    local gSunFirstMin = (fibaro:getGlobal(„SunFirstMin“));
    — gSunFirstMaxTime = tonumber(gSunFirstMaxTime)
    gSunFirstMaxTime = fibaro:getGlobalModificationTime(„SunFirstMax“);
    gSunFirstMinTime = fibaro:getGlobalModificationTime(„SunFirstMin“);
    — gSunFirstMinTime = tonumber(gSunFirstMinTime);
    local currentLux = tonumber(fibaro:getValue(7, „value“));–currentLux = 17000; — nur für Debug !!fibaro:debug(„— Current Lux: “ … currentLux … “ RolloDown: “ … fibaro:getGlobalValue(„RolloSunDown“) … “ parallele Szenen: “ … fibaro:countScenes() … “ —„);

if ( currentLux >= startSunLux and fibaro:getGlobalValue(„RolloSunDown“) ~= ‚1‘) then
if (gSunFirstMaxTime == 0 or gSunFirstMaxTime == nil or gSunFirstMax == ‚0‘) then
fibaro:setGlobal(„SunFirstMax“,currentLux);
fibaro:debug(„New Max Timestamp (Down)“);
setTimeout(tempFunc, startSunDelay*1000) — sicherheitshalber diese Szene / Funktion schonmal für zukünftigen Zeitpunkt aufrufen, falls es da dann keinen Trigger gibt
elseif (os.time() – gSunFirstMaxTime >= startSunDelay ) then

fibaro:call(118, „setValue“, „45“);
fibaro:call(120, „setValue“, „45“);
fibaro:call(116, „setValue“, „45“);
fibaro:call(114, „setValue“, „45“);

fibaro:debug(„*** Aktion: ZU nach “ … os.time() – gSunFirstMaxTime);
fibaro:setGlobal(„RolloSunDown“,1);
else
fibaro:debug(„Restzeit bis zu “ … os.time() – gSunFirstMaxTime – startSunDelay);
end
else
fibaro:setGlobal(„SunFirstMax“,0);
fibaro:debug(„RolloDown Restzeit reset“);
end

if ( currentLux <= endSunLux and fibaro:getGlobalValue(„RolloSunDown“) == ‚1‘) then if (gSunFirstMinTime == 0 or gSunFirstMinTime == nil or gSunFirstMin ==’0′) then
fibaro:setGlobal(„SunFirstMin“, currentLux); fibaro:debug(„New Min Timestamp (Up)“); setTimeout(tempFunc, endSunDelay*1000) — sicherheitshalber diese Szene / Funktion schonmal für zukünftigen Zeitpunkt aufrufen, falls es da dann keinen Trigger gibt elseif (os.time() – gSunFirstMinTime >= endSunDelay) then

fibaro:call(114, „open“);
fibaro:call(116, „open“);
fibaro:call(118, „open“);
fibaro:call(120, „open“);

fibaro:debug(„*** Aktion: AUF nach “ … os.time() – gSunFirstMinTime);
fibaro:setGlobal(„RolloSunDown“,0);
else
fibaro:debug(„Restzeit bis auf “ … os.time() – gSunFirstMinTime – endSunDelay);
end
else
fibaro:setGlobal(„SunFirstMin“,0);
fibaro:debug(„RolloUp Restzeit reset“);
end
else
fibaro:debug(„Nachtabschaltung“);
end
end

if ( startSource[„type“] == „other“ ) then
— manueller Start der Szene
if (fibaro:getGlobalValue(„RolloSunDown“) == ‚1‘) then
fibaro:debug(„Manuelles sofortiges Öffnen…“);
fibaro:call(114, „open“);
fibaro:call(116, „open“);
fibaro:call(118, „open“);
fibaro:call(120, „open“);
fibaro:setGlobal(„RolloSunDown“,0);
else
fibaro:debug(„Manueller sofortiger Sonnenschutz…“);
fibaro:call(118, „setValue“, „45“);
fibaro:call(120, „setValue“, „45“);
fibaro:call(116, „setValue“, „45“);
fibaro:call(114, „setValue“, „45“);

fibaro:setGlobal(„RolloSunDown“,1);
end
else
— automatischer Lauf
fibaro:debug(„Scene läuft… „);
tempFunc();
end

Die 1. Fehlermeldung ist die folgende:
[DEBUG] 17:46:35: 2025-06-05 17:46:35.371371 [ fatal] Unknown exception: /opt/fibaro/scenes/95.lua:8: unexpected symbol near char(226)

Bitte mal alle “ durch ‘ ersetzen.

Siehe hier.
https://stackoverflow.com/questions/41588317/running-lua-file-unexpected-symbol-near-char226

LG


Moin,
ich ändere das mal entsprechend auch für das unter anführungszeichen, d.h. es gilt auch für „ ?

OK,
hab das nun entsprechend geändert. Nun gibt es eine weitere Fehlermeldung, dieses Mal offensichtlich in Zeile 9…

[DEBUG] 15:28:44: 2025-06-10 15:28:44.544088 [ fatal] Unknown exception: /opt/fibaro/scenes/95.lua:9: unexpected symbol near char(226)

Der Einfacheit halber hier nochmal die Zeile 9…

local startSunLux = 25000; — über 10.000 Lux für zu

Viele Grüße

ps.: habe eben mal die ü durch ue ersetzt, ändert aber nichts an der Fehlermeldung

Ich nochmal…
hab das Ganze nun mit Gemini gelöst, kann ich nur empfehlen!

Hier nochmal der korrigierte code:–[[
%% autostart
%% properties
7 value
%% globals
–]]
local startSource = fibaro:getSourceTrigger()

function tempFunc()
if (tonumber(fibaro:getGlobalValue(‚RolloNightDown‘)) ~= 1) then
local startSunLux = 25000
local startSunDelay = 300
local endSunLux = 8000
local endSunDelay = 1200

    local gSunFirstMax = fibaro:getGlobalValue('SunFirstMax')
    local gSunFirstMin = fibaro:getGlobalValue('SunFirstMin')

    gSunFirstMaxTime = fibaro:getGlobalModificationTime('SunFirstMax')
    gSunFirstMinTime = fibaro:getGlobalModificationTime('SunFirstMin')

    local rawLuxValue = fibaro:getValue(7, 'value')
    local currentLux = tonumber(rawLuxValue)

    -- *** ERROR HANDLING FOR CURRENTLUX ***
    if currentLux == nil then
        fibaro:debug('ERROR: Could not get valid Lux value from device 7. Raw value: ' .. tostring(rawLuxValue))
        -- Optionally, you can stop the function here if the Lux value is critical
        return -- Exit the function if lux is not available
    end
    -- ************************************

    local rolloSunDownStatus = fibaro:getGlobalValue('RolloSunDown') or 'N/A' -- Provide a default if nil
    local sceneCount = fibaro:countScenes() or 0 -- Provide a default if nil

    fibaro:debug('--- Current Lux: ' .. currentLux .. ' RolloDown: ' .. rolloSunDownStatus .. ' parallele Szenen: ' .. sceneCount .. ' ---')

    if (currentLux >= startSunLux and rolloSunDownStatus ~= '1') then
        if (gSunFirstMaxTime == 0 or gSunFirstMaxTime == nil or tonumber(gSunFirstMax) == 0) then
            fibaro:setGlobal('SunFirstMax', 0)
            fibaro:debug('New Max Timestamp (Down)')
            setTimeout(tempFunc, startSunDelay * 1000)
        elseif (os.time() - gSunFirstMaxTime >= startSunDelay) then
            fibaro:call(118, 'setValue', 45)
            fibaro:call(120, 'setValue', 45)
            fibaro:call(116, 'setValue', 45)
            fibaro:call(114, 'setValue', 45)

            fibaro:debug('*** Aktion: ZU nach ' .. tostring(os.time() - gSunFirstMaxTime)) -- Use tostring for robustness
            fibaro:setGlobal('RolloSunDown', 1)
        else
            fibaro:debug('Restzeit bis zu ' .. tostring(startSunDelay - (os.time() - gSunFirstMaxTime))) -- Use tostring for robustness
        end
    else
        fibaro:setGlobal('SunFirstMax', 0)
        fibaro:debug('RolloDown Restzeit reset')
    end

    if (currentLux <= endSunLux and rolloSunDownStatus == '1') then
        if (gSunFirstMinTime == 0 or gSunFirstMinTime == nil or tonumber(gSunFirstMin) == 0) then
            fibaro:setGlobal('SunFirstMin', 0)
            fibaro:debug('New Min Timestamp (Up)')
            setTimeout(tempFunc, endSunDelay * 1000)
        elseif (os.time() - gSunFirstMinTime >= endSunDelay) then
            fibaro:call(114, 'open')
            fibaro:call(116, 'open')
            fibaro:call(118, 'open')
            fibaro:call(120, 'open')

            fibaro:debug('*** Aktion: AUF nach ' .. tostring(os.time() - gSunFirstMinTime)) -- Use tostring for robustness
            fibaro:setGlobal('RolloSunDown', 0)
        else
            fibaro:debug('Restzeit bis auf ' .. tostring(endSunDelay - (os.time() - gSunFirstMinTime))) -- Use tostring for robustness
        end
    else
        fibaro:setGlobal('SunFirstMin', 0)
        fibaro:debug('RolloUp Restzeit reset')
    end
else
    fibaro:debug('Nachtabschaltung')
end

end

if (startSource[‚type‘] == ‚other‘) then
if (fibaro:getGlobalValue(‚RolloSunDown‘) == ‚1‘) then
fibaro:debug(‚Manuelles sofortiges Öffnen…‘)
fibaro:call(114, ‚open‘)
fibaro:call(116, ‚open‘)
fibaro:call(118, ‚open‘)
fibaro:call(120, ‚open‘)
fibaro:setGlobal(‚RolloSunDown‘, 0)
else
fibaro:debug(‚Manueller sofortiger Sonnenschutz…‘)
fibaro:call(118, ‚setValue‘, 45)
fibaro:call(120, ‚setValue‘, 45)
fibaro:call(116, ‚setValue‘, 45)
fibaro:call(114, ‚setValue‘, 45)

    fibaro:setGlobal('RolloSunDown', 1)
end

else
fibaro:debug('Scene läuft… ')
tempFunc()
end