Skip to content

Instantly share code, notes, and snippets.

View TotallyInformation's full-sized avatar

Julian Knight TotallyInformation

View GitHub Profile
@TotallyInformation
TotallyInformation / README.md
Created February 11, 2018 21:30
Secure Home Automation Control via a Telegram Bot

Those who know me from the Google group and Slack will know that I have a bit of a "thing" about security. It isn't easy to secure a web service at the best of times and trying to do so via your home network with minimal resources is even harder.

So why not avoid the issue altogether! By instead using a bot with a secure messaging service, you don't need to expose Node-RED or a web server, mess with certificates, authentication and authorisation. Nor worry about how to secure websockets.

The flow listed here demonstrates a simple Telegram bot that shows the current status of a set of wireless switches (in my case that control lights) and that let you turn them on and off via a simple text interaction.

If you want the full details, including pictures and some info on wiring up MQTT and the other dependencies, you can find them on the Totally Information development blog.

@TotallyInformation
TotallyInformation / README.md
Created February 10, 2018 13:56
Analogue Clock Dashboard Example

As Dashboard includes JQuery as well as Angular, you can use the extensive collection of JQuery examples and tutorials with it.

Here is a simple CSS driven analogue clock that you could easily adapt. It is based on a example on the web Old School Clock with CSS3 and jQuery. You will need to download the image files that are part of the archive that page links to.

Make sure you have httpStatic set in your settings.js file and put the CSS3Clock folder from the downloaded archive into your static folder. Then import the flow below, deploy and enjoy.

@TotallyInformation
TotallyInformation / README.md
Created December 2, 2017 22:17
Send APC UPS data to MQTT

Here is an example flow that reads data from an APC UPS (Uninterruptible Power Supply). These are commonly used to keep PC's and servers powered up during short power outages and to allow them to gracefully shut down.

In this case, I have a low-cost APC UPS connected via a USB cable to the Raspberry Pi that is running Node-RED and a Mosquitto MQTT broker.

To get the latest data from the UPS, we are using a command-line Linux tool called apcaccess. This is part of apcupsd which you should be able to install directly from your distribution's software library.

There are 2 function nodes included in the flow. One that isn't wired in, that converts the text output from the tool into an object on the payload containing properties for everything returned by the query. The second one, that is in use, is very similar but throws out a new message for each property using topics that correspond roughly to the homie MQTT topic structure. Homie is simi

@TotallyInformation
TotallyInformation / README.md
Created October 28, 2017 14:33
Example Web REST API with loop through record sets

Quite often, web REST API's return JSON data but are limited to the number of records they return.

Good API's also return the total number of records that could be returned along with the current offset (from start), the record limit and perhaps even a URL that lets you make the next call in the series.

Mailroute is a cloud service that pre-checks email for you, filtering out spam and viruses and letting you white-/black-list sending domains and email addresses.

It has a pretty good API that returns 20 records at a time. So, if you want to return a large number (all) of the white-/black-list entries, you need a flow that will loop through each recordset.

The attached flow does just that. It also makes use of links to keep the looping flow neat. Also uses JSONata in Change nodes instead of function nodes so reducing the level of JavaScript coding knowledge required.

@TotallyInformation
TotallyInformation / README.md
Created September 29, 2017 22:22
UIbuilder with MoonJS - simple, responsive UI

Here is a quick example using UIbuilder which is an alternative UI for Node-RED.

It demonstrates the use of a lightweight front-end library, MoonJS, which can be a lot faster and easier to work with than Node-RED's built-in Dashboard UI once you reach the point of needing to customise the UI beyond the standard capabilities of Dashboard.

This is a really quick demo of what you can do with uibuilder. MoonJS is a lightweight alternative to the likes of Angular (used by Dashboard), REACT, VueJS, etc. It is fast and really easy to use.

Here are the steps to set up (details given below):

  1. Install MoonJS & uibuilder using npm
@TotallyInformation
TotallyInformation / README.md
Last active September 7, 2019 17:36
JSONata Example: Changing topic and payload

OK, so I've been a bit slow in getting my head around JSONata. I knew it was going to be valuable but I've just had my first actual use case.

I needed to rebuild an output payload from several parts of the input so I could monitor inputs from an RFXtrx433E. I wired up all the input nodes from Max's RFX node, added a timestamp using my moment node then added a change node with 2 changes.

The first change alters the msg.topic - I wanted to add RFX/ to the beginning to push the MQTT output messages to a new, dedicated path. Here is the JSONata for that:

"RFX/" & topic
@TotallyInformation
TotallyInformation / README.md
Created May 13, 2017 18:37
Reliably Get Network IP Address

Your network IP address is the default address that other systems on your network will see as the "server" running Node-RED.

In many environments though, this address is remarkably hard to get hold of reliably. Particularly when you have multiple NIC's. Worse, many of the methods are totally different on different operating systems.

There is one fairly reliable method however, though it does require a connection to the Internet.

To make use of this, you first need to add a global function in settings.js

    functionGlobalContext: {
@TotallyInformation
TotallyInformation / nodered.conf
Created March 16, 2017 00:10 — forked from natcl/nodered.conf
Node-red startup file for Synology (/etc/init)
# only start this service after the httpd user process has started
#start on syno.network.ready
start on runlevel 2
# stop the service gracefully if the runlevel changes to 'reboot'
stop on runlevel [06]
# run the scripts as the 'admin' user. Running as root (the default) is a bad idea.
setuid admin
@TotallyInformation
TotallyInformation / README.md
Created December 21, 2016 23:38
Simple Windows Text to Speech

Windows from certainly at least version 7+ and the equivalent server versions have an excellent built-in Speech engine that does both text-to-speech and speech recognition.

The speech engine is written as a system library and so is easily called from PowerShell.

This flow makes use of that feature and uses the exec node to shell out to PowerShell, calling the speech engine using a one-line PowerShell script.

You send the text into the exec node and it passes it through.

See the comment node for some details. This is exactly the way that the popular say.js library works.

@TotallyInformation
TotallyInformation / README.md
Created September 3, 2016 17:15
Node-RED Process Details (Debugging, Linux)

This example flow will let you monitor the Operating System process details for your Node-RED instance.

To make this work, you need to know the PID (Process Identifier) of your Node-RED instance. The easiest way to do that is to grab it on startup and add it to the global variables from settings.js. Add the following to your settings.js file & restart NR:

...
functionGlobalContext: {
    'pid': process.pid
},
...