Skip to content

Event Handlers

Calin Crisan edited this page Nov 13, 2023 · 1 revision

About

Event handlers are used by add-ons to apply filters to events before processing them. Please refer to the documentation of respective add-ons to actually make use of event handlers - you cannot use event handlers directly. This page offers details on configuring the filtering part of add-ons that make use of event handlers.

Usage

In your qtoggleserver.conf, the add-on should be present in the event_handlers configuration section. To specify filtering, simply add the filter parameter to the event handler parameters:

qtoggleserver.conf:
...
event_handlers = [
    ...
    {
        ...
        filter = {
            # here go your filtering rules
        }
        ...
    }
    ...
]
...

Event Types

To process only events of a certain type, use type = "<event-type>". Following example will process only events of type value-change:

qtoggleserver.conf:
filter = {
    type = "value-change"
    ...
}
...

You can also specify a list of accepted event types:

qtoggleserver.conf:
filter = {
    type = ["value-change", "port-update"]
    ...
}
...

Port Values

To process only port events that occur on a port having a certain value, use port_value = <value>. Following example will process only events on ports having value true:

qtoggleserver.conf:
filter = {
    port_value = true
    ...
}
...

You can also specify a list of accepted values:

qtoggleserver.conf:
filter = {
    port_value = [1, 2]
    ...
}
...

You can even set it to an expression. Following example will process only events on ports having value equal to ten times the value of vport1:

qtoggleserver.conf:
filter = {
    port_value = "MUL($vport1, 10)"
    ...
}
...

If you want to handle events that occur on a port value transition, use port_value_transition = [<from_value>, <to_value>]. Following example will process only events on ports whose value has just became true:

qtoggleserver.conf:
filter = {
    port_value_transition = [false, true]
    ...
}
...

To react on transitions from any or to any value, simply use any, e.g. port_value_transition = [any, 10]

Port Attributes

To process only port events that occur on a port having a certain attribute, use port_<attribute> = <value>. Following example will process only events on writable ports:

qtoggleserver.conf:
filter = {
    port_writable = true
    ...
}
...

You can also specify a list of accepted values. Following example will process only events on ports with id "bedroom_temperature" or "kitchen_temperature":

qtoggleserver.conf:
filter = {
    port_id = ["bedroom_temperature", "kitchen_temperature"]
    ...
}
...

If you want to handle events that occur on a port attribute transition, use port_<attribute>_transition = [<from_value>, <to_value>]. Following example will process only events on ports that have just been enabled:

qtoggleserver.conf:
filter = {
    port_enabled_transition = [false, true]
    ...
}
...

To react on transitions from any or to any attribute value, simply use any, e.g. port_enabled_transition = [any, true]

Device Attributes

To process only device events that occur on a device having a certain attribute, use device_<attribute> = <value>. Following example will process only events on device when its battery is low:

qtoggleserver.conf:
filter = {
    device_low_battery = true
    ...
}
...

You can also specify a list of accepted values. Following example will process only events when device's IP address is one of the given values:

qtoggleserver.conf:
filter = {
    device_ip_address = ["192.168.0.5", "192.168.0.6"]
    ...
}
...

If you want to handle events that occur on a device attribute transition, use device_<attribute>_transition = [<from_value>, <to_value>]. Following example will process only events on device when its battery becomes low:

qtoggleserver.conf:
filter = {
    device_low_battery_transition = [false, true]
    ...
}
...

To react on transitions from any or to any attribute value, simply use any, e.g. device_low_battery_transition = [any, true]

Slave Device Attributes

To process only slave device events that occur on a device having a certain attribute, use slave_<attribute> = <value>. Following example will process only events on online devices:

qtoggleserver.conf:
filter = {
    slave_online = true
    ...
}
...

You can also specify a list of accepted values. Following example will process only events on devices with name "bedroom_light" or "kitchen_ight":

qtoggleserver.conf:
filter = {
    slave_name = ["bedroom_light", "kitchen_light"]
    ...
}
...

If you want to handle events that occur on a slave device attribute transition, use slave_<attribute>_transition = [<from_value>, <to_value>]. Following example will process only events on slave devices that have just been enabled:

qtoggleserver.conf:
filter = {
    slave_enabled_transition = [false, true]
    ...
}
...

To react on transitions from any or to any attribute value, simply use any, e.g. slave_enabled_transition = [any, true]