2 inputs function: mqtt & telegram?

#1

Hi there!
I'm very new to nodered (what a huge world to discover!)
I come to my 1st issue....
I would like to do something simple,but I cannot figure out how to do (even based on http://noderedguide.com/node-red-lecture-6-example-6-7-multiple-inputs-on-a-function-node/)

let's me explain the situation:
I would like to get the state of a tasmota sonoff switch as an answer to a telegram message.

Let's image I sent on my phone "light?" by telegram...I wish to received "on" or "off".
good point is that I have on mqtt a retained "stat" topic from the tasmota, so I can know anytime what is it's state.

So my idea was to draw:

  • an MQTT input node (with the relevant "stat" topic)
  • a telegram receive node.
    and join both their outputs on same "function" node...
    and here I'm stuck...the documentation talk about "topics"....ok for mqtt input...but telegram does not have topic?
0 Likes

#2

Hi,
One way would be to use a change node in the path of the tasmota and just set msg.topic to something.
Another way (as you only have two inputs) is to use the lack of a topic to indicate the other branch. So "if (msg topic == " whatever... else (it must be the other one (tasmota))

0 Likes

#3

I'm not 100% sure I understand your requirements but from what I can gather...

  1. Use a function node after MQTT to store status of light in a flow variable named "light".
  2. When you receive a telegram use a switch node to determine if the message is "light?". Connect the output to a function node to retrieve the value from your flow variable and pass it on as a msg.payload to the telegram node as a reply.

Clues.
Use flow.set('light', msg.payload); to store MQTT status in flow context and to retrieve it, var lightStat = flow.get('light');

0 Likes