I did a small script that runs as a service on my Pi that recover the state of the alarm (armed, normal or night mode) but it could recover many other states
It requires pysiaalarm and python3-systemd (this latter being installed by apt) as packages and some I forgot (requests?)..
Code: Select all
#! /usr/bin/env python3.9
import json
import requests
#import logging
import time
from pysiaalarm import SIAAccount, SIAClient, SIAEvent
import systemd.daemon
#logging.basicConfig(level=logging.DEBUG)
local_ip = "192.168.0.1"
sia_port = 8125
sia_account = "AAAA"
url_domoticz = "http://192.168.0.1:80/"
id_armed_night = "11" #night mode alarm switch id
id_armed_normal = "21" #alarm switch id
id_text = "35" #text device to recover non recognized code
reactions = {
"BA" : [{"state":"ALARM","value":True}],
"BS" : [{"state":"ALARM","value":True}],#device shorted
"BV" : [{"state":"ALARM","value":True}],#intrusion
"HA" : [{"state":"ALARM","value":True}],#hold-up
"JA" : [{"state":"ALARM","value":True}],#Unauthorized access keypad
"PA" : [{"state":"ALARM","value":True}],
"SM" : [{"state":"ALARM","value":True}], #Alarm because of movement
"YC" : [{"state":"ALARM","value":True}],#hub offline mobile and ethernet
"NL" : [{"state":"ARM NIGHT" ,"value":True}],
"NC" : [{"state":"ARM NIGHT" ,"value":True}],
"OP" : [{"state":"ARM","value":False}],
"CF" : [{"state":"ARM","value":True}], #armed with malfunction
"CL" : [{"state":"ARM","value":True}],
"OA" : [{"state":"ARM","value":False}],
"FA": [{"state":"FIRE" ,"value":True}],
"KA": [{"state":"FIRE" ,"value":True}],#temperature of fire sensor
"WA": [{"state":"LEAK","value":True}],
"WH": [{"state":"LEAK" ,"value":False}],
"GA": [{"state":"GAS","value":True}],
"GH": [{"state":"GAS" ,"value":False}],
"BR" : [{"state":"ALARM","value":False}],
"TA" : [{"state":"LID OPEN","value":True}],
"TR" : [{"state":"LID OPEN","value":False}],
"ZZ" : [{"state":"Device OFF","value":True}],
"ZY" : [{"state":"Device OFF","value":False}],
"YP" : [{"state":"Power failure","value":True}],
"YQ" : [{"state":"Power failure","value":False}],
"RB" : [{"state":"Updating firmware","value":True}],
"RS" : [{"state":"Updating firmware","value":False}],
"RP" : [],
"YG" : [] #New settings
}
def func(event: SIAEvent):
#print(event.code)
tipo = event.code
if tipo in reactions:
reaction = reactions[tipo]
for reactio in reaction:
state = reactio["state"]
value = reactio["value"]
print("Event: " + state + " : " + str(value))
if state == "ARM" and value == False:
r = requests.get(url_domoticz + 'json.htm?type=command¶m=switchlight&idx=' + id_armed_normal + '&switchcmd=Off')
r = requests.get(url_domoticz + 'json.htm?type=command¶m=switchlight&idx=' + id_armed_night + '&switchcmd=Off')
elif state == "ARM" and value == True:
r = requests.get(url_domoticz + 'json.htm?type=command¶m=switchlight&idx=' + id_armed_normal + '&switchcmd=On')
elif state == "ARM NIGHT" and value == True:
r = requests.get(url_domoticz + 'json.htm?type=command¶m=switchlight&idx=' + id_armed_night + '&switchcmd=On')
else:
print("Unknown event: " + tipo )
r = requests.get(url_domoticz + 'json.htm?type=command¶m=udevice&idx=' + id_text + '&nvalue=0&svalue='+tipo)
account = [SIAAccount(sia_account, "")]
sleep_time = 1200
count = 0
#systemd.daemon.notify('READY=1')
with SIAClient(local_ip, sia_port, account, function=func) as client:
#time.sleep(sleep_time)
client.start()
systemd.daemon.notify('WATCHDOG=1')
while (True) :
time.sleep(1)
count = count + 1
if count == 30:
count = 0
systemd.daemon.notify('WATCHDOG=1')