Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ZBus

API for the Z-Bus Home Script environment which allows you to access and control your Z-Bus smart home system.

This class is loaded into the runtime and accessible via the global zBus object (see zBus)

At a glance

  • receive allows to register callback functions, which get executed upon reception of Z-Bus events
  • scene allows to register callback functions, which get executed through scene buttons in Z-Bus Home
  • transmit allows to send events to the Z-Bus system
  • dim allows to control the brightness of Z-Bus dimmers

Hierarchy

  • ZBus

Index

Properties

jobs

jobs: {} = ...

A dictionary of all node-schedule scheduled Jobs, accessible by name.

Type declaration

  • [jobName: string]: Job

Readonly reception

reception: Observable<DeviceEvent>

RxJS reception stream.

Z-Bus smart home DeviceEvents (e.g., switching a device from a physical button) can be subscribed to using RxJS Observables including all their operators.

Example

const { filter } = require('rxjs/operators');
zBus.reception
  .pipe(filter(event => event.address === 79 || event.address === 80))
  .subscribe((event) => {
    //This triggers for any reception of the addresses 79 or 80
    console.log('Received address', event.address);
  });

Readonly scenes

scenes: Observable<SceneEvent>

RxJS scene stream.

When a user triggers a scene from the button in the web app, this can be subscribed to using RxJS Observables including all their operators.

Readonly transmission

transmission: Subject<DeviceEvent>

RxJS transmission stream.

This pushes a RxJS Subject every time a DeviceEvent is sent from the scripting environment.

Methods

dim

  • dim(address: number | number[], brightness: number, duration?: number): void
  • Dims a Z-Bus Device

    Examples

    zBus.dim(1, 0.0); // Fade to 0% brightness - off
    zBus.dim(1, 0.5); // Fade to 50% brightness - off
    zBus.dim(1, 1.0); // Fade 100% brightness - on
    
    zBus.dim(1, 0.0, 0.04); // Instant off
    zBus.dim(1, 1.0, 160); // Slow "sunrise" fade on within 160 s
    
    zBus.dim([1, 2, 3], 0.5); // Dim multiple lights
    

    Parameters

    • address: number | number[]

      One or more addresses of the controlled dimmer(s) between 0 and 242

    • brightness: number

      The brightness between 0.0 and 1.0 %

    • duration: number = 8

      Duration of a full dimming ramp (from 0 to 100%) between 0.04 and 160 seconds

    Returns void

receive

  • receive(callback: DeviceEventNotification): void
  • receive(address: number, callback: DeviceEventNotification): void
  • receive(address: number[], callback: DeviceEventNotification): void
  • receive(address: number, command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop", callback: DeviceEventNotification): void
  • receive(address: number | number[], command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop" | (number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop")[], callback: DeviceEventNotification): void
  • Notifies of incoming communication from a Z-Bus Device

    • Calls user-defined code upon reception to inform about the received DeviceEvent

    This is useful for general Z-Bus system monitoring.

    Example

    Notifies of all received Z-Bus events:

    zBus.receive((event) => {
       //This triggers for any reception
       console.log('Received', event.address, event.event);
    });
    

    Parameters

    • callback: DeviceEventNotification

      This function is called when an event is received from the Z-Bus network. The notification contains the received DeviceEvent including address, event, and possibly a data packet

    Returns void

  • Notifies of incoming communication from a Z-Bus Device

    • Filters receptions by a matching addresses
    • Calls user-defined code upon reception to inform about the received DeviceEvent

    This is useful for triggering central automations or scenes from a button.

    Example

    Both variations notify of any Z-Bus receptions of devices set to address 80:

    zBus.receive(80, (event) => {
       //This triggers for a reception of any event on the address 80
       //Address and event are passed via the event
       console.log('Received on address', event.address, event.event);
    });
    zBus.receive(80, () => {
       //This triggers for a reception of any event on the address 80
       console.log('Triggered on address 80');
    });
    

    Parameters

    • address: number

      Only events matching this address between 0 and 242 are received

    • callback: DeviceEventNotification

      This function is called when an event is received from the Z-Bus network. The notification contains the received DeviceEvent including address, event, and possibly a data packet

    Returns void

  • Notifies of incoming communication from a Z-Bus Device

    • Filters receptions by one or more matching addresses
    • Calls user-defined code upon reception to inform about the received DeviceEvent

    This is useful for triggering similar scenes from different buttons, and for grouping single devices together.

    Example

    zBus.receive([79, 80], (event) => {
       //This triggers for a reception of any event on either address 79 or 80
       console.log('Received on address', event.address);
    });
    

    Parameters

    • address: number[]

      Only events matching any of these addresses between 0 and 242 are received

    • callback: DeviceEventNotification

      This function is called when an event is received from the Z-Bus network. The notification contains the received DeviceEvent including address, event, and possibly a data packet

    Returns void

  • Notifies of incoming communication from a Z-Bus Device

    • Filters receptions by a matching address and Command
    • Calls user-defined code upon reception to inform about the received DeviceEvent

    This is useful for triggering automations with hardware buttons (e.g., for triggering a scene on top of a 'toggle' button press) or for piggybacking automation on top of devices which are individually switched by single device control Commands (e.g. implementing a staircase light group)

    Example

    Notifies of received combinations of address 1 in combination with the event toggle (or its numeric equivalent 0)

    zBus.receive(80, 'toggle', () => {
       //This triggers for a reception of 'toggle' on address 80
       console.log('Central control button pressed');
       zBus.transmit([1, 2, 3], 'on');
    });
    zBus.receive(15, 0, () => {
       //This triggers for a reception of event 0 == 'toggle' on address 15
       console.log('Individual button pressed, switching entire group on');
       zBus.transmit([15, 16, 17], 'on');
    });
    

    Parameters

    • address: number

      Only events matching this address between 0 and 242 are received

    • command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop"

      Only events matching this Command (name or number between 0 and 255) are received

    • callback: DeviceEventNotification

      This function is called when an event is received from the Z-Bus network. The notification contains the received DeviceEvent including address, event, and possibly a data packet

    Returns void

  • Notifies of incoming communication from a Z-Bus Device

    • Filters receptions by one or more matching addresses, and one or more matching Commands
    • Calls user-defined code upon reception to inform about the received DeviceEvent

    This is useful for forwarding a specific set of commands to specific devices

    Example

    zBus.receive([79, 80], ['toggle', 'on', 'off'], (event) => {
       //This triggers for a reception of the commands 'toggle', 'on', or 'off'
       //on the "central" addresses 79 or 80
       console.log('Received on address', event.address);
    });
    

    Forwarding commands to a range of addresses:

    function forwardCommand(event) {
        zBus.transmit([0, 1, 2, 3, 4, 5, 6, 7, 8], event.event);
    }
    zBus.receive(99, ['on', 'off'], forwardCommand);
    

    Parameters

    • address: number | number[]

      Only events matching this address or any of these addresses between 0 and 242 are received

    • command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop" | (number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop")[]

      Only events matching this Command (name or number between 0 and 255) or any of these commands are received

    • callback: DeviceEventNotification

      This function is called when an event is received from the Z-Bus network. The notification contains the received DeviceEvent including address, event, and possibly a data packet

    Returns void

scene

  • scene(name: string, callback: SceneEventNotification): void
  • scene(name: string, address: number | number[], callback: SceneEventNotification): void
  • scene(name: string, address: number | number[], command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop" | (number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop")[], callback: SceneEventNotification): void
  • Sets a scene, when the corresponding SceneEvent scene button in the app is pressed

    This is useful for triggering scenes from the app.

    Example

    zBus.scene('Movie', () => {
       //This scene is triggered when pressing the button named "Movie" in the app
       zBus.transmit(4, 'off'); //Switch the main light off
       zBus.dim([5, 6], 0.2); //Dim both ambient lights to 20%
    });
    

    Parameters

    • name: string

      SceneEvents matching this name (or this id) receive this scene

    • callback: SceneEventNotification

      This callback function defines the scene to be executed

    Returns void

  • Sets a scene, when

    • the corresponding SceneEvent scene button in the app is pressed, or
    • when an DeviceEvent event from a physical button is received

    This is useful for triggering scenes both from the app and from a wall switch.

    Example

    zBus.scene('Movie', 3, () => {
       //This scene is triggered
       // * when pressing the button named "Movie" in the app
       // * when pushing the physical button attached to the sender address 3, event 'toggle'
       zBus.transmit(4, 'off'); //Switch the main light off
       zBus.dim([5, 6], 0.2); //Dim both ambient lights to 20%
    });
    

    Parameters

    • name: string

      SceneEvents matching this name (or this id) receive this scene, or

    • address: number | number[]

      DeviceEvents received on this address (or any of these addresses) between 0 and 242 receive this scene

    • callback: SceneEventNotification

      This callback function defines the scene

    Returns void

  • Sets a scene, when

    • the corresponding SceneEvent scene button in the app is pressed, or
    • when an DeviceEvent event from a physical button is received

    This is useful for triggering scenes both from the app and from a wall switch.

    Example

    zBus.scene('Movie', 3, 'toggle', () => {
       //This scene is triggered
       // * when pressing the button named "Movie" in the app
       // * when pushing the physical button attached to the sender address 3, event 'toggle'
       zBus.transmit(4, 'off'); //Switch the main light off
       zBus.dim([5, 6], 0.2); //Dim both ambient lights to 20%
    });
    

    Parameters

    • name: string

      SceneEvents matching this name (or this id) receive this scene, or

    • address: number | number[]

      DeviceEvents received on this address (or any of these addresses) between 0 and 242 receive this scene, in combination with

    • command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop" | (number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop")[]

      DeviceEvents received matching this Command (name or number between 0 and 255) or any of these commands receive this scene

    • callback: SceneEventNotification

      This callback function defines the scene to be executed

    Returns void

schedule

  • schedule(rule: string | number | RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date, callback: JobCallback): Job
  • schedule(name: string, rule: string | number | RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date, callback: JobCallback): Job
  • Schedules recurring events and timers as a node-schedule job.

    Cron-style scheduling

    The cron format allows to create complex schedules in a single string, 0 8 * * mon-fri for example defines "Every weekday at 08:00h". Such expressions are parsed by cron-parser and consists of:

    *    *    *    *    *    *
    ┬    ┬    ┬    ┬    ┬    ┬
    │    │    │    │    │    └ day of week (0 - 7) (0 or 7 is Sun)
    │    │    │    │    └───── month (1 - 12)
    │    │    │    └────────── day of month (1 - 31)
    │    │    └─────────────── hour (0 - 23)
    │    └──────────────────── minute (0 - 59)
    └───────────────────────── second (0 - 59, optional)
    
    Field names Allowed values
    second 0-59 (optional)
    minute 0-59
    hour 0-23
    day of month 1-31
    month 1-12 where 1 is January, 2 is February, and so on, or jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, or dec as three-character strings based on the English name of the month
    day of week 0-7 where 0 or 7 is Sunday, 1 is Monday, and so on, or mon, tue, wed, thu, fri, sat, or sun as three-character strings based on the English name of the day

    For example, the schedule 30 16 1 1 0 runs on 16:30h on the 1st of January, plus on every Sunday in January.

    Ranges and lists

    Ranges are two numbers separated with a -. For example, the range 8-11 for an hour field executes at hours 8, 9, 10 and 11.

    A list is a set of numbers or ranges separated by ,. For example: 1,3,5,7,9 or 8-12,14-18

    Unrestricted range

    A field can contain an asterisk *, which represents all possible values.

    For example, the schedule 30 16 1,15 * * executes at 16:30 on the 1st and 15th of each month.

    Step values

    Step values can be defined by first-last/step and define a range and an execution interval. For example, to specify event execution every other hour, use 0-23/2. This is equivalent to 0,2,4,6,8,10,12,14,16,18,20,22.

    If you specify *∕step the schedule will receive at any step interval. For example, the expression *∕2 will also receive every other hour.

    Cron examples

    Schedule Expression
    14:10 every Monday 10 14 * * 1
    Every day at midnight 0 0 * * *
    Every weekday at midnight 0 0 * * 1-5
    Midnight on 1st and 15th day of the month 0 0 1,15 * *
    18.32 on the 17th, 21st and 29th of November plus each Monday and Wednesday in November each year 32 18 17,21,29 11 mon,wed

    Example

    zBus.schedule('0 8 * * mon-fri', () => {
      //Blinds up every weekday morning at 08:00h
      zBus.transmit([10, 11, 12, 13, 14, 15], 'up');
    });
    

    Parameters

    • rule: string | number | RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date

      scheduling info

    • callback: JobCallback

      callback to be executed on each invocation

    Returns Job

  • Schedules recurring events and timers as a node-schedule job.

    Parameters

    • name: string

      name for the new Job

    • rule: string | number | RecurrenceRule | RecurrenceSpecDateRange | RecurrenceSpecObjLit | Date

      scheduling info

    • callback: JobCallback

      callback to be executed on each invocation

    Returns Job

transmit

  • transmit(address: number | number[], command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop", data?: number[]): void
  • Transmits an address, Command, and possibly a data packet to control a Z-Bus Device

    Examples

    Send address 99, event 'on' (e.g. for light)

    zBus.transmit(99, 'on');
    zBus.transmit(99, 3);
    

    Send address 5, event 'down' (e.g. for blinds)

    zBus.transmit(5, 'down');
    

    Send address 1, 2, 3, 4, 5 event 'down' (e.g. for centrally controlling multiple blinds)

    zBus.transmit([1, 2, 3, 4, 5], 'down');
    

    Send a data packet:

    zBus.transmit(5, 'on', [0x03, 0xFF]);
    

    Parameters

    • address: number | number[]

      One or more addresses of the controlled Device(s) between 0 and 242

    • command: number | "toggle" | "up-stop" | "down-stop" | "start" | "end" | "on" | "off" | "up" | "down" | "stop"

      Valid Command (name or number between 0 and 255) to send to the device

    • Optional data: number[]

      An optional two-bytes data packet. This is an unvalidated transmission, so preferably use dim instead

    Returns void

Generated using TypeDoc