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.
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.
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.
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?
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.
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.
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.