How to convert the IR sensor values into appropriate payload values (which were to be sent via mqtt)

hello this is my first post, I hope you can understand me and help me.

I want to control the leds of a partner through mqtt, this previously I had already achieved but this time I want to do it through an infrared sensor controlled by a control of the same type, I have tried a thousand ways but I can not do it.

Previously I did it with a script in arduino serializing by json and controlling with a dashboard switch that went to a mqtt node and so I could interact with its circuit but now as I said I want to do it with a control but I can not send anything.

1 Like

Hello and welcome to the forum.

You'll need to provide more information/details as I'm having a problem visualising your set-up.
For a start you could tell us the hardware you are using.
For example, have you got a Raspberry Pi acting as a broker and what hardware is your 'partner'?
You also mentioned Arduino. Are you using these sorts of devices?
A block diagram of your current set-up would be very useful.

1 Like

I'm really sorry Kevin but I'm not going to be of any further help as I've not used the serial comms link or infrared in this way. I'm sure someone else from the forum will jump-in and offer some guidance/help.

1 Like

Thank you very much for your time sir dave and I appreciate your intention, and I hope if anyone can help me.

Which bit isn't working?

1 Like

I can't send the infrared control data to my partner to turn on his leds.

Which bit of that isn't working? Getting the infrared sensor into node-red? Getting it from node-red to MQTT? Your partner picking it up from node-red?

I can get the sensor data to node-red, what I can no longer do is to use that data to get the leds to turn on.

I thought you were sending it to MQTT after you get it into node-red.

yes, I put it in mqtt to send it to my partner

or better explained I use the sensor data to pass them to a function node which is the part that I don't get to send it through a mqtt and thus interact with my partner's leds.
yes, I put it in mqtt to send it to my partner

or better explained I use the data of the sensor to pass them to a function node that is the part that I do not get to send it through a mqtt and thus interact with the leds of my partner.

So is the problem that you have the sensor data, but you don't know how to reformat it the right message to send via MQTT?

If that is the question then show us what the sensor data looks like in a debug node, and tell us what you need to send to MQTT.

1 Like

What MQTT values do you want to send for each of those? I think you said you already had it working from a dashboard switch so presumably you know what you want to send via MQTT.

That is the flow, not the message. What does the message that you send to MQTT look like?

2 Likes

OK, making progress at last. Draw up a table of sensor values to mqtt messages, then we just need to code that up.

1 Like

How do you know whether you want on or off?

1 Like

my partner Kevin has run out of replications for the day today.

by means of the number one and zero

The infra red sensor provides the values shown in the table, but what do you want to be sent to MQTT when each one of those is received?

First use a Switch node to send the message down three different paths, one for each sensor value. Use debug nodes to check that is working. When it is working then add a function node in each one of those three outputs containing

// Set these to the correct values for the led
const on_off_values = [{ "LED_5": 1, "LED_6": 2, "LED_7": 2 }, { "LED_5":0, "LED_6": 2, "LED_7": 2 }]
// get the current state
let state = context.get("state") || 0 // 0 for off, 1 for on
// flip the current state
state = state ? 0 : 1
// save it again
context.set("state", state)
msg.payload = on_off_values[state]
return msg;

Adjust the on_off_values there for each one. Again use debug nodes to check you are getting the right outputs. Then you should be able to send that to MQTT.

I think your table is wrong by the way, so you might want to check that.

1 Like

let's try it for a moment please