0.4.0 • Published 1 year ago

tasmota-commands-core v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Tasmota Commands Core

npm version

Overview

A core package for controlling Tasmota devices. Doesn't include any implementations for sending the commands. Use the package tasmota-commands-http or tasmota-commands-mqtt if you want a ready-to-use solution or create a custom commandHandler

Install

npm install tasmota-commands-core or yarn add tasmota-commands-core

Custom command handler

Create a function satisfying type "CommandHandler" that sends a command and returns a response. The response should be a json object that Tasmota returns.

import { CommandHandler } from 'tasmota-commands-core';

const myCustomCommandHandler: CommandHandler = async ({ command, payload, logger }) => {
  // Send command
  // Wait response
  return { POWER: 'OFF' };
};

Example

const myCustomCommandHandler = ...;

const commands = new TasmotaCommands(myCustomCommandHandler);
commands.Control.setPower0('on');

Parameters

ParameterRequiredAccepted valuesDescription
refreshStateOnInitnobooleanGet the current state from the device asynchronously after class initialization
refreshStateIntervalnonumberRefresh state interval in milliseconds. Disabled by default.
loggernologger implementation, should satisfy type LoggerLogging implementation. Leave unset to disable logging. Set to console or your custom implementation.
onStateChangednoOnStateChangeCallbackCallback that is called always after state is changed
onStateRefreshednoOnStateChangeCallbackCallback that is called always after state is refreshed

Setup Development Environment

Install Development Dependencies

Navigate to the project folder and install dependencies with yarn

yarn install

Roadmap

Contribution

License

MIT