<%- vis.formatDate(item.pubdate, "TT.MM.JJJJ SS:mm") %>
<%- item.title %>
<%- item.description %>
Adapter and vis widget for rss feeds
npm install iobroker.rssfeedbash
iobroker upload rssfeed
`
In the right area in the line of the adapter, an instance can be added using the plus button
Configuration
The configuration is easy. There are only a few fields
| Setting | description |
| ---------------------- | ------------------------------------------------------------------------------------------------------------------ |
| Default Refresh (min) | is the general specification of how often the feed should be called up again in minutes. The default is 60 minutes |
| Max Artikel (Standard) | The total amount of data to be processed can be limited here. |
Then for each new feed:
| Setting | description |
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Name | A name for the datapoint. Inside a folder a name must not appear twice. |
| Category | Name for a subfolder there the datapoint should appear. |
| Url | The full address of the feed (with http: // or https: //, see examples below) |
| Refresh (min) | Time to refres/load the feed. A different value can be specified for this feed. Otherwise the general specification is taken |
| Max Articles | Number of Articles thare should be saved int the datapoint. A different value can be specified for this feed. Otherwise the general specification is taken |
If you saved and closed the configuration, the feed-data can be found as a JSON data point in the object tree.
If you delete an entry, the datapoints aren't deleted automatically.
vis and widgets
The following widgets actually exists
- RSS Feed widget 2 - to show a single feed
- RSS Feed Multi widget 3 - to show several aggregated feeds in one widget.
- RSS Feed Meta Helper - a helper widget to inspect the metadata of a feed
- RSS Feed Article Helper 2 - a helper widget to inspect the article data of a feed
- RSS Feed Title marquee 4 (deprecated) - a widget to show the Headlines of a feed as a marquee
- RSS Feed Title marquee 5 - a widget to show the Headlines of a feed as a marquee
- JSON Template 3 - a widget that have nothing todo with RSS Feeds, but uses the same technology, and you can define a custom template to show any JSON-Data in vis.
$3
This widget can be used to display the RSS feeds subscribed to in the adapter's configuration dialog.
With a template system, the output can be customized as desired. A simple standard template is already provided.
Descriptions of the formatting and syntax can be found on the following pages.
| Setting | description |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| rss_oid | Selecting the data point with the corresponding RSS feed. |
| rss_template | The template determines the appearance of the RSS feed. All valid HTML tags (including CSS attributes in style tags) can be used in the template. In addition, there are special tags within which the feed data is displayed and JavaScript instructions can be executed. In order to better identify the data and the attribute names used, there are two widgets, rssfeed Meta helper and rssfeed Article helper. |
| rss_maxarticles | The maximum number of individual articles displayed from the RSS feed |
| rss_filter | For the filter function, one or more filter criteria can be entered in the field, separated by semicolons (;). The following article attributes are searched for the search: title, description, categories. Only articles that contain one of these terms are displayed. |
Availability of variable:
- rss.meta: the meta information of the feed
- rss.articles: an array of all articles
- widgetid: the widgetID of the widget
- style: the style object if you configure additional style information
For more details about these variables, see chapter Available variables
For details on the template system, see chapter Template based on examples
$3
With this widget, several feeds can be aggregated in one feed.
Due to the multiple feeds, there are a few differences in the data availability in the template compared to the normal RSS feed widget.
The meta variable is not available in the template. However, 3 meta attributes title and description are available in each individual article under the names meta_title and meta_description.
In addition, a general name can be assigned to each feed in the settings, which is available within the template under the name meta_name in each article so that the origin of an article can be identified.
Otherwise, the same rules apply to the template as for the RSS feed widget.
| Setting | Group | description |
| --------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| rss_feedCount | General group | Here you can set the number of feeds to be configured. A separate group for configuration is created in vis for each feed. |
| rss_template | | The template determines the appearance of the RSS feed. All valid HTML tags (including CSS attributes in style tags) can be used in the template. In addition, there are special tags within which the feed data is displayed and JavaScript instructions can be executed. In order to better identify the data and the attribute names used, there are two widgets, rssfeed Meta helper and rssfeed Article helper. For details on the template system, see chapter Template based on examples |
| rss_dpCount | General group | Here you can specify the number of additional data points that should be made available within the template. |
| rss_dp[number] | General group | Here you can select the respective data point. The data point is available within the template under the variable dp. This means that a data point can be retrieved within the template as follows.For details on these variables, see chapter Available variables |
| rss_oid | Group feeds[number] | Selection of the data point with the corresponding RSS feed. |
| rss_name | Group feeds[number] | Here you can enter a name that will be made available in the template for each article under the attribute name meta_name. |
| rss_maxarticles | Group feeds[number] | The maximum number of individual articles displayed from the RSS feed |
| rss_filter | Group feeds[number] | For more details on these variables, see chapter Available variablesFor the filter function, one or more filter criteria can be entered in the field, separated by semicolons (;).The following article attributes are searched for the search: title, description, categories. Only articles that contain one of these terms are displayed. |
Availability of variable:
- rss.articles: an array of all articles.
- A subset of the the meta information of an item is available in the article as meta_name, meta_title and meta_description
- dp[] as array, if you configure additional datapoints
- widgetid: the widgetID of the widget
- style: the style object if you configure additional style information
$3
This widget can be used to display the meta attributes of a specific feed. It is simply used as an help widget for creating a template to quickly and easily display the contents of the RSS feed data.
Attributes
| Setting | description |
| ------- | ------------------------------------------------------------ |
| rss_oid | Selection of the data point with the corresponding RSS feed. |
$3
This widget can be used to display the article attributes of a specific feed. It is simply used as an help widget for creating a template to quickly and easily display the contents of the RSS feed data.
| Setting | description |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| rss_oid | Selection of the data point with the corresponding RSS feed. |
| rss_prefix | To make it easier to use the attribute names via copy/paste, the variable name used in the template for an article can be specified here. |
| rss_article | This attribute can be used to switch between the various existing articles in the RSS feed. |
$3
With this widget, all title attributes will be displayed as a scrolling text. As part of the change from marquee widget 2 to 3, this widget is now a multi widget in which you can aggregate more than one RSS feed.
| Setting | group | description |
| ---------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| rss_feedCount | General group | Here you can set the number of feeds to be configured. A separate group is created in vis for each feed to be configured. |
| rss_speed | General group | The scrolling speed of the scrolling text Attribute rss_divider - General group Here you can enter the characters used to separate the headlines. The default value is +++. |
| rss_pauseonhover | General group | If this option is switched on, the scrolling text stops as soon as you hover the mouse over the text. |
| rss_link | General group | If this option is switched on, the headlines are displayed as a link. If you click or touch a headline, the link to the article opens in a new window or tab. |
| rss_withtime | General group | If this option is switched on, the time is displayed before the respective headline. Attribute rss_withdate - General group If this option is enabled, the date without the year and the time are displayed before the respective headline. |
| rss_withyear | General group | If this option is enabled, the date with the year and the time are displayed before the respective headline. |
| rss_oid | Feeds[number] group | Select the data point with the corresponding RSS feed. |
| rss_maxarticles | Feeds[number] group | The maximum number of individual articles displayed from the RSS feed |
| rss_filter | Feeds[number] group | For the filter function, one or more filter criteria can be entered in the field, separated by semicolons (;). The following article attributes are searched for the search: title, description, categories. Only articles that contain one of these terms are displayed. |
$3
With this widget, all title attributes will be displayed as a scrolling text. As part of the change from marquee widget 2 to 3, this widget is now a multi widget in which you can aggregate more than one RSS feed.
| Setting | group | description |
| ---------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| rss_feedCount | General group | Here you can set the number of feeds to be configured. A separate group is created in vis for each feed to be configured. |
| rss_speed | General group | The scrolling speed of the scrolling text Attribute rss_divider - General group Here you can enter the characters used to separate the headlines. The default value is +++. |
| rss_pauseonhover | General group | If this option is switched on, the scrolling text stops as soon as you hover the mouse over the text. |
| rss_opentype | General group | Selection of how the link is opened: none, link, popup |
| rss_withtime | General group | If this option is switched on, the time is displayed before the respective headline. Attribute rss_withdate - General group If this option is enabled, the date without the year and the time are displayed before the respective headline. |
| rss_withyear | General group | If this option is enabled, the date with the year and the time are displayed before the respective headline. |
| rss_oid | Feeds[number] group | Select the data point with the corresponding RSS feed. |
| rss_maxarticles | Feeds[number] group | The maximum number of individual articles displayed from the RSS feed |
| rss_filter | Feeds[number] group | For the filter function, one or more filter criteria can be entered in the field, separated by semicolons (;). The following article attributes are searched for the search: title, description, categories. Only articles that contain one of these terms are displayed. |
$3
Using this widget, any data point with JSON data can be displayed as desired.
The display is done using a template format, which can be thought of as a combined form of HTML code + JavaScript + special tags that control the display of the JSON attributes.
JSON Template3 now supports async calls with await. JSON Template 2 is going to be deprecated in the future.
| Setting | description |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| rss_template | The template can be used to determine the appearance of the JSON data. All valid HTML tags (including CSS attributes in style tags) can be used in the template. There are also special tags within which the JSON data is displayed and JavaScript instructions can be executed. |
| json_oid | Selection of the data point with the corresponding JSON data. |
For details on the template system, see chapter Template based on examples
The JSON data is passed to the template with the prefix data. In addition, the current widgetID is also available as a variable so that it can be specified in individual CSS instructions.
#### Advanced use case
In the examples above, only the pure output was covered. The template can now also be enriched with HTML tags to achieve a specific layout. Here is an example:
`html
Output
<% for (var prop in data.oneobject) { %>
><%- "data.oneobject." + prop + " = " %> >
<%- data.oneobject[prop] %>
<% } %>
`
Result:
`text
data.oneobject.attribute1 = 1
data.oneobject.attribute2 = 2
`
(In Markdown colors arent visible)
#### Use case for async calls
Block 1:
call sendToAsync Function with await. This example calls a test function in the admin adapter.
Block 2:
stringify the result and output to html
Block 3:
definition of the sendToAsync function
`html
<% req = await sendToAsync("admin.0","selectSendTo",{test:"test"}); %>
<%- JSON.stringify(req) %>
<%
async function sendToAsync(instance, command, sendData) {
console.log(sendToAsync ${command} ${sendData});
return new Promise((resolve, reject) => {
try {
vis.conn.sendTo(instance, command, sendData, function (receiveData) {
resolve(receiveData);
});
} catch (error) {
reject(error);
}
});
}
%>
`
Result:
`text
[{"label":"Afghanistan","value":"AF"},{"label":"Åland Islands","value":"AX"},{"label":"Albania","value":"AL"}]
`
#### Use case for a database-supported task list
##### Introduction
This use case describes how to visualize and interactively modify
a to-do list from a MySQL database in ioBroker using
the >=rssfeed 3.5.0 adapter. The focus is on implementing a simple
status change via a button click. This concept serves as
a Proof of Concept (PoC) and can be included in future documentation.
---
##### Database Structure (MySQL)
First, a MySQL database named test is created. It contains a table test with the following fields:
- id: Unique ID for each entry
- todo: Title of the to-do entry
- action: Status of the entry (0 = in progress, 1 = completed)
###### SQL Code for Table Creation
Details
`sql
CREATE TABLE test (
id int(11) NOT NULL,
todo varchar(100) NOT NULL,
action int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO test (id, todo, action) VALUES
(1, 'Todo 1', 0),
(2, 'Todo 2', 1),
(3, 'Todo 3', 1),
(4, 'Todo 4', 0);
ALTER TABLE test
ADD PRIMARY KEY (id),
ADD UNIQUE KEY id (id),
ADD KEY idx (id);
ALTER TABLE test
MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
COMMIT;
`
---
##### Integration into ioBroker
###### SQL Adapter
To interact with the database, the ioBroker.sql adapter is required.
It is configured accordingly to connect to the MySQL database test.
Note that ioBroker automatically creates its own structures in the
database to store history data points.
###### RSSFeed Adapter & JSONTemplate Widget
For visualization, we use the JSONTemplate widget.
Important Notes:
- In vis 2, the widget is included in the vis-2-widget-ovarious adapter.
- In the future, this widget is planned to be integrated into ioBroker.jsontemplate once bluefox stabilizes the build chain.
##### Integration into VIS
We place the JSONTemplate widget and fill in the following fields:
###### Template Code
Details
`html
ID
Todo
Action
<%
let todos = await getTodo();
for (let i = 0; i < todos.length; i++) {
let todo = todos[i];
%>
<%- todo.id %>
<%- todo.todo %>
<%- getButton(todo.id, todo.action) %>
<% } %>
`
###### Data Point for Refreshing Content
To ensure updates are reflected after a status change,
we add the following local data point:
`text
local_trigger
`
This data point does not need to be explicitly created, as local_? data points are processed internally within VIS (see vis documentation).
##### Code Explanation
###### Template Structure
| Line | Content |
|-------|--------|
| 1-5 | CSS styles for button appearance |
| 6-11 | Table header with columns ID, Todo, Action |
| 12-16 | Fetching data from the MySQL database using getTodo() |
| 17-21 | Loop to display to-do entries with buttons |
| 23-28 | Global reference of the clicktodo() function |
| 30-37 | getButton() function to create a button with the current status |
| 38-44 | clicktodo() function to change the status via button click |
| 45-48 | getTodo() function to fetch data via the SQL adapter |
| 49-52 | setAction() function to update the database entry |
| 53-58 | sendToAsync() function to use async/await with vis.conn.sendTo() |
Templatesystem
Tags
The template system works with certain tags.
The tags used mean the following
| tag | description |
| ----- | ------------------------------------------------------------------- |
| <%= | The content of the contained expression / variable will be escaped. |
| <%- | The content of the contained expression / variable is unescaped. |
| <% | No output, is used for enclosed javascript instructions |
| %> | is generally a closing tag to complete one of the previous ones |
Everything that is outside of these tags is displayed exactly as it is or if it is HTML interpreted as HTML.
Within the template you have 2 predefined variables available
$3
For all the following examples the following json is used.
`json
{
"onearray": ["one", "two"],
"oneobject": {
"attribute1": 1,
"attribute2": 2
},
"onenumber": 123,
"onetext": "onetwothree"
}
`
Attributes could be output as follows
Template:
`html
<%- data.onenumber %> <%- data.onetext %>
`
Result:
`text
123 onetwothree
`
Arrays can be accessed via an index. The index always starts with 0. However, there are also fake arrays where the index does not start with 0 or even consists of text. Here the rules for objects apply. In the example above, this would be
Template:
`html
<%- data.onearray[0] %> <%- data.onearray[1] %>
`
Result:
`text
one two
`
If you try to output an array directly without an index, the template outputs all elements separated by commas
Template:
`html
<%- data.onearray %>
`
Result:
`text
one,two
`
Arrays can also consist of a collection of objects. The example here contains only a simple array. An example of arrays with objects will be given later.
Template:
`html
<% for (var i = 0; i < data.onearray.length ; i++ ) { %> <%- data.onearray[i] %>
<% } %>
`
Result:
`text
one two
`
Objects can contain individual attributes, arrays or objects again. This means that JSON data can be nested to any depth.
Attributes of an object can be addressed using dot notation or bracket notation. The dot notation only works if the attribute conforms to certain naming conventions (first character must be a letter, rest numbers or letters or underscore).
The bracket notation also works for attributes that do not conform to the naming convention.
Dot notation:
Template:
`html
<%- data.oneobject.attribute1 %>
`
Bracket notation:
Template:
`html
<%- data.oneobject["attribute1"] %>
`
Result for both examples:
`text
1
`
Loop over the attributes of an object
Template:
`html
<% for (var prop in data.oneobject) { %> <%- "data.oneobject." + prop + " = " +
data.oneobject[prop] %> <% } %>
`
Result:
`text
data.oneobject.attribute1 = 1
data.oneobject.attribute2 = 2
`
Available variables in templates
$3
This contains all meta information about the feed. The following content is available. I think the identifiers are self-explanatory. In the help I will describe them in more detail. or specify the content (some are arrays)
Only in Rss Feed widget 2, a complete set of the meta information is available
The usage in the template see in Template based on example
- meta.title
- meta.description
- meta.link
- meta.xmlurl
- meta.date
- meta.pubdate
- meta.author
- meta.language
- meta.image
- meta.favicon
- meta.copyright
- meta.generator
- meta.categories
$3
Is an array with individual elements (javascript array). Each element has the following properties.
So that it fits, for example, I will do the prefix item in front of it. But if you want you can choose that yourself. It only has to be named accordingly in the loop (forEach). Here, too, the identifiers are self-explanatory. Not all attributes are filled in every feed. The most important ones are already included in the template above.
The articles are available as rss.articles in RSS feed widget 2 and as articles in RSS feed multi widget 3
The usage in the template see in Template based on example
- item.title
- item.description
- item.summary
- item.link
- item.origlink
- item.permalink
- item.date
- item.pubdate
- item.author
- item.guid
- item.comments
- item.image
- item.categories
- item.source
- item.enclosures
Template based on examples
$3
The following template is currently used as standard in the RSS feed widget 2.
It has been tested with the following feeds
- or
-
`html
<%- rss.meta.title %>
<% rss.articles.forEach(function(item){ %>
<%- vis.formatDate(item.pubdate, "TT.MM.JJJJ SS:mm") %>
<%- item.title %>
<%- item.description %>
<% }); %>
`
$3
The following template is currently used as standard in the RSS feed multi widget 3.
Please note little differences in the usage of the variables
It has been tested with the following feeds
`html
<% rss.articles.forEach(function(item){ %>
<%- item.meta_name || item.meta_title || '' %>
<%- vis.formatDate(item.pubdate, "TT.MM.JJJJ SS:mm") %>
<%- item.title %>
<%- item.description %>
<% }); %>
`
$3
`html
<% rss.articles.forEach(function(item){ %>
<% }); %>
`
$3
`html
<%= meta.title %> <% articles.forEach(function(item){ %>
<%- vis.formatDate(item.pubdate, "TT.MM.JJJJ SS:mm") %>
<%- item.title %>
<%- item.description %>
<% }); %>
``