node-red-contrib-lgtv-notify 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 rcaldeira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # node-red-contrib-lgtv-notify
2
+
3
+ Send toast notifications to LG webOS Smart TVs from Node-RED.
4
+
5
+ **Works with webOS 10+ (2025 TVs)** - Includes built-in SSL handling for newer TV firmware.
6
+
7
+ ## Features
8
+
9
+ - Simple toast notifications on your LG TV
10
+ - Works with webOS 3.0 and newer (including 2025 models)
11
+ - Automatic SSL certificate handling (no manual configuration needed)
12
+ - Auto-reconnection and message queuing
13
+ - Saves pairing key for seamless future connections
14
+
15
+ ## Installation
16
+
17
+ ### From Node-RED Palette Manager
18
+
19
+ 1. Open Node-RED
20
+ 2. Go to Menu > Manage palette > Install
21
+ 3. Search for `node-red-contrib-lgtv-notify`
22
+ 4. Click Install
23
+
24
+ ### From Command Line
25
+
26
+ ```bash
27
+ cd ~/.node-red
28
+ npm install node-red-contrib-lgtv-notify
29
+ ```
30
+
31
+ Then restart Node-RED.
32
+
33
+ ## Setup
34
+
35
+ 1. Drag an **LG TV notify** node onto your flow
36
+ 2. Double-click to configure
37
+ 3. Add a new TV configuration with your TV's IP address
38
+ 4. Deploy
39
+ 5. **Important:** Check your TV for a pairing prompt and accept it
40
+
41
+ After accepting the pairing prompt once, the node will remember the connection key.
42
+
43
+ ## Usage
44
+
45
+ ### Basic Example
46
+
47
+ ```
48
+ [inject] → [lgtv-notify]
49
+ ```
50
+
51
+ Set `msg.payload` to your notification message:
52
+
53
+ ```javascript
54
+ msg.payload = "Someone is at the front door!";
55
+ return msg;
56
+ ```
57
+
58
+ ### Home Automation Example
59
+
60
+ ```
61
+ [mqtt in] → [function] → [lgtv-notify]
62
+ doorbell format
63
+ ```
64
+
65
+ Function node:
66
+ ```javascript
67
+ msg.payload = "Doorbell: " + msg.payload;
68
+ return msg;
69
+ ```
70
+
71
+ ## Requirements
72
+
73
+ - LG webOS Smart TV (webOS 3.0 or newer)
74
+ - TV and Node-RED on the same network
75
+ - "LG Connect Apps" enabled on the TV
76
+ - Settings > General > External Device Manager > LG Connect Apps
77
+
78
+ ## Troubleshooting
79
+
80
+ ### TV not connecting
81
+
82
+ 1. Make sure the TV is powered on (not in standby)
83
+ 2. Check that "LG Connect Apps" is enabled
84
+ 3. Verify the IP address is correct
85
+ 4. The TV takes ~25 seconds after power-on before the API is available
86
+
87
+ ### Pairing prompt not appearing
88
+
89
+ - Restart Node-RED and redeploy the flow
90
+ - Try removing and re-adding the TV configuration
91
+
92
+ ### Notifications not showing
93
+
94
+ - Notifications only appear when the TV is on and displaying content
95
+ - Maximum message length is 60 characters
96
+
97
+ ## License
98
+
99
+ MIT
100
+
101
+ ## Credits
102
+
103
+ Built on [lgtv2](https://github.com/hobbyquaker/lgtv2) by Sebastian Raff.
@@ -0,0 +1,96 @@
1
+ <!-- LG TV Configuration Node -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('lgtv-config', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ host: { value: '', required: true }
8
+ },
9
+ credentials: {
10
+ clientKey: { type: 'text' }
11
+ },
12
+ label: function() {
13
+ return this.name || this.host || 'LG TV';
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="lgtv-config">
19
+ <div class="form-row">
20
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
21
+ <input type="text" id="node-config-input-name" placeholder="Living Room TV">
22
+ </div>
23
+ <div class="form-row">
24
+ <label for="node-config-input-host"><i class="fa fa-globe"></i> TV IP</label>
25
+ <input type="text" id="node-config-input-host" placeholder="192.168.1.100">
26
+ </div>
27
+ <div class="form-tips">
28
+ <p><strong>First connection:</strong> Accept the pairing prompt on your TV.</p>
29
+ <p>The TV must be on and "LG Connect Apps" must be enabled in TV settings.</p>
30
+ </div>
31
+ </script>
32
+
33
+ <!-- LG TV Notify Node -->
34
+ <script type="text/javascript">
35
+ RED.nodes.registerType('lgtv-notify', {
36
+ category: 'home automation',
37
+ color: '#A6BBCF',
38
+ defaults: {
39
+ name: { value: '' },
40
+ tv: { value: '', type: 'lgtv-config', required: true },
41
+ message: { value: '' }
42
+ },
43
+ inputs: 1,
44
+ outputs: 1,
45
+ icon: 'font-awesome/fa-television',
46
+ label: function() {
47
+ return this.name || 'LG TV Notify';
48
+ },
49
+ paletteLabel: 'LG TV notify',
50
+ inputLabels: 'notification message',
51
+ outputLabels: 'result'
52
+ });
53
+ </script>
54
+
55
+ <script type="text/html" data-template-name="lgtv-notify">
56
+ <div class="form-row">
57
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
58
+ <input type="text" id="node-input-name" placeholder="Name">
59
+ </div>
60
+ <div class="form-row">
61
+ <label for="node-input-tv"><i class="fa fa-television"></i> TV</label>
62
+ <input type="text" id="node-input-tv">
63
+ </div>
64
+ <div class="form-row">
65
+ <label for="node-input-message"><i class="fa fa-comment"></i> Message</label>
66
+ <input type="text" id="node-input-message" placeholder="Use msg.payload or enter default">
67
+ </div>
68
+ </script>
69
+
70
+ <script type="text/html" data-help-name="lgtv-notify">
71
+ <p>Send toast notifications to an LG webOS TV.</p>
72
+
73
+ <h3>Inputs</h3>
74
+ <dl class="message-properties">
75
+ <dt>payload <span class="property-type">string</span></dt>
76
+ <dd>The notification message to display on the TV.</dd>
77
+ </dl>
78
+
79
+ <h3>Outputs</h3>
80
+ <dl class="message-properties">
81
+ <dt>payload <span class="property-type">string</span></dt>
82
+ <dd>The original message.</dd>
83
+ <dt>toastId <span class="property-type">string</span></dt>
84
+ <dd>The ID of the created toast notification.</dd>
85
+ </dl>
86
+
87
+ <h3>Details</h3>
88
+ <p>This node sends a toast notification to an LG webOS Smart TV.</p>
89
+ <p>The notification will appear in the top-right corner of the TV screen for approximately 5 seconds.</p>
90
+ <p><strong>First use:</strong> When you first deploy, check your TV for a pairing prompt and accept it.</p>
91
+
92
+ <h3>References</h3>
93
+ <ul>
94
+ <li><a href="https://github.com/rcaldeira/node-red-contrib-lgtv-notify">GitHub</a> - the node's repository</li>
95
+ </ul>
96
+ </script>
@@ -0,0 +1,157 @@
1
+ // Disable SSL certificate verification for LG TV's self-signed certificates
2
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
3
+
4
+ module.exports = function(RED) {
5
+ const lgtv = require('lgtv2');
6
+
7
+ // Configuration node for TV connection
8
+ function LgtvConfigNode(config) {
9
+ RED.nodes.createNode(this, config);
10
+ const node = this;
11
+
12
+ this.host = config.host;
13
+ this.name = config.name || config.host;
14
+ this.connection = null;
15
+ this.connected = false;
16
+ this.connecting = false;
17
+ this.clientKey = null;
18
+ this.queue = [];
19
+
20
+ // Store client key in credentials
21
+ if (this.credentials && this.credentials.clientKey) {
22
+ this.clientKey = this.credentials.clientKey;
23
+ }
24
+
25
+ this.connect = function() {
26
+ if (node.connecting || node.connected) return;
27
+
28
+ node.connecting = true;
29
+
30
+ const options = {
31
+ url: `wss://${node.host}:3001`,
32
+ reconnect: false
33
+ };
34
+
35
+ if (node.clientKey) {
36
+ options.clientKey = node.clientKey;
37
+ }
38
+
39
+ node.connection = lgtv(options);
40
+
41
+ node.connection.on('error', (err) => {
42
+ node.error(`Connection error: ${err.message}`);
43
+ node.connected = false;
44
+ node.connecting = false;
45
+ });
46
+
47
+ node.connection.on('close', () => {
48
+ node.connected = false;
49
+ node.connecting = false;
50
+ });
51
+
52
+ node.connection.on('prompt', () => {
53
+ node.log('Pairing prompt shown on TV - please accept');
54
+ });
55
+
56
+ node.connection.on('connect', () => {
57
+ node.connected = true;
58
+ node.connecting = false;
59
+ node.log(`Connected to ${node.host}`);
60
+
61
+ // Save client key for future connections
62
+ if (node.connection.clientKey && node.connection.clientKey !== node.clientKey) {
63
+ node.clientKey = node.connection.clientKey;
64
+ node.credentials.clientKey = node.clientKey;
65
+ }
66
+
67
+ // Process queued messages
68
+ while (node.queue.length > 0) {
69
+ const msg = node.queue.shift();
70
+ node.sendToast(msg.message, msg.callback);
71
+ }
72
+ });
73
+ };
74
+
75
+ this.disconnect = function() {
76
+ if (node.connection) {
77
+ node.connection.disconnect();
78
+ node.connection = null;
79
+ }
80
+ node.connected = false;
81
+ node.connecting = false;
82
+ };
83
+
84
+ this.sendToast = function(message, callback) {
85
+ if (!node.connected) {
86
+ node.queue.push({ message, callback });
87
+ node.connect();
88
+ return;
89
+ }
90
+
91
+ node.connection.request(
92
+ 'ssap://system.notifications/createToast',
93
+ { message: message },
94
+ (err, res) => {
95
+ if (callback) callback(err, res);
96
+ }
97
+ );
98
+ };
99
+
100
+ this.on('close', function(done) {
101
+ node.disconnect();
102
+ done();
103
+ });
104
+ }
105
+
106
+ RED.nodes.registerType('lgtv-config', LgtvConfigNode, {
107
+ credentials: {
108
+ clientKey: { type: 'text' }
109
+ }
110
+ });
111
+
112
+ // Notify node
113
+ function LgtvNotifyNode(config) {
114
+ RED.nodes.createNode(this, config);
115
+ const node = this;
116
+
117
+ this.tv = RED.nodes.getNode(config.tv);
118
+ this.name = config.name;
119
+
120
+ if (!this.tv) {
121
+ node.error('No TV configured');
122
+ return;
123
+ }
124
+
125
+ node.status({ fill: 'grey', shape: 'dot', text: 'idle' });
126
+
127
+ this.on('input', function(msg, send, done) {
128
+ const message = msg.payload || config.message || 'Notification';
129
+
130
+ node.status({ fill: 'yellow', shape: 'dot', text: 'sending...' });
131
+
132
+ node.tv.sendToast(message, (err, res) => {
133
+ if (err) {
134
+ node.status({ fill: 'red', shape: 'dot', text: 'error' });
135
+ if (done) done(err);
136
+ else node.error(err, msg);
137
+ } else {
138
+ node.status({ fill: 'green', shape: 'dot', text: 'sent' });
139
+ msg.toastId = res.toastId;
140
+ send(msg);
141
+ if (done) done();
142
+
143
+ // Reset status after 3 seconds
144
+ setTimeout(() => {
145
+ node.status({ fill: 'grey', shape: 'dot', text: 'idle' });
146
+ }, 3000);
147
+ }
148
+ });
149
+ });
150
+
151
+ this.on('close', function() {
152
+ node.status({});
153
+ });
154
+ }
155
+
156
+ RED.nodes.registerType('lgtv-notify', LgtvNotifyNode);
157
+ };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "node-red-contrib-lgtv-notify",
3
+ "version": "1.0.0",
4
+ "description": "Send toast notifications to LG webOS TVs from Node-RED. Works with webOS 10+ (2025 TVs).",
5
+ "keywords": [
6
+ "node-red",
7
+ "lgtv",
8
+ "lg",
9
+ "webos",
10
+ "tv",
11
+ "notification",
12
+ "toast",
13
+ "smart-home",
14
+ "home-automation"
15
+ ],
16
+ "author": "rcaldeira",
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/rcaldeira/node-red-contrib-lgtv-notify"
21
+ },
22
+ "node-red": {
23
+ "version": ">=2.0.0",
24
+ "nodes": {
25
+ "lgtv-notify": "nodes/lgtv-notify.js"
26
+ }
27
+ },
28
+ "dependencies": {
29
+ "lgtv2": "^1.4.1"
30
+ },
31
+ "engines": {
32
+ "node": ">=14.0.0"
33
+ }
34
+ }