Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "fhem-client"

A small Promise-based client for executing FHEM commands via FHEMWEB, supporting SSL, Basic Auth and CSRF Token.
Uses Node.js http or https module, depending on the protocol specified in the URL; no further dependencies.

It provides the methods execCmd, execPerlCode and callFn to interact with FHEM.
See the full documentation for details.

Changelog

Examples

Import

TypeScript

import FhemClient = require('fhem-client');

JavaScript

const FhemClient = require('fhem-client');

Usage

const fhemClient = new FhemClient(
    {
        url: 'https://localhost:8083/fhem',
        username: 'thatsme',
        password: 'topsecret',
        getOptions: { timeout: 2000 }
    }
);

fhemClient.expirationPeriod = 20000;

async function example()
{
    await fhemClient.execCmd('get hub currentActivity')
        .then(
            result => console.log('Current activity:', result),
            // Like below, but in plain JS.
            // You may also write it like this in TS with the following directive for @typescript-eslint, in case you are using it:
            // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
            e => console.log(`Error: Message: ${e.message}, code: ${e.code}`)
        );

    await fhemClient.execPerlCode('join("\n", map("Device: $_, type: $defs{$_}{TYPE}", keys %defs))')
        .then(
            (result: string) => console.log(`Your devices:\n${result}`),
            // This is correct TS code:
            // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
            (e: Error) => console.log(`Error: Message: ${e.message}, code: ${(e as any).code as string}`)
        );

    // Notify your companion device that your server application is shutting down
    // by calling its function 'serverEvent' with arguments <device hash>, 'ServerStateChanged', 'ShuttingDown'.
    await fhemClient.callFn('myDevice', 'serverEvent', true, false, 'ServerStateChanged', 'ShuttingDown');
}

void example()

Index

Classes

Interfaces

Generated using TypeDoc