Page 1 of 1

Variable fails in Code

Posted: Tuesday 07 May 2019 14:23
by Opus
Hi,
a short code and my big problem. I use the variable 'stufe' for memory the step of thunderstorm levels. I get the 4 levels as bit code from 2 switches, connected to a lighning sensor.
If the Ligntning approaching the messages are warnings, downwards changed to 'departure'.
But the variable 'stufe' falls everytime back to '0' between the steps. In that case the code will never work.
How may I store the value of stufe in a secure methode?

Code: Select all


--
Gewitter = 'AUS'
local stufe =0
gemeldet = 0
debug = 1

commandArray = {}

 --if (gemeldet == nil) then gemeldet = 0 end
 --if (stufe == nil) then stufe = 5 end
 --if (Gewitter == nil) then Gewitter = 'AUS' end

-- Set value of Gewitter AUS, GRÜN, GELB, ROT from bit code:
if     (otherdevices['Gewitter Bit 0'] == "On") and (otherdevices['Gewitter Bit 1'] == "On") then Gewitter = 'AUS'
elseif (otherdevices['Gewitter Bit 0'] == "Off") and (otherdevices['Gewitter Bit 1'] == "On") then Gewitter = 'GRÜN'
elseif (otherdevices['Gewitter Bit 0'] == "On")  and (otherdevices['Gewitter Bit 1'] == "Off") then Gewitter = 'GELB'    
elseif (otherdevices['Gewitter Bit 0'] == "Off") and (otherdevices['Gewitter Bit 1'] == "Off") then Gewitter = 'ROT'
end


if (Gewitter =='AUS') and (gemeldet == 0) then
    commandArray['UpdateDevice'] = "685|0|Keine Wetterwarnung"
    stufe = 0
    gemeldet = 1
    end
if (Gewitter == 'AUS') and (stufe == 1) then
    commandArray['UpdateDevice'] = "685|0|Gewitter sind abgezogen"  
    stufe = 0
    end

if (Gewitter == 'GRÜN') and (stufe == 0) then
    commandArray['UpdateDevice'] = "685|0|Wetterwarnung: Kommende Gewitter in 30-100 km Entfernung!"         
    stufe = 1
    end
if (Gewitter == 'GRÜN') and (stufe == 2) then
    commandArray['UpdateDevice'] = "685|0|Abziehendes Gewitter in ca. 30km Entfernung!"  
    stufe = 1
    end

if (Gewitter == 'GELB') and (stufe == 1) then
    stufe = 2
    commandArray['UpdateDevice'] = "685|0|Wetterwarnung: Kommende Gewitter in ca. 10km Entfernung!"         
    commandArray['Markise'] = 'On'
    end
if (Gewitter == 'GELB') and (stufe == 3) then
    commandArray['UpdateDevice'] = "685|0|Abziehendes Gewitter in ca. 10km Entfernung!"  
    stufe = 2
    end


if (Gewitter == 'ROT') and (stufe ==2) then
    commandArray['UpdateDevice'] = "685|0|Wetterwarnung: Örtlich wirkendes Gewitter!!!"         
    commandArray['SendNotification']='Lokales Gewitter!!!'         -- Meldung an Handys 
    commandArray['Markise'] = 'On'
    stufe = 3
    end  

if (debug == 1) then
--print ('gemeldet:'..tostring(gemeldet))
--print ('stufe:'..tostring(stufe))
--print ('Gewitter:'..tostring(Gewitter))
end



return commandArray