het lua script zelf heeft de naam gang, ik zal morgen als test eens zonder haakjes proberen, bedankt voor de tip!
Wat ik met het gehele script wil bereiken is het automatisch schakelen van de lamp in de gang (met variabele lichtsterkte aan de hand van de tijd en licht buiten).
Met bovenstaande code wil ik dat wanneer alle 5 de variabelen uit zijn, de lamp ook automatisch uit gaat.
Situatie is zo dat ik 4x pir schakeling heb (1 voor 's ochtends, 1 voor 's middags, 1 voor 's avonds en 1x 's nachts) en 1x voordeur. Zoals de namen al deels aangeven, is er van de PIR schakeling maar 1 tegelijk actief (aan de hand van hoe laat het is), eventueel samen met de voordeur (wanneer deze open is).
Wat er dus moet gebeuren is wanneer alle 5 de (virtuele) schakelaars uit zijn, het script de lamp ook uit moet zetten.
Heb het probleem nu eerst op de "lelijke manier" opgelost, het stukje code wat ik hierboven al poste steeds opnieuw in het script gezet en de "devicechanged" steeds 1 positie opgeschoven

(Ik ben nog nieuw / lerende met lua scripting

)
Zie ook het volledige script wat ik gebruik (en nog flink verbeterd kan worden zeer waarschijnlijk

):
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
| commandArray = {}
-- Declare time function
time = os.date("*t")
-- Voordeur
if ((devicechanged['Voordeur'] == 'Open') and otherdevices['Schemering buiten'] == 'On') then
commandArray['Voordeur_Timer']='On'
end
-- Ochtend
if (((devicechanged['PIR Gang Voordeur'] == 'On') or (devicechanged['PIR Gang ***'])) and (otherdevices['Schemering buiten'] == 'On') and ((time.hour >= 05) and (time.hour < 09))) then
commandArray['PIR_Gang_Ochtend']='On'
end
-- Middag
if (((devicechanged['PIR Gang Voordeur'] == 'On') or (devicechanged['PIR Gang ***'])) and (otherdevices['Schemering buiten'] == 'On') and ((time.hour >= 09) and (time.hour < 17))) then
commandArray['PIR_Gang_Middag']='On'
end
-- Avond
if (((devicechanged['PIR Gang Voordeur'] == 'On') or (devicechanged['PIR Gang ***'])) and (otherdevices['Schemering buiten'] == 'On') and ((time.hour >= 17) and (time.hour < 23))) then
commandArray['PIR_Gang_Avond']='On'
end
-- Nacht
if (((devicechanged['PIR Gang Voordeur'] == 'On') or (devicechanged['PIR Gang ***'])) and (otherdevices['Schemering buiten'] == 'On') and ((time.hour >= 23) and (time.hour < 05))) then
commandArray['PIR_Gang_Nacht']='On'
end
-- Voordeur
if (devicechanged['Voordeur_Timer'] == 'On') then
commandArray['Gang']='Set Level 100'
end
-- PIR_Gang_Ochtend
if ((devicechanged['PIR_Gang_Ochtend'] == 'On') and (otherdevices['Voordeur_Timer'] == 'Off')) then
commandArray['Gang']='Set Level 30'
end
-- PIR_Gang_Middag
if ((devicechanged['PIR_Gang_Middag'] == 'On') and (otherdevices['Voordeur_Timer'] == 'Off')) then
commandArray['Gang']='Set Level 100'
end
-- PIR_Gang_Avond
if ((devicechanged['PIR_Gang_Avond'] == 'On') and (otherdevices['Voordeur_Timer'] == 'Off')) then
commandArray['Gang']='Set Level 80'
end
-- PIR_Gang_Nacht
if ((devicechanged['PIR_Gang_Nacht'] == 'On') and (otherdevices['Voordeur_Timer'] == 'Off')) then
commandArray['Gang']='Set Level 10'
end
-- Automatisch uitzetten Voordeur_Timer
if ((devicechanged['Voordeur_Timer'] == 'Off') and (otherdevices['PIR_Gang_Ochtend'] == 'Off') and (otherdevices['PIR_Gang_Middag'] == 'Off') and (otherdevices['PIR_Gang_Avond'] == 'Off') and (otherdevices['PIR_Gang_Nacht'] == 'Off')) then
commandArray['Gang']='Off'
end
-- Automatisch uitzetten PIR_Gang_Ochtend
if ((otherdevices['Voordeur_Timer'] == 'Off') and (devicechanged['PIR_Gang_Ochtend'] == 'Off') and (otherdevices['PIR_Gang_Middag'] == 'Off') and (otherdevices['PIR_Gang_Avond'] == 'Off') and (otherdevices['PIR_Gang_Nacht'] == 'Off')) then
commandArray['Gang']='Off'
end
-- Automatisch uitzetten PIR_Gang_Middag
if ((otherdevices['Voordeur_Timer'] == 'Off') and (otherdevices['PIR_Gang_Ochtend'] == 'Off') and (devicechanged['PIR_Gang_Middag'] == 'Off') and (otherdevices['PIR_Gang_Avond'] == 'Off') and (otherdevices['PIR_Gang_Nacht'] == 'Off')) then
commandArray['Gang']='Off'
end
-- Automatisch uitzetten PIR_Gang_Avond
if ((otherdevices['Voordeur_Timer'] == 'Off') and (otherdevices['PIR_Gang_Ochtend'] == 'Off') and (otherdevices['PIR_Gang_Middag'] == 'Off') and (devicechanged['PIR_Gang_Avond'] == 'Off') and (otherdevices['PIR_Gang_Nacht'] == 'Off')) then
commandArray['Gang']='Off'
end
-- Automatisch uitzetten PIR_Gang_Nacht
if ((otherdevices['Voordeur_Timer'] == 'Off') and (otherdevices['PIR_Gang_Ochtend'] == 'Off') and (otherdevices['PIR_Gang_Middag'] == 'Off') and (otherdevices['PIR_Gang_Avond'] == 'Off') and (devicechanged['PIR_Gang_Nacht'] == 'Off')) then
commandArray['Gang']='Off'
end
return commandArray |
PIR Gang *** heb ik wegens privacy redenen even gemaskeerd.