Skip to content
ggodart edited this page Jan 6, 2021 · 1 revision

trigger_code

See original

DESCRIPTION

This file contains code that implements MisterHouse's trigger functionality. Monitors trigger code, used by code like tv_grid and the web alarm page, that specifies events that trigger actions. View, add, modify, or delete triggers with http://localhost:8080/bin/triggers.pl (also under the ia7 MisterHouse Home button).

You can create triggers to easily run MisterHouse code on specified events. When you create a trigger with trigger_set, MisterHouse will create or modify the code_dir/triggers.mhp file.

SUBROUTINES

trigger_set(event, code, type, name, replace, triggered, new_name)

Creates or modified an existing trigger. Only event and code are required. The code will run when event returns true. The type defaults to OneShot (see below) and $name will default to a unique auto-generated name. If name is specified and already exists, name will be incremented, unless replace=1. triggered is the last time the trigger ran in epoch second.

If new_name is specified, trigger name is renamed to new_name and the other arguments are applied.

The event string is evaluated to check for errors and the trigger doesn't run any are found. The code is always run in an eval, so MisterHouse won't crash if you type an error.

Examples:

      &trigger_set("time_now '$date $time - 00:02'",
        "speak 'Something cool happens in 2 minutes'");
  
      &trigger_set("time_now '$Save{wakeup_time}'",
        "speak 'Time to wake up'", "NoExpire", "Wakeup Trigger", 1);

Another example of using triggers is in mh/code/common/tv_grid.pl.

Here are the valid trigger types:

    OneShot  => The trigger will run once, then changed type to Expired
  
    Expired  => Will be pruned from the triggers.mhp file after one week
                and archived in data_dir/triggers.expired.
  
    NoExpire => Runs on every event and never expires.
  
    Disabled => Will stay in your triggers.mph file, but will not run.

trigger_get(name}

Returns the event, code, type, last triggered time, event error (if any), and code error (if any) of the specified trigger.

trigger_delete(name}

Deletes the specified trigger.

trigger_copy(name}

Copies the specified trigger, the new name has a sequential number appended to the old name.

trigger_list

Returns a list of trigger names.

trigger_active(name)

Returns true if the trigger is active.

trigger_expired(name)

Returns true if the trigger is expired.

Clone this wiki locally