je m'étais fais une petite alarme en blockly, qui fonctionnait, et suis passé sous LUA que je ne connais pas vraiment.. mais bon, je suis têtu
En LUA j'avais d'abord un switch virtuel on/off pour simuler une porte ouverte, ça fonctionnait
et puis.. j'ai voulu enlever ce switch virtuel pour y mettre le vrai capteur sur ma porte d'entrée et la.. ça ne fait plus rien
Après pas mal d'essais, (et beaucoup trop d'escaliers descendus puis remontés)...
Comment dois-je faire pour récupérer en lua l'état du contact xiaomi "Contact 1 - Front Door " ?
Dans le code ci dessous, AlarmState est lié à l'état du control panel (je mets le code plus bas)
Code sûrement pas joli mais bon..
Code : Tout sélectionner
commandArray = {}
if (devicechanged['Contact 1 - Front Door'] == 'Open' and commandArray['Variable:AlarmState'] == '2') then
print('Potential breach: Alarm State to 3 and set 5 secondes alarmgrace period on')
commandArray['Variable:AlarmState'] = '3'
commandArray['AlarmGracePeriod'] = 'Off AFTER 5' -- physical switch
end
return commandArrayÇi dessous le code lua pour allumer/éteindre l'alarme - sons désactivés car mes enfants ne supportaient plus de les entendre !
Switch est le Switch multifonction de xiaomi
Code : Tout sélectionner
commandArray = {}
if (devicechanged['Switch'] == 'Click') then
print('in 5s we will arm the Alarm')
commandArray['AlarmGracePeriod'] ='On' --
commandArray['SecurityPanel'] ='Arm Away AFTER 5' -- Give 5 seconds to leave before arming the alarm
commandArray['Variable:AlarmState'] ='2 AFTER 5'
-- commandArray[#commandArray + 1] = {['Blueway Alarm'] = 'Set Level:30' } --Play soundtrack Accident tone
-- commandArray[#commandArray + 1] = {['Blueway Alarm'] = 'Off AFTER 1'} --Turn off after 1 second
commandArray['Blueway Gate'] = 'On AFTER 5' -- turn on gateway light to signal alarm is set
end
if (devicechanged['Switch'] == 'Double Click') then -- this part is not in use today
print('we will now immediately activate the alarm in -at home- configuration')
commandArray['SecurityPanel'] ='Arm Home'
-- commandArray['Variable:AlarmState']='999'
end
if (devicechanged['Switch']== 'Long Click') then
print('we will now immediately deactivate the alarm')
commandArray['SecurityPanel'] ='Disarm'
commandArray['Variable:AlarmState'] ='1'
commandArray['AlarmGracePeriod'] ='On'
-- commandArray[#commandArray + 1] = {['Blueway Alarm Clock'] = 'Set Level:20'} -- Play soundtrack Enthousiastic
-- commandArray[#commandArray + 1] = {['Blueway Alarm Clock'] = 'Off AFTER 1'} --Turn off after 1 second
commandArray['Blueway Gate'] = 'Off'
end
return commandArray