Hi All,
I am fairly new to node-red and have made a flow for controlling my Xbox, AV Receiver, Projector and Lights in my Media Room. The goal is to ask Alexa to either just enable Gaming Mode which just turns everything on or turn on a specific game which turns everything on, if its not already, and then start the game. I have the flow working but there’s a lot of spaghetti so I’m wondering if there is a smarter way to achieve this.
[
{
"id": "9879bffe.2be56",
"type": "tab",
"label": "Media Room",
"disabled": false,
"info": ""
},
{
"id": "d39dc354.49feb",
"type": "link in",
"z": "9879bffe.2be56",
"name": "Alexa In",
"links": [
"dff1328c.941a6"
],
"x": 65,
"y": 100,
"wires": [
[
"3ae81e9840f3b68f",
"38663ed8401afb54",
"65eb907a374594de"
]
]
},
{
"id": "dc72ed9d.68814",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn on Projector",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "remote",
"service": "send_command",
"areaId": [],
"deviceId": [],
"entityId": [
"remote.media_room_remote"
],
"data": "{\"command\":\"turn_on\",\"device\":\"media_room_projector\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1170,
"y": 100,
"wires": [
[]
]
},
{
"id": "97daa3c2.0dc6d",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn on AV",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "remote",
"service": "send_command",
"areaId": [],
"deviceId": [],
"entityId": [
"remote.media_room_remote"
],
"data": "{\"command\":\"power\",\"device\":\"media_room_av\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1150,
"y": 160,
"wires": [
[
"ea44579f.9d1db8"
]
]
},
{
"id": "ea44579f.9d1db8",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Set Input to Game",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "remote",
"service": "send_command",
"areaId": [],
"deviceId": [],
"entityId": [
"remote.media_room_remote"
],
"data": "{\"command\":\"game\",\"device\":\"media_room_av\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1370,
"y": 160,
"wires": [
[
"2e956646.e5ff3a"
]
]
},
{
"id": "2e956646.e5ff3a",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Mute AV",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "remote",
"service": "send_command",
"areaId": [],
"deviceId": [],
"entityId": [
"remote.media_room_remote"
],
"data": "{\"command\":\"mute\",\"device\":\"media_room_av\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1580,
"y": 160,
"wires": [
[]
]
},
{
"id": "5adaed27.ce4a74",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn on Rear Light - 10%",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_on",
"areaId": [],
"deviceId": [],
"entityId": [
"light.media_room_back_light"
],
"data": "{\"brightness_pct\":\"10\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1190,
"y": 220,
"wires": [
[]
]
},
{
"id": "ba2c5358.51ac6",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn off Front Light",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_off",
"areaId": [],
"deviceId": [],
"entityId": [
"light.media_room_front_light"
],
"data": "",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1170,
"y": 280,
"wires": [
[]
]
},
{
"id": "1520f6f2.34af79",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Gaming Mode Enabled",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "notify",
"service": "alexa_media",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"target\":\"media_player.media_room_echo_dot\",\"message\":\"Gaming Mode Enabled!\",\"data\":{\"type\":\"tts\"}}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1180,
"y": 400,
"wires": [
[]
]
},
{
"id": "3bb3454244c77d13",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn off Projector",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "remote",
"service": "send_command",
"areaId": [],
"deviceId": [],
"entityId": [
"remote.media_room_remote"
],
"data": "{\"command\":\"turn_off\",\"device\":\"media_room_projector\",\"num_repeats\":\"2\",\"delay_secs\":\"2\"}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1170,
"y": 520,
"wires": [
[]
]
},
{
"id": "8936a5cadd4b229c",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn off Media Room Lights",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "light",
"service": "turn_off",
"areaId": [
"ce6faed16c5646febd6fbfb209c0063b"
],
"deviceId": [],
"entityId": [],
"data": "",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1200,
"y": 580,
"wires": [
[]
]
},
{
"id": "3ae81e9840f3b68f",
"type": "amazon-echo-device",
"z": "9879bffe.2be56",
"name": "Gaming Mode",
"topic": "",
"x": 240,
"y": 100,
"wires": [
[
"195993283e1176f5"
]
]
},
{
"id": "195993283e1176f5",
"type": "switch",
"z": "9879bffe.2be56",
"name": "Gaming Mode",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 520,
"y": 100,
"wires": [
[
"dc72ed9d.68814",
"97daa3c2.0dc6d",
"5adaed27.ce4a74",
"ba2c5358.51ac6",
"1520f6f2.34af79",
"10f16f029c479329"
],
[
"3bb3454244c77d13",
"8936a5cadd4b229c",
"23e2cec2c810d949",
"4782b243acc7822e"
]
]
},
{
"id": "23e2cec2c810d949",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Gaming Mode Disabled",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "notify",
"service": "alexa_media",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"target\":\"media_player.media_room_echo_dot\",\"message\":\"Gaming Mode Disabled!\",\"data\":{\"type\":\"tts\"}}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1190,
"y": 640,
"wires": [
[]
]
},
{
"id": "10f16f029c479329",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn on Xbox",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "media_player",
"service": "turn_on",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1160,
"y": 340,
"wires": [
[]
]
},
{
"id": "4782b243acc7822e",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn off Xbox",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": true,
"domain": "media_player",
"service": "turn_off",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1150,
"y": 700,
"wires": [
[]
]
},
{
"id": "38663ed8401afb54",
"type": "amazon-echo-device",
"z": "9879bffe.2be56",
"name": "Destiny",
"topic": "",
"x": 220,
"y": 160,
"wires": [
[
"e7a63f2248054581"
]
]
},
{
"id": "83e206a7625009f7",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Launch Destiny",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "media_player",
"service": "play_media",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "{\"media_content_id\":\"BPQ955FQFPH6\",\"media_content_type\":\"game\"}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1720,
"y": 820,
"wires": [
[
"1f645ea59eb91e4d"
]
]
},
{
"id": "e7a63f2248054581",
"type": "switch",
"z": "9879bffe.2be56",
"name": "Play Destiny",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 510,
"y": 160,
"wires": [
[
"dc72ed9d.68814",
"5adaed27.ce4a74",
"ba2c5358.51ac6",
"ae11003b02034c84"
],
[
"3bb3454244c77d13",
"8936a5cadd4b229c",
"23e2cec2c810d949",
"4782b243acc7822e"
]
]
},
{
"id": "1f645ea59eb91e4d",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "It's Destiny time",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "notify",
"service": "alexa_media",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"target\":\"media_player.media_room_echo_dot\",\"message\":\"It's Destiny time!\",\"data\":{\"type\":\"tts\"}}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2040,
"y": 820,
"wires": [
[]
]
},
{
"id": "94615505f4453067",
"type": "ha-wait-until",
"z": "9879bffe.2be56",
"name": "Wait for Xbox to turn on",
"server": "f8a50b9a.39c988",
"version": 1,
"outputs": 1,
"entityId": "media_player.media_room_series_x",
"entityIdFilterType": "exact",
"property": "state",
"comparator": "is",
"value": "on",
"valueType": "str",
"timeout": "0",
"timeoutType": "num",
"timeoutUnits": "minutes",
"entityLocation": "data",
"entityLocationType": "none",
"checkCurrentState": true,
"blockInputOverrides": true,
"x": 1470,
"y": 820,
"wires": [
[
"83e206a7625009f7"
]
]
},
{
"id": "6c8ca67ae6bdeb02",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn on Xbox",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "media_player",
"service": "turn_on",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1160,
"y": 820,
"wires": [
[
"94615505f4453067"
]
]
},
{
"id": "65eb907a374594de",
"type": "amazon-echo-device",
"z": "9879bffe.2be56",
"name": "Fortnite",
"topic": "",
"x": 220,
"y": 220,
"wires": [
[
"72bd51ced414b66a"
]
]
},
{
"id": "72bd51ced414b66a",
"type": "switch",
"z": "9879bffe.2be56",
"name": "Play Fortnite",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 510,
"y": 220,
"wires": [
[
"dc72ed9d.68814",
"5adaed27.ce4a74",
"ba2c5358.51ac6",
"52ec778d471990cc"
],
[
"3bb3454244c77d13",
"8936a5cadd4b229c",
"23e2cec2c810d949",
"4782b243acc7822e"
]
]
},
{
"id": "28421d9bf4b133a5",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Launch Fortnite",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "media_player",
"service": "play_media",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "{\"media_content_id\":\"BT5P2X999VH2\",\"media_content_type\":\"game\"}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1720,
"y": 980,
"wires": [
[
"b4398109fdcc88bc"
]
]
},
{
"id": "b4398109fdcc88bc",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "It's Fortnite time",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "notify",
"service": "alexa_media",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"target\":\"media_player.media_room_echo_dot\",\"message\":\"It's Fortnite time!\",\"data\":{\"type\":\"tts\"}}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2040,
"y": 980,
"wires": [
[]
]
},
{
"id": "f7a6d87ff6c8ce01",
"type": "ha-wait-until",
"z": "9879bffe.2be56",
"name": "Wait for Xbox to turn on",
"server": "f8a50b9a.39c988",
"version": 1,
"outputs": 1,
"entityId": "media_player.media_room_series_x",
"entityIdFilterType": "exact",
"property": "state",
"comparator": "is",
"value": "on",
"valueType": "str",
"timeout": "0",
"timeoutType": "num",
"timeoutUnits": "minutes",
"entityLocation": "data",
"entityLocationType": "none",
"checkCurrentState": true,
"blockInputOverrides": true,
"x": 1470,
"y": 980,
"wires": [
[
"28421d9bf4b133a5"
]
]
},
{
"id": "730fdeaff402503a",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn on Xbox",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "media_player",
"service": "turn_on",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1160,
"y": 980,
"wires": [
[
"f7a6d87ff6c8ce01"
]
]
},
{
"id": "ae11003b02034c84",
"type": "api-current-state",
"z": "9879bffe.2be56",
"name": "Xbox status",
"server": "f8a50b9a.39c988",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "media_player.media_room_series_x",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 930,
"y": 760,
"wires": [
[
"83e206a7625009f7"
],
[
"6c8ca67ae6bdeb02",
"97daa3c2.0dc6d"
]
]
},
{
"id": "52ec778d471990cc",
"type": "api-current-state",
"z": "9879bffe.2be56",
"name": "Xbox status",
"server": "f8a50b9a.39c988",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "media_player.media_room_series_x",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 930,
"y": 920,
"wires": [
[
"28421d9bf4b133a5"
],
[
"730fdeaff402503a",
"97daa3c2.0dc6d"
]
]
},
{
"id": "3d02edac1221cf9f",
"type": "amazon-echo-device",
"z": "9879bffe.2be56",
"name": "Battlefield",
"topic": "",
"x": 220,
"y": 280,
"wires": [
[
"c208bdcdadbb9d36"
]
]
},
{
"id": "c208bdcdadbb9d36",
"type": "switch",
"z": "9879bffe.2be56",
"name": "Play Battlefield",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 520,
"y": 280,
"wires": [
[
"ab76246b6af38d39",
"dc72ed9d.68814",
"5adaed27.ce4a74",
"ba2c5358.51ac6"
],
[
"3bb3454244c77d13",
"8936a5cadd4b229c",
"23e2cec2c810d949",
"4782b243acc7822e"
]
]
},
{
"id": "33063c0bc6708b6c",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Launch Battlefield",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "media_player",
"service": "play_media",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "{\"media_content_id\":\"9PD5BFNZ4V7K\",\"media_content_type\":\"game\"}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1730,
"y": 1120,
"wires": [
[
"ba623d55ef22ecad"
]
]
},
{
"id": "ba623d55ef22ecad",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "It's Fortnite time",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "notify",
"service": "alexa_media",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "{\"target\":\"media_player.media_room_echo_dot\",\"message\":\"It's Battlefield time!\",\"data\":{\"type\":\"tts\"}}",
"dataType": "json",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 2040,
"y": 1120,
"wires": [
[]
]
},
{
"id": "c81d11254fb65dc7",
"type": "ha-wait-until",
"z": "9879bffe.2be56",
"name": "Wait for Xbox to turn on",
"server": "f8a50b9a.39c988",
"version": 1,
"outputs": 1,
"entityId": "media_player.media_room_series_x",
"entityIdFilterType": "exact",
"property": "state",
"comparator": "is",
"value": "on",
"valueType": "str",
"timeout": "0",
"timeoutType": "num",
"timeoutUnits": "minutes",
"entityLocation": "data",
"entityLocationType": "none",
"checkCurrentState": true,
"blockInputOverrides": true,
"x": 1470,
"y": 1120,
"wires": [
[
"33063c0bc6708b6c"
]
]
},
{
"id": "91edbfab7a79e7a2",
"type": "api-call-service",
"z": "9879bffe.2be56",
"name": "Turn on Xbox",
"server": "f8a50b9a.39c988",
"version": 5,
"debugenabled": false,
"domain": "media_player",
"service": "turn_on",
"areaId": [],
"deviceId": [
"c3a53f9c81ee8d6804dde3c8048e9ecf"
],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 1160,
"y": 1120,
"wires": [
[
"c81d11254fb65dc7"
]
]
},
{
"id": "ab76246b6af38d39",
"type": "api-current-state",
"z": "9879bffe.2be56",
"name": "Xbox status",
"server": "f8a50b9a.39c988",
"version": 3,
"outputs": 2,
"halt_if": "on",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "media_player.media_room_series_x",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "payload",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 930,
"y": 1080,
"wires": [
[
"33063c0bc6708b6c"
],
[
"91edbfab7a79e7a2",
"97daa3c2.0dc6d"
]
]
},
{
"id": "f8a50b9a.39c988",
"type": "server",
"name": "VASHA01",
"version": 2,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": "30"
}
]