Skip to content

Instantly share code, notes, and snippets.

@nshores

nshores/check_zm_alarm.py

Last active Jul 27, 2020
Embed
What would you like to do?
check_zm_alarm.py
import pyzm.ZMMemory as zmmemory
import requests
import time
#set monitor id
mid = 6
#HA Url
ha_webhook = 'http://slim-dev.local:8123/api/webhook/patio'
#State List 0 = Idle
#State List 2 = Alarm - This is the one we want
#State List 3 = Alert
while True:
print ("--------| Getting State | for monitor 6 ----------")
m = zmmemory.ZMMemory(mid=mid)
current_state = m.get_shared_data()['state']
print('Current state is {}'.format(current_state))
if current_state == 2:
print("State is Alarm")
print("Triggering HA Automation Webhook")
try:
re = requests.post(ha_webhook)
except:
print("Issue connecting to HA")
elif current_state == 3:
print("State is Alert")
print("Triggering HA Automation Webhook")
try:
re = requests.post(ha_webhook)
except:
print("Issue connecting to HA")
else:
print("Monitor not in any alarm states")
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment