Examples

Sending Commands

A list of commands that can be sent can be found in the Input Commands section of the protocol documentation. Additional information on the user-level commands available can be found in the Operation Summary of the installer manual.

import asyncio

from nessclient import Client

loop = asyncio.get_event_loop()
host = '127.0.0.1'
port = 65432
client = Client(host=host, port=port, loop=loop)

# Send arming command via library abstraction
loop.run_until_complete(client.arm_away('1234'))
# Send panic command via library abstraction
loop.run_until_complete(client.panic('1234'))
# Send disarm command via library abstraction
loop.run_until_complete(client.disarm('1234'))
# Send aux control command for output 2 via library abstraction
loop.run_until_complete(client.aux(2))
# Send custom command
# In this instance, we are sending a status update command to view
# output status
loop.run_until_complete(client.send_command('S15'))

client.close()
loop.close()

Listening for Events

import asyncio

from nessclient import Client, ArmingState, BaseEvent

loop = asyncio.get_event_loop()
host = '127.0.0.1'
port = 65432
client = Client(host=host, port=port, loop=loop)


@client.on_zone_change
def on_zone_change(zone: int, triggered: bool):
    print('Zone {} changed to {}'.format(zone, triggered))


@client.on_state_change
def on_state_change(state: ArmingState):
    print('Alarm state changed to {}'.format(state))


@client.on_event_received
def on_event_received(event: BaseEvent):
    print('Event received:', event)


loop.run_until_complete(asyncio.gather(
    client.keepalive(),
    client.update(),
))

client.close()
loop.close()

.