MQTT forwarding message based on received message

Hi there,
After googling for more than need (which means more than 5 minutes :slight_smile: ), I've decided to ask my question here, even if it's simple, already answered but never found. Here is the context :

I have a flow to power on/off dim up/down a light if a remote button is pressed. Simple no ?
I've designed my flow actually with HomeAssistant integration, but I don't know why, time to time, commands are not passed throw light, so I've decided to create a full Node-Red MQTT flow, bypassing HomeAssistant

With the process of getting HA away, I'm blocked on 2 steps :

  1. replace command "Etat Lampe Couloir" [State of light] -> answer is ON or OFF
  2. send a MQTT msg to my light to switch on/off

I can do it with the Inject command, but I need to click on it which is not a good option in automation :slight_smile:

[{"id":"be79b0d9.6ec8a","type":"tab","label":"REZ_Cuisine_Couloir","disabled":false,"info":""},{"id":"f994533b.f0502","type":"mqtt in","z":"be79b0d9.6ec8a","name":"","topic":"zigbee2mqtt/REZ_Remote_P2","qos":"2","datatype":"auto","broker":"722c39fb.209b88","x":340,"y":400,"wires":[["ea3697f9.64ae48"]]},{"id":"ea3697f9.64ae48","type":"json","z":"be79b0d9.6ec8a","name":"","property":"payload","action":"","pretty":false,"x":550,"y":400,"wires":[["e27f8df4.812be"]]},{"id":"e27f8df4.812be","type":"switch","z":"be79b0d9.6ec8a","name":"Actions","property":"payload.action","propertyType":"msg","rules":[{"t":"eq","v":"on-press","vt":"str"},{"t":"eq","v":"off-press","vt":"str"},{"t":"eq","v":"down-press","vt":"str"},{"t":"eq","v":"up-press","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":680,"y":400,"wires":[["dc860dbb.4adbf"],["4880d6b1.c6a0c8"],["7898dba5.571234"],["5bba0ad7.e88594"]]},{"id":"4880d6b1.c6a0c8","type":"api-call-service","z":"be79b0d9.6ec8a","name":"Couloir off","server":"b589fe88.10c7b","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"group.rez_cuisine_couloir_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":360,"wires":[[]]},{"id":"7898dba5.571234","type":"api-call-service","z":"be79b0d9.6ec8a","name":"Couloir down","server":"b589fe88.10c7b","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"group.rez_cuisine_couloir_light","data":"{\"brightness_step_pct\":-10}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":420,"wires":[[]]},{"id":"5bba0ad7.e88594","type":"api-call-service","z":"be79b0d9.6ec8a","name":"Couloir up","server":"b589fe88.10c7b","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"group.rez_cuisine_couloir_light","data":"{\"brightness_step_pct\":10}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":480,"wires":[[]]},{"id":"5aafb6f3.c03c48","type":"function","z":"be79b0d9.6ec8a","name":"Profile Cycle","func":"var HueProfile = { \n    \"detente\" : {\n        \"color\" : {\n            \"xy_color\" : [0.5016,0.4151],\n            \"brightness\" : 144\n        },\n        \"mono\" : {\n            \"color_temp\" : 443,\n            \"brightness\" : 144\n        }\n    },\n    \"concentration\" : {\n        \"color\" : {\n            \"xy_color\" : [0.3691,0.3716],\n            \"brightness\" : 254\n        },\n        \"mono\" : {\n            \"color_temp\" : 233,\n            \"brightness\" : 254\n        }\n    },\n    \"stimulation\" : {\n        \"color\" : {\n            \"xy_color\" : [0.3146,0.3303],\n            \"brightness\" : 254\n        },\n        \"mono\" : {\n            \"color_temp\" : 443,\n            \"brightness\" : 144\n        }\n    },\n    \"lecture\" : {\n        \"color\" : {\n            \"xy_color\" : [0.445,0.4067],\n            \"brightness\" : 254\n        },\n        \"mono\" : {\n            \"color_temp\" : 343,\n            \"brightness\" : 254\n        }\n    },\n    \"lumineux\" : {\n        \"color\" : {\n            \"xy_color\" : [0.4578,0.41],\n            \"brightness\" : 254\n        },\n        \"mono\" : {\n            \"color_temp\" : 367,\n            \"brightness\" : 254\n        }\n    },\n    \"attenue\" : {\n        \"color\" : {\n            \"xy_color\" : [0.4575,0.4099],\n            \"brightness\" : 77\n        },\n        \"mono\" : {\n            \"color_temp\" : 367,\n            \"brightness\" : 77\n        }\n    }\n}\nvar ActualProfile = global.get('group.rez_cuisine_couloir.profile') || 0;\nvar result = {};\n\nnode.warn([\"ActualProfile=\",ActualProfile]);\nnode.warn([\"Input Payload=\",msg.payload]);\nif (msg.payload.action === \"on\") {\n    switch (ActualProfile)\n    {\n        case \"detente\":\n            node.warn([\"Switch=Detente\"]);\n            global.set(\"group.rez_cuisine_couloir.profile\", \"concentration\");\n            break;\n        case \"concentration\":\n            node.warn([\"Switch=concentration\"]);\n            global.set(\"group.rez_cuisine_couloir.profile\", \"stimulation\");\n            break;\n        case \"stimulation\":\n            node.warn([\"Switch=stimulation\"]);\n            global.set(\"group.rez_cuisine_couloir.profile\", \"lumineux\");\n            break;\n        case \"lumineux\":\n            node.warn([\"Switch=lumineux\"]);\n            global.set(\"group.rez_cuisine_couloir.profile\", \"detente\");\n            break;\n        default:\n            node.warn([\"Switch=Default\"]);\n            global.set(\"group.rez_cuisine_couloir.profile\", \"detente\");\n            break;\n    }\n} else {\n    node.warn([\"Else IF\"]);\n    global.set(\"group.rez_cuisine_couloir.profile\", \"detente\");\n}\nresult.payload = { data: {\"color_temp\":HueProfile[global.get('group.rez_cuisine_couloir.profile')].mono.color_temp,\n                          \"brightness\":HueProfile[global.get('group.rez_cuisine_couloir.profile')].mono.brightness} };\n\nreturn result;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1130,"y":280,"wires":[["7df7e879.670ef8"]]},{"id":"dc860dbb.4adbf","type":"api-current-state","z":"be79b0d9.6ec8a","name":"Etat lampe Couloir","server":"b589fe88.10c7b","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"group.rez_cuisine_couloir_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":910,"y":300,"wires":[["5aafb6f3.c03c48"]]},{"id":"7df7e879.670ef8","type":"api-call-service","z":"be79b0d9.6ec8a","name":"Couloir off","server":"b589fe88.10c7b","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"group.rez_cuisine_couloir_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1170,"y":360,"wires":[[]]},{"id":"722c39fb.209b88","type":"mqtt-broker","name":"MQTT","broker":"10.10.0.22","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"b589fe88.10c7b","type":"server","name":"Hass.io","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Any kind of help would be very welcome.

nobody can help me ?

Possibly because no-one understood your problem.

I don't understand what that means. Do you mean you have something in the payload and wish to change it to something else? If so then exactly what do you want to change to what?

For 2, if you mean that you want to send the changed payload to an mqtt node then connect the output of the node doing the change to the MQTT node.

Thanks you Colin for reply. It seems to be clear in my mind but not in community mind :slight_smile:

In other words, I want to request zigbee network to know if a light is on or off and replace other commands such as send a power off command, light up or down.
Hope it's more clear in popular minds...

Not really, as I know nothing about zigbee. Do you know how to do any of that? Your original question gave the impression it was just converting some values to different values and sending them to MQTT, so what I was asking for is what are the input messages like and what do the output messages look like. If your question is actually about zigbee then you need someone who knows about that.

You're right this is about Zigbee and how to send a message (json) from the node-red components

Since you didn't mention zigbee in the thread title it may be that no one who knows the answer will see the question. I suggest you start a new thread with a title that describes the question, and try and give a more detailed description of what you need to know. Read you question back before posting it and ask yourself if someone who knows nothing about your system will have enough information to understand what you are doing.