How to best re-use with a sub-flow with different payload for telegram?

I’m able to configure a node-red flow like below, when front door open, telegram will send “front door open” to my telegram account.

front door open → conversation node → text node (with value “front door open”) → telegram sender

it works fine.

Now how do I re-use the same flow but for back door open, with text node value of “back door open”?

I can copy and paste and change the value, but I don’t think this is the best way? For example actually if this can be re-used, it can applied to many status change notification.

Thanks!

Assuming you have friendly names set for each.

[{"id":"83d87e9f.e237","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.front_door,sensor.back_door","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"open","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":238,"y":704,"wires":[["ff2daafa.b76198"],[]]},{"id":"ff2daafa.b76198","type":"template","z":"ffbd7f06.4a014","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{data.attributes.friendly_name}} open","output":"str","x":524,"y":704,"wires":[["c28e3afd.058868"]]},{"id":"c28e3afd.058868","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":678,"y":704,"wires":[]}]
1 Like

I run EVERYTHING that I want notifications in Telegram through a subflow that uses a few different functions to determine a few things for the message:

  • Unit of measurement (percent, degrees, etc)
  • Friendly name
  • What verb to use (House alarm IS armed, Phone battery IS AT X%, Intrusion detection HAS BEEN breached, Multiple devices ARE in this state)

This allows me to have ONE Telegram sender.

image

1 Like

Yes I do have just one telegram sender, and others just link to that to send.

I think my question is how to reuse conversation and text node as well.

As far as I read, in order to send to telegram, we need add a conversation node, then followed by a text node, how do we pass those entity friendly name through conversation node?

Those are attributes you can use from events. So you just use the attribute property.

What do you mean? Every message that comes through has all those properties. There’s nothing special you need to do to pass that data through

1 Like

I see, thanks!

Got the whole flow kind of working after try and error. Purpose is to notify me every 10 minutes if front door is open.
Seems that I need to add blank text node after template node, otherwise it doesn’t work.
Also in the debug window, I saw that conversation node and text node emit below, is this normal? or there is error in my setup?

12/29/2019, 1:42:23 PM node: telegram conversation
msg : string[0]
""
12/29/2019, 1:42:23 PM node: 830b7c95.868e3
msg : string[0]
""

[{"id":"5e2ef1a8.03fef","type":"server-state-changed","z":"2f511d14.797992","name":"Front Door Open","server":"e8b4e59e.644ec8","version":1,"entityidfilter":"binary_sensor.front_door","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":120,"y":60,"wires":[["1bbdc881.0d2177"],[]]},{"id":"1bbdc881.0d2177","type":"ha-wait-until","z":"2f511d14.797992","name":"","server":"e8b4e59e.644ec8","outputs":2,"entityId":"binary_sensor.front_door","property":"state","comparator":"is_not","value":"on","valueType":"str","timeout":"10","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":380,"y":100,"wires":[[],["a4f10c53.28562","9e54f19c.e5f2"]]},{"id":"a4f10c53.28562","type":"function","z":"2f511d14.797992","name":"placeholder","func":"\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":40,"wires":[["1bbdc881.0d2177"]]},{"id":"9e54f19c.e5f2","type":"chatbot-conversation","z":"2f511d14.797992","name":"telegram conversation","botDevelopment":"d1f7aac3.9c2a98","botProduction":"","chatId":"xxxxxxxx","userId":"","transport":"telegram","store":"","x":660,"y":80,"wires":[["fa5d9660.1c0218"]]},{"id":"830b7c95.868e3","type":"chatbot-message","z":"2f511d14.797992","name":"","message":[{"message":""}],"answer":false,"silent":false,"x":970,"y":80,"wires":[["4257cbfd.fb8a94"]]},{"id":"4257cbfd.fb8a94","type":"link out","z":"2f511d14.797992","name":"","links":["55e9507d.041bd"],"x":1045,"y":80,"wires":[]},{"id":"fa5d9660.1c0218","type":"template","z":"2f511d14.797992","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{data.new_state.attributes.friendly_name}} open","output":"str","x":830,"y":80,"wires":[["830b7c95.868e3"]]},{"id":"e8b4e59e.644ec8","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

add this in your text node.

I added but didn’t make a difference. Seems the payload is passed by default. Those two notes still split empty msgs. I also saw error log from the node-red container like below:

29 Dec 18:38:02 - [error] [chatbot-conversation:9e54f19c.e5f2]
29 Dec 18:38:02 - [error] [chatbot-message:830b7c95.868e3]

The msg sent to telegram seems correct though.