Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tbowmo/node-red-small-timer

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tbowmo/node-red-small-timer

Small timer node for Node-RED with support for sunrise, sunset etc. timers

  • 0.19.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Node-red-small-timer

Quality Gate Status Sonar cloud test Build status

A Node-RED timer node to rule them all. It delivers either an on or off message at scheduled intervals. These intervals can be consistent daily occurrences, like '19:00' for 'on' and '23:00' for 'off', perfect for controlling f.ex. a porch light. However, its true power lies in its ability to activate the light at, let's say sunset and deactivate it at dusk. Pretty cool, right?

This encapsulates the core concept: Emit a predefined message at either specific times, or on sunrise / sunset. Garnish this with a powerful day schedule configuration, and you have a small timer for your lights, or other things that needs to be turned on or off daily.

Install

Either use the palette manager in Node-RED to install the plugin, or use a terminal to install directly in your local installation of Node-RED:

npm install @tbowmo/node-red-small-timer

Once installed, restart your node-red server, and you will have a set of new nodes available in your palette under timers.

Setup

image of configuration
Optional: Start by configuring your location, which is used to calculate the correct sunrise and sunset times for your area. You can either let your browser do this by clicking the "Get position from browser" button, or manually enter the latitude and longitude using a service like Google Maps.

If you don't configure a location, you'll only be able to use fixed times to send on/off messages.

On and Off time

Configures the on and off events
On off times

Time of day

Set this property to the desired on / off time for the day. Can be a specific time, or use a dynamic time such as sunrise, sunset etc.

image of time of day

Note! the timestamps shown under "Dynamic sun and moon times" is calculated on the fly, by the suncalc library, and are shown for the location chosen and current time of year. The actual time used by small timer will be re-calculated regularly, if one of these event times are chosen

Offset

When using a dynamic time, you can add an offset to the calculated time. Use it for example to turn the light on 30 minutes before sunrise.

Timeout

Used when triggering an override of the current state, after set time the node will switch back to whatever the output state should be at the given time, if it was in auto mode. This value is split into an on and off timeout. This means that you could have an 5 minutes on timeout (for turning on lights momentarily) while keeping off at default timeout which is 24 hours (or until next state change)

Minimum time

This can be used to set a minimum required 'on time'. If the calculated 'on time' is less than this value, the event will be ignored. For example, if you are using sunset to turn on lights in the evening with a fixed off time, you might not be interested in turning on the light for only 5 minutes. This can be prevented by setting a minimum 'on time' here.

Schedule rules

Schedule
This is used to determine which days the timer should or should not operate.

== is include, this specifies days where the rule should run

!= is exclude, this specifies days where the rule does not run.

Note that if the state is turned on by auto state, it will also run at the off time, even if the day is excluded (ie, if the off time is after midnight and the day is excluded).

The rules are read and executed one by one, it is the outcome after the last rule has been read, that defines if the day is included or excluded

If the node is turned on on a "do not run day", temporary on is used, and output will be turned off after set timeout

Default logic state is that the timer is disabled, so you need at least one rule that turns it on (==).

Month / week

Note that the weeks numbers are calculated according to ISO8601, which means that weeks start on mondays.

Examples of schedule rules

  1. Run on every day, except thursdays in July
    All days except thursdays in July

  2. Run on mondays in odd weeks, except all of December
    Odd weeks on mondays, except December

  3. Run on mondays in June
    Only mondays in june

Output configuration

Topic

Topic parameter of the msg that is sent out on events. This can be used to send on to mqtt for example.

On message

Payload of the output message is set to this value during on, can be set to json, number, string, or boolean

Off message

Payload of the output message is set to this value during off, can be set to json, number, string, or boolean

Options

Options
Wrap midnight: Will wrap on time around midnight, if on time is 23:00 and off time is 02:00, checking this will turn on before midnight, and off after. If unchecked, it will be ignored. This is particularly useful if you have a fixed on time at 06:00 in the morning, and a dynamic off time tracking sunrise, when the sunrise is before 06:00 you might not want it to turn on the porch light, and thus it should not wrap midnight.

Emit on startup: Configures the node to emit a message 2 seconds after startup / redeploy of your node red flow.

Debug enable: This will add an extra output to the node providing debug information, like the different sunrise/sunset etc. times (see debug section below)

Repeat: Enables the node to repeat status messages with the specified interval (in seconds). If disabled the node will only emit a message when its state changes.

Output

By default the node has a single output, which provides the following object:

{
    trigger: 'input' | 'timer',
    autoState: boolean,
    timeout: number,
    temporaryManual: boolean,
    duration: number,
    stamp: number,
    state: string,
    payload: object, string, number // as setup in the node
    topic: string // (as setup in the node)
}

propertydescription
triggerif the output is triggered by an input message, then this property is set to "input" otherwise it is set to "timer"
autoStatewill be true whenever the node is running in auto mode
timeoutindicates how long there is until the node will return to auto state, when in temporary override
temporaryManualWill be true when the node is in temporary override
durationtime until next on, or off, event happens
statewill be one of auto, tempOn or tempOff
stampcurrent unix timestamp (since epoch)

Input

The input of the node takes a few commands in the payload property of the message sent to small timer, these are completely optional and not needed for normal operation, but can be used to turn the output temporary on or off.

payloaddescription
1 / onTurns the output temporarily on
0 / offTurns the output temporarily off
auto / defaultSets the node back to autostate, and outputs whatever the autostate would be (on/off)
syncEmits the current state on the output

Using the temporary on/off feature will emit the respective on/off message on the output. Simultaneously, it will start an internal timer with the value from the timeout configuration option. When this timer runs out, the node will resume auto mode.

Note that if you do a temporary on/off to the same state that the auto mode will be in, then the node will return to auto state.

Sending an auto/default payload will cause it to return to auto mode (if it was in a temporary on/off state earlier), and emit the new state if so required

NOTE: If the input payload property contains non-decodable properties/strings, the input will be ignored, and an error will be emitted to Node-RED.

Optional properties on input message

propertytypedescription
resetbooleanIf this property resolves to a truthy value, the node will be reset to auto mode (Works like auto/default payload)
timeoutnumberThis can be used to override the timeout set in the configuration, and applies to the current on or off command. If left out / undefined, the configured timeout will be used

Debug

When debug is enabled, the node will have a secondary output, which emits data from the suncalc calculations for sunrise/sunset, etc. This data will be emitted at the same time as the main output is emitted (at changes, or when sync is sent to the input).

The debug output will contain the following data

{
    override: 'tempOn' | 'tempOff' | 'auto',
    topic: 'debug'
    sunTimes: {
        dawn: number,
        dusk: number,
        solarNoon: number,
        sunrise: number,
        sunset: number,
        night: number,
        nightEnd: number,
    },
    moonTimes: {
        rise: number,
        set: number,
    },
    now: number,
    actualStart: number,
    actualEnd: number,
    nextStart: number,
    nextEnd: number,
    onState: boolean,
    operationToday: 'normal' | 'noMidnightWrap' | 'minimumOnTimeNotMet',
}

All the above numbers will represent the number of minutes since midnight on the day the event happens, except for nextStart and nextEnd, which will indicate the number of minutes until the next event.

The debug object can be extended with new properties in future releases that might not be fully described here.

Origin

SmallTimer was originally inspired by BigTimer, which, in my opinion, has a somewhat overwhelming editor UI with numerous checkboxes. This inspired the creation of SmallTimer, aiming for a simpler approach to the editor UI. SmallTimer is a complete rewrite from scratch, utilizing modern TypeScript and unit tests to ensure the core functionality works during development.

Keywords

FAQs

Package last updated on 20 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc