I am using the Node-red installed from Home Assistant v0.72.1 (Hass.os)
This flow contains the following nodes:
inject, MQTT-in, MQTT-out, Function, Debug, Home Assistant Call Service.
What I am building is an IR-MQTT bridge where the hardware (an ESP8266-01) receives IR from any remote and publishes the IR Code (in Hex).
Any MQTT client can subscribe to the IRCode topic and handle codes as needed. In this case, this Node-Red flow is going to work as a remote for my Family Room Fios PVR. (We have a monitor in the basement that displays the A/V from the PVR. It's cheaper than renting another STB). The Home Assistant Call Service nodes are sending Turn_on service to a Broadlink Mini in the Family Room.
As I said before, I have a workaround where I put the Domain and Service in the Home Assistant Service Call node, then decide in the first Function node which Call Service node to send the flow to. I should be able to put the domain and service data into msg.payload going into the Home Assistant Call Service node, but I just can't figure that out.
[{"id":"bbc57818.901578","type":"mqtt in","z":"4820e6f6.309498","name":"","topic":"IRData","qos":"0","broker":"a5f4b39c.527e6","x":180,"y":160,"wires":[["436ad5bb.3c4eec","808b664a.f9b3a8"]]},{"id":"60705f51.0fb36","type":"mqtt out","z":"4820e6f6.309498","name":"","topic":"","qos":"1","retain":"","broker":"a5f4b39c.527e6","x":750,"y":220,"wires":[]},{"id":"436ad5bb.3c4eec","type":"debug","z":"4820e6f6.309498","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":430,"y":140,"wires":[]},{"id":"47eff4ce.7140fc","type":"inject","z":"4820e6f6.309498","name":"Toggle Sidelight","topic":"","payload":"A93A4","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":260,"wires":[["808b664a.f9b3a8"]]},{"id":"808b664a.f9b3a8","type":"function","z":"4820e6f6.309498","name":"Process the MQTT payload (2a)","func":"// This function routes the incoming MQTT messages containing an IR Code.\n// Output 1 goes to an MQTT-Out node.\n// Output 2 goes to a Home Assistant Call Service node for turn_on\n// Output 3 goes to a Home Assistant Call Service node for turn_off\n\nvar payload=msg.payload;\nvar newMsg;\nswitch (payload){\n // MQTT outputs\n case \"A93A4\":\n msg = { payload: \"TOGGLE\",topic:\"sidetable/light/cmnd/power\"};\n return [ msg, null, null ];\n case \"333A2\":\n msg = { payload: \"ON\",topic:\"sidetable/light/cmnd/power\"};\n return [ msg, null, null ];\n\n case \"133A4\":\n msg = { payload: \"OFF\",topic:\"sidetable/light/cmnd/power\"};\n return [ msg, null, null ];\n\n case \"693A4\":\n msg = { payload: \"TOGGLE\",topic:\"cmnd/DeskLight/power\"};\n return [ msg, null, null ];\n\n case \"EB3A4\":\n msg = { payload: \"ON\",topic:\"cmnd/DeskLight/power\"};\n return [ msg, null, null ];\n\n case \"6B3A4\":\n msg = { payload: \"OFF\",topic:\"cmnd/DeskLight/power\"};\n return [ msg, null, null ];\n\n case \"D3A4\":\n msg = { payload: \"ON\",topic:\"cmnd/studioheat/power\"};\n return [ msg, null, null ];\n\n case \"8D3A4\":\n msg = { payload: \"OFF\",topic:\"cmnd/studioheat/power\"};\n return [ msg, null, null ];\n\n\n // Home Assistant Call Service, Turn_on \n //FIOS 6\n case \"D93A4\":\n msg.payload= {\"data\":{\"entity_id\":\"switch.fios_6\"}};\n\t return [ null, msg, null ];\n //FIOS 0\n case \"593A4\":\n msg.payload= {\"data\":{\"entity_id\":\"switch.fios_0\"}};\n\t return [ null, msg, null ];\n //FIOS 3\n case \"393A4\":\n msg.payload= {\"data\":{\"entity_id\":\"switch.fios_3\"}};\n\t return [ null, msg, null ];\n\n\n}\nreturn \"\";\n","outputs":3,"noerr":0,"x":450,"y":280,"wires":[["60705f51.0fb36"],["27cfafaf.92275"],[]]},{"id":"d3d713fd.65f78","type":"inject","z":"4820e6f6.309498","name":"FIOS 6","topic":"","payload":"D93A4","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":340,"wires":[["808b664a.f9b3a8"]]},{"id":"27cfafaf.92275","type":"api-call-service","z":"4820e6f6.309498","name":"","server":"1a3c51f6.4b493e","service_domain":"homeassistant","service":"turn_on","data":"","mergecontext":"","x":920,"y":300,"wires":[[]]},{"id":"2f4e8c8e.f3c3c4","type":"inject","z":"4820e6f6.309498","name":"FIOS 0","topic":"","payload":"593A4","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":380,"wires":[["808b664a.f9b3a8"]]},{"id":"47384cba.c02e74","type":"inject","z":"4820e6f6.309498","name":"FIOS 3","topic":"","payload":"393A4","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":420,"wires":[["808b664a.f9b3a8"]]},{"id":"a5f4b39c.527e6","type":"mqtt-broker","z":"","name":"Marvin","broker":"192.168.1.124","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"1a3c51f6.4b493e","type":"server","z":"","name":"Home Assistant- Raspberry","url":"http://localhost:8123","pass":"raspberry"}]