Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- t = os.date("*t")
- commandArray = {}
- m_testmodus = false
- function isVeranderingIemandThuis()
- local a = devicechanged["IemandThuis"] == "On" or devicechanged["IemandThuis"] == "Off"
- return a
- end
- function isVeranderingDonkerBinnen()
- local a = devicechanged["DonkerBinnen"] == "On" or devicechanged["DonkerBinnen"] == "Off"
- return a
- end
- function isVeranderingDonker()
- local a = devicechanged["Donker"] == "On" or devicechanged["Donker"] == "Off"
- return a
- end
- function isVeranderingBedtijd()
- local a = devicechanged["Bedtijd"] == "On" or devicechanged["Bedtijd"] == "Off"
- return a
- end
- function scriptMagWordenUitgevoerd()
- local a, b, c, d, e = false, false, false, false
- if (devicechanged ~= nil) then
- a = isVeranderingDonker()
- b = isVeranderingDonkerBinnen()
- c = isVeranderingBedtijd()
- d = isVeranderingIemandThuis()
- else
- e = true
- end
- print('scriptMagWordenUitgevoerd() A: '..tostring(a)..' B: '..tostring(b)..' C: '..tostring(c)..' D: '..tostring(d))
- return a or b or c or d
- end
- if (scriptMagWordenUitgevoerd() == false) then
- print('Geen geldige input voor script. Afgebroken.')
- return commandArray
- end
- -- enums
- local VerlichtingUitgeschakeld, NietThuisStand, VerlichtingIngeschakeld, Ongedefinieerd = 0, 1, 2, 3
- function toToestandString(toestand)
- if (toestand == VerlichtingUitgeschakeld) then
- return "Toestand: Verlichting Uitgeschakeld"
- elseif (toestand == NietThuisStand) then
- return "Toestand: Niet thuis"
- elseif (toestand == VerlichtingIngeschakeld) then
- return "Toestand: Verlichting Ingeschakeld"
- elseif (toestand == Ongedefinieerd) then
- return "Toestand: Ongedefinieerd"
- end
- end
- function iemandThuis()
- a = devicechanged ~= nil and devicechanged["IemandThuis"] == "On"
- b = otherdevices["IemandThuis"] == "On"
- print('iemandThuis() C: '..tostring(a)..' O: '..tostring(b))
- return a or b
- end
- -- Controleer of uitschakelen van de verlichting is toegestaan
- function isUitschakelenToegestaan()
- local a = devicechanged ~= nil and devicechanged["DonkerBinnen"] == "Off"
- local b = isVeranderingIemandThuis() == true and iemandThuis() == false
- local c = devicechanged ~= nil and devicechanged["Bedtijd"] == "On"
- print('isUitschakelenToegestaan() A: '..tostring(a)..' B: '..tostring(b)..' C: '..tostring(c))
- return a or b or c
- end
- function isInschakelenToegestaan()
- local a = devicechanged ~= nil and devicechanged["DonkerBinnen"] == "On"
- local b = isVeranderingIemandThuis() == true and iemandThuis() == true
- local c = devicechanged ~= nil and devicechanged["Bedtijd"] == "Off"
- print('isInschakelenToegestaan() A: '..tostring(a)..' B: '..tostring(b)..' C: '..tostring(c))
- return a or b or c
- end
- function isHetDonkerBinnen()
- local a = devicechanged ~= nil and devicechanged["DonkerBinnen"] == "On"
- local b = otherdevices["DonkerBinnen"] == "On"
- print('isHetDonkerBinnen() A: '..tostring(a)..' B: '..tostring(b))
- return a or b
- end
- function bepaalHuidigeToestand()
- for i, v in pairs(otherdevices) do print(i, v) end
- if (
- otherdevices["Staande lamp bank rechts"] == "Off" and
- otherdevices["Staande lamp bank links"] == "Off" and
- otherdevices["Staande lamp dressoir links"] == "Off" and
- otherdevices["Lamp dressoir rechts"] == "Off"
- ) then
- return VerlichtingUitgeschakeld
- elseif (
- otherdevices["Staande lamp bank rechts"] == "On" and
- otherdevices["Staande lamp bank links"] == "On" and
- otherdevices["Staande lamp dressoir links"] == "On"
- -- and
- -- otherdevices["Lamp dressoir rechts"] == "On"
- ) then
- return VerlichtingIngeschakeld
- elseif (
- otherdevices["Staande lamp bank rechts"] == "On" and
- otherdevices["Staande lamp bank links"] == "Off" and
- otherdevices["Staande lamp dressoir links"] == "On" and
- otherdevices["Lamp dressoir rechts"] == "Off"
- ) then
- return NietThuisStand
- end
- return Ongedefinieerd
- end
- function isOvergangToegestaan(van, naar)
- local a = naar == VerlichtingIngeschakeld and m_maglichtinschakelen == true
- local b = naar == VerlichtingUitgeschakeld and m_maglichtuitschakelen == true
- local c = naar == NietThuisStand
- print('isOvergangToegestaan() A: '..tostring(a)..' B: '..tostring(b)..'C: '..tostring(c))
- return a or b or c
- end
- function stelToestandIn(naar)
- print(toToestandString(naar)..' wordt ingesteld.')
- if (m_testmodus == true) then
- return false
- end
- if (naar == VerlichtingIngeschakeld) then
- commandArray["Group:Woonkamer"] = "On"
- elseif (naar == VerlichtingUitgeschakeld) then
- commandArray["Group:Woonkamer"] = "Off"
- elseif (naar == NietThuisStand) then
- commandArray["Staande lamp bank rechts"] = "On"
- commandArray["Staande lamp bank links"] = "Off"
- commandArray["Staande lamp dressoir links"] = "On"
- commandArray["Lamp dressoir rechts"] = "Off"
- end
- end
- -- Controleer of er behoefte is aan verlichting.
- function lichtbehoefteBinnen()
- if ( isHetDonkerBinnen() == true and iemandThuis() == true ) then
- print('Er is behoefte aan licht.')
- return true
- elseif ( isHetDonkerBinnen() == false or iemandThuis() == false ) then
- print('Er is geen behoefte aan licht.')
- return false
- end
- end
- if ( otherdevices["Donker"] == "On" and otherdevices["Buitenlamp schuur"] == "Off" ) then
- print('De buitenverlichting wordt ingeschakeld.')
- commandArray["Group:Buitenverlichting"] = "On"
- elseif ( otherdevices["Donker"] == "Off" and otherdevices["Buitenlamp schuur"] == "On" ) then
- print('De buitenverlichting wordt uitgeschakeld.')
- commandArray["Group:Buitenverlichting"] = "Off"
- end
- local m_huidigeToestand = bepaalHuidigeToestand()
- local m_gewensteToestand = m_huidigeToestand
- m_donker = isHetDonkerBinnen()
- m_lichtbehoefte = lichtbehoefteBinnen()
- m_iemandthuis = iemandThuis()
- m_maglichtuitschakelen = isUitschakelenToegestaan()
- m_maglichtinschakelen = isInschakelenToegestaan()
- -- debug
- -- m_lichtbehoefte = false
- -- m_iemandthuis = false
- -- m_maglichtuitschakelen = false
- print('m_huidigeToestand '..toToestandString(m_huidigeToestand))
- print('m_gewensteToestand '..toToestandString(m_gewensteToestand))
- print('m_donker '..tostring(m_donker))
- print('m_lichtbehoefte '..tostring(m_lichtbehoefte))
- print('m_iemandthuis '..tostring(m_iemandthuis))
- print('m_maglichtuitschakelen '..tostring(m_maglichtuitschakelen))
- print('m_maglichtinschakelen '..tostring(m_maglichtinschakelen))
- -- local VerlichtingUitgeschakeld, NietThuisStand, VerlichtingIngeschakeld, Ongedefinieerd = 0, 1, 2, 3
- function gaNaarGewensteToestand()
- if ( m_donker == true ) then
- if ( m_lichtbehoefte == false ) then
- m_gewensteToestand = NietThuisStand
- else
- if ( otherdevices["Bedtijd"] == "On" ) then
- m_gewensteToestand = VerlichtingUitgeschakeld
- else
- m_gewensteToestand = VerlichtingIngeschakeld
- end
- end
- else
- m_gewensteToestand = VerlichtingUitgeschakeld
- end
- print('m_huidigeToestand '..toToestandString(m_huidigeToestand))
- print('m_gewensteToestand '..toToestandString(m_gewensteToestand))
- if (m_huidigeToestand ~= m_gewensteToestand) then
- print('Huidige toestand is niet de gewenste!')
- if (isOvergangToegestaan(m_huidigeToestand, m_gewensteToestand) == true) then
- stelToestandIn(m_gewensteToestand)
- else
- print('Overgang is niet toegestaan.')
- end
- else
- print('Huidige toestand is de gewenste!')
- end
- end
- gaNaarGewensteToestand()
- return commandArray
Advertisement
Add Comment
Please, Sign In to add comment