Hello everyone,
As an absolute newcomer to Node Red, I have now implemented my complete shutter control system in Node Red with the help of a YouTube video.
I have to admit, however, that I have taken over a large part and only made small changes to adapt it to my system.
Nevertheless, I find that Node Red is clearer than the automations in HA, especially for more complex requirements.
I would therefore like to delve a little deeper into NR and implement 1-2 projects myself. I have some questions in advance as to whether this is possible, how it can be done better and possibly also tips (links where I can find help on similar projects)
Evaluate alarm situation switching states, report to Telegram and switch additional function
Here I have previously created a message via the HA automation (alarm system switched on and alarm system switched off), whereby the change between the switching states is monitored in the automations in HA and then a corresponding message is sent to Telegram.
The switching states of the alarm system are supported by HA (alarm off, alarm home on/off, alarm full on/off, alarm area X on/off).
How can I do this via NR? (The Telegram connection is already up and running).
Send all important messages in HA to Telegram (extension to 1.)
Do I have the possibility to integrate other āvariables/entitiesā so that I have a central NR board for all messages, which I then send to Telegram with different texts?
Yes itās code and HA is a fully featured platform. If you can dream it up you can probably write it.
Read the docs.in short thereās a collection of nodes in NR just for accessing HA. Thereās a node that will fire every time a entity state changes and put the state on the flow. You start with that.
Yes. See above. Thereās tons of node types. Too many to name. Just get started building flows and kick the tires.
Iāve now got to the point where every status change is sent to Telegram.
I have stored the texts in functions, there is certainly still a lot to optimize here, as I have not yet been able to address 2 Telegram IDs simultaneously in one functionā¦ but that will probably still happen.
The basic functions are in place and tested, the āoldā HA automation is deactivated and IFTTT is no longer required.
I think I need to work a bit more with the strings under NR, they still cause me problems as a newcomer (several Telegram IDs in one function, formatting and variablesā¦ You grow with your tasksā¦
Just a note here. Jsonata is for use in HA nodes and nodered nodes except for a function node. Function nodes use javascript. You can use either w3 or mdn for reference of how to deal with different types of data.
If you need further help please export and post your flow.
Basically everything is running smoothly. However, I have made the workflow simple so that it works first.
The status change disarmed/armed_home/armed_away call a function (3 statuses)
The function passes a text matching the status
I use one function each, because I somehow havenāt figured out how to send the text to 2 Telegram IDs at the same timeā¦
Optimization 1 would be:
Status change via one node (if possible)
Optimization 2 would be:
Customize the functions (one?) so that it takes all status changes into account and sends the corresponding message to 2 Telegram IDās.
You can use one event state by leaving state blank. It will send all state changes this way. Delete message data and topic output by clicking the x so that payload = entity state is the only output.
const alarmState = msg.payload;
// create empty msg. this clears all incoming messages parts
msg = {};
// create an empty string text
let text = '';
if (alarmState == 'armed_away') {
text = 'Armed away text';
}
else if ( alarmState == 'armed_home') {
text = 'Armed home text';
}
else if ( alarmState == 'disarmed') {
text = 'Disarmed text';
}
else { // this is a catch all should the state not match any of the above
text = 'Alarm state is not available';
}
msg.payload = { chatID: 'id1 here', type: "message", content: text};
node.send(msg);
//slight delay between messages
setTimeout(() => {
msg.payload = { chatID: 'id2 here', type: "message", content: text };
node.send(msg);
}, 500);// delay in milliseconds
I tried to implement the whole thing today. I came across an error that I canāt get rid of.
I have done everything as described. The status change is recognized and passed correctly according to the debug. However, the function cannot be sent because errors occur here.
I have (among other things) already tried to send the chat ID differently (āChat IDā changed to Chat ID). Unfortunately, nothing helps.
ā¦
I have now found the error!
the ChatID must be entered as a pure number, i.e. 12345678 not ā12345678ā (no apostrophe character)
The ChatId spelling is important (the D must be a small d)
I compared the output with my non-cortable solution and then saw/correlated the differences in the debug.
Now everything works, thank you very much, without you I would not have been able to do it so quickly!!!