Combine two function nodes? (Multi light control with single remote with TTS)

Hey,
So I’ve created a pretty elaborate flow to control my lights from ONE xiaomi Mi Cube.

It functions like this:
Flip 90 - changes the light that’s selected
Tap Twice - toggles the light that’s selected
Rotate - Dim/brighten the light that’s selected (not yet implemented)
Shake - Turn off all lights.

I’ve also created a TTS function to announce which light is currently selected through Google Home. I have it so it will set the volume to 50% (if it isn’t already) and then return to whatever the previous volume was.

It’s all working great, but I have two function nodes for the return volume section. I’m trying to understand stored variable nodes, but I can’t seem to wrap my head around the code.

Can someone with a little more experience help me streamline this a little more please?

THANK YOU!
:slight_smile:

Function node 1:

var volume = { payload: msg.data.attributes.volume_level };
return [volume];

Function node 2:

msg.payload =
{
“data”:{
“entity_id”:“media_player.living_room_speaker”,
“volume_level”: msg.payload
}
}
return msg;

Full code:

[{"id":"57d252ac.ecc8ac","type":"tab","label":"Xiaomi Cube","disabled":false,"info":""},{"id":"c1027b8e.5aaad8","type":"inject","z":"57d252ac.ecc8ac","name":"Flip 90","topic":"","payload":"flip90","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":300,"wires":[["7e0bf332.2d5bcc","f913aba3.22c688"]]},{"id":"47841701.e9fee8","type":"inject","z":"57d252ac.ecc8ac","name":"Tap Twice","topic":"","payload":"tap_twice","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":340,"wires":[["7e0bf332.2d5bcc"]]},{"id":"68a2ba0b.d05c54","type":"inject","z":"57d252ac.ecc8ac","name":"Rotate","topic":"","payload":"rotate","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":380,"wires":[["7e0bf332.2d5bcc"]]},{"id":"7e0bf332.2d5bcc","type":"switch","z":"57d252ac.ecc8ac","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"flip90","vt":"str"},{"t":"eq","v":"tap_twice","vt":"str"},{"t":"eq","v":"rotate","vt":"str"},{"t":"eq","v":"shake","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":330,"y":380,"wires":[["df5a8e61.946cf"],["223a0bcb.83bf14","606e9a9.c404b64","64e1caa6.3479c4","897b1e79.a0d6"],["7172102f.1d59e","c9348085.480de","68d84eb4.cd39d","594b61fb.1de12"],["4023fb56.157574"]]},{"id":"df5a8e61.946cf","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Input Selection","server":"1b36a1cc.1e72ee","service_domain":"input_select","service":"select_next","data":"{ \"entity_id\" : \"input_select.room_selection\" }","mergecontext":"","x":560,"y":120,"wires":[[]]},{"id":"897b1e79.a0d6","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":220,"wires":[["f57b7780.8817b8"]]},{"id":"f57b7780.8817b8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":220,"wires":[["fc052e39.28b76"]]},{"id":"fc052e39.28b76","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":220,"wires":[["440d5e3e.e4387"]]},{"id":"f6cc8f59.de638","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":970,"y":340,"wires":[["f05be7c1.728818"]]},{"id":"b302164b.367a38","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":340,"wires":[["f6cc8f59.de638"]]},{"id":"684e4d9d.feff74","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":260,"wires":[["abe5da13.d6f5c8"]]},{"id":"abe5da13.d6f5c8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":260,"wires":[["4f28a800.84ea28"]]},{"id":"bb98ec2f.c27f8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":300,"wires":[["1619c786.30f138"]]},{"id":"223a0bcb.83bf14","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":260,"wires":[["684e4d9d.feff74"]]},{"id":"606e9a9.c404b64","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":300,"wires":[["54f6b0e8.8395b"]]},{"id":"54f6b0e8.8395b","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":300,"wires":[["bb98ec2f.c27f8"]]},{"id":"64e1caa6.3479c4","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":340,"wires":[["b302164b.367a38"]]},{"id":"cdd514ce.639278","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Kitchen","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Kitchen Selected\"}","mergecontext":"","x":1130,"y":940,"wires":[[]]},{"id":"1ec7f64a.9f41ea","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Family Room","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Family Room Selected\"}","mergecontext":"","x":1150,"y":860,"wires":[[]]},{"id":"7e23d838.5af7b8","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Dining Room","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Dining Room Selected\"}","mergecontext":"","x":1150,"y":900,"wires":[[]]},{"id":"73e949a8.68f508","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Living Room","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Living Room Selected\"}","mergecontext":"","x":1150,"y":820,"wires":[[]]},{"id":"4f28a800.84ea28","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Family Room Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.family_room\" }","mergecontext":"","x":1230,"y":260,"wires":[["c43d1ebe.f5f35"]]},{"id":"ea2d9fed.94922","type":"server-state-changed","z":"57d252ac.ecc8ac","name":"TTS","server":"1b36a1cc.1e72ee","entityidfilter":"input_select.room_selection","entityidfiltertype":"substring","haltifstate":"","x":330,"y":840,"wires":[["d04457f4.6c9f58"]]},{"id":"f6f2892b.7bcb28","type":"switch","z":"57d252ac.ecc8ac","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Living Room","vt":"str"},{"t":"eq","v":"Family Room","vt":"str"},{"t":"eq","v":"Dining Room","vt":"str"},{"t":"eq","v":"Kitchen","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":930,"y":840,"wires":[["73e949a8.68f508"],["1ec7f64a.9f41ea"],["7e23d838.5af7b8"],["cdd514ce.639278"]]},{"id":"1614cb4f.08d575","type":"comment","z":"57d252ac.ecc8ac","name":"Light Toggle","info":"","x":550,"y":180,"wires":[]},{"id":"60eb0889.80ad88","type":"comment","z":"57d252ac.ecc8ac","name":"Light Dimming","info":"","x":550,"y":400,"wires":[]},{"id":"f05be7c1.728818","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Kitchen Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.kitchen\" }","mergecontext":"","x":1240,"y":340,"wires":[["c43d1ebe.f5f35"]]},{"id":"1619c786.30f138","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Dining Room Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.dining_room\" }","mergecontext":"","x":1230,"y":300,"wires":[["c43d1ebe.f5f35"]]},{"id":"440d5e3e.e4387","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Living Room Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.living_room\" }","mergecontext":"","x":1230,"y":220,"wires":[["c43d1ebe.f5f35"]]},{"id":"7172102f.1d59e","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":440,"wires":[["75028ae.de18d74"]]},{"id":"75028ae.de18d74","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":440,"wires":[["ac81d5ab.fd5a48"]]},{"id":"ac81d5ab.fd5a48","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":440,"wires":[["bb422442.46e978"]]},{"id":"b718bc1c.05147","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":970,"y":560,"wires":[["3f80fd9a.583ae2"]]},{"id":"2a1b8eba.94a0b2","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":560,"wires":[["b718bc1c.05147"]]},{"id":"42747e6a.d1c58","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":480,"wires":[["725c4c99.f177f4"]]},{"id":"725c4c99.f177f4","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":480,"wires":[["e1f8508f.00857"]]},{"id":"8380b5a1.4276a8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":520,"wires":[["d967ad03.a97d5"]]},{"id":"c9348085.480de","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":480,"wires":[["42747e6a.d1c58"]]},{"id":"68d84eb4.cd39d","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":520,"wires":[["c43efe3d.f0eb9"]]},{"id":"c43efe3d.f0eb9","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":520,"wires":[["8380b5a1.4276a8"]]},{"id":"594b61fb.1de12","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":560,"wires":[["2a1b8eba.94a0b2"]]},{"id":"e1f8508f.00857","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Family Room Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1220,"y":480,"wires":[[]]},{"id":"3f80fd9a.583ae2","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Kitchen Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1240,"y":560,"wires":[[]]},{"id":"d967ad03.a97d5","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Dining Room Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1220,"y":520,"wires":[[]]},{"id":"bb422442.46e978","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Living Room Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1220,"y":440,"wires":[[]]},{"id":"c43d1ebe.f5f35","type":"debug","z":"57d252ac.ecc8ac","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1510,"y":280,"wires":[]},{"id":"be88fab2.994e38","type":"server-state-changed","z":"57d252ac.ecc8ac","name":"Xiaomi Cube","server":"1b36a1cc.1e72ee","entityidfilter":"binary_sensor.xiaomicube1","entityidfiltertype":"substring","haltifstate":"","x":110,"y":240,"wires":[["7e0bf332.2d5bcc","f913aba3.22c688"]]},{"id":"4023fb56.157574","type":"api-call-service","z":"57d252ac.ecc8ac","name":"All off","server":"1b36a1cc.1e72ee","service_domain":"light","service":"turn_off","data":"{ \"entity_id\": [\"light.living_room\", \"light.family_room\", \"light.dining_room\", \"light.kitchen\" ] }","mergecontext":"","x":530,"y":640,"wires":[[]]},{"id":"f323c764.9fb568","type":"inject","z":"57d252ac.ecc8ac","name":"Shake","topic":"","payload":"shake","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":420,"wires":[["7e0bf332.2d5bcc"]]},{"id":"d04457f4.6c9f58","type":"traffic","z":"57d252ac.ecc8ac","name":"","property_allow":"payload","filter_allow":"on","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"off","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":false,"differ":false,"x":650,"y":840,"wires":[["f6f2892b.7bcb28","eab1ebab.653568","eaa2e437.e8e238"]]},{"id":"eab1ebab.653568","type":"stoptimer","z":"57d252ac.ecc8ac","duration":"5","units":"Second","payloadtype":"str","payloadval":"","name":"5 Sec","x":590,"y":940,"wires":[["b6bc170.73bfee8"],[]]},{"id":"b6bc170.73bfee8","type":"change","z":"57d252ac.ecc8ac","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":940,"wires":[["d04457f4.6c9f58"]]},{"id":"4597c763.682aa8","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Set volume to 50%","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{\"entity_id\": \"media_player.living_room_speaker\", \"volume_level\": 0.5 }","mergecontext":"","x":1530,"y":720,"wires":[[]]},{"id":"cd27457f.5dc038","type":"switch","z":"57d252ac.ecc8ac","name":"50% ?","property":"data.attributes.volume_level","propertyType":"msg","rules":[{"t":"neq","v":"0.5","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":930,"y":720,"wires":[["4597c763.682aa8","4ee734cd.ce092c"]]},{"id":"94c74a11.889608","type":"delay","z":"57d252ac.ecc8ac","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1320,"y":760,"wires":[["efaec75b.3b2478"]]},{"id":"efaec75b.3b2478","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Set volume to Previous","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{}","mergecontext":"","x":1510,"y":760,"wires":[[]]},{"id":"4ee734cd.ce092c","type":"function","z":"57d252ac.ecc8ac","name":"","func":"var volume = { payload: msg.data.attributes.volume_level };\nreturn [volume];","outputs":1,"noerr":0,"x":1070,"y":760,"wires":[["5fd839fc.562a48"]]},{"id":"5fd839fc.562a48","type":"function","z":"57d252ac.ecc8ac","name":"","func":"msg.payload =\n{\n    \"data\":{\n      \"entity_id\":\"media_player.living_room_speaker\",\n      \"volume_level\": msg.payload\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":1190,"y":760,"wires":[["94c74a11.889608"]]},{"id":"eaa2e437.e8e238","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Volume","server":"1b36a1cc.1e72ee","halt_if":"","override_topic":true,"override_payload":true,"entity_id":"media_player.living_room_speaker","x":800,"y":720,"wires":[["cd27457f.5dc038"]]},{"id":"dc7f8113.d62c8","type":"function","z":"57d252ac.ecc8ac","name":"","func":"var newMsg = { payload: msg.data.attributes.volume_level };\nmsg.payload =\n{  \"data\":{\n    \"entity_id\":\"media_player.living_room_speaker\",\n    \"volume_level\": newMsg\n  }\n}\nreturn msg;","outputs":1,"noerr":0,"x":650,"y":1160,"wires":[[]]},{"id":"f913aba3.22c688","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Playing already?","server":"1b36a1cc.1e72ee","halt_if":"playing","override_topic":true,"override_payload":true,"entity_id":"media_player.living_room_speaker","x":330,"y":740,"wires":[["9756293.cd8b2d8"]]},{"id":"9756293.cd8b2d8","type":"change","z":"57d252ac.ecc8ac","name":" ","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":740,"wires":[["d04457f4.6c9f58"]]}]

1 Like

I’ve been at it all day, and I’ve finally worked it out!

msg.payload =
{
“data”:{
“entity_id”:“media_player.living_room_speaker”,
“volume_level”: msg.data.attributes.volume_level
}
}
return msg;

1 Like

A few more changes.

I realised that if the speaker times out, the previous volume state was not being detected. So I added a couple of nodes to turn on the speaker (if it was previously off), and a 500ms delay to the TTS trigger.

Code:

[{"id":"57d252ac.ecc8ac","type":"tab","label":"Xiaomi Cube","disabled":false,"info":""},{"id":"c1027b8e.5aaad8","type":"inject","z":"57d252ac.ecc8ac","name":"Flip 90","topic":"","payload":"flip90","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":300,"wires":[["7e0bf332.2d5bcc","f913aba3.22c688"]]},{"id":"47841701.e9fee8","type":"inject","z":"57d252ac.ecc8ac","name":"Tap Twice","topic":"","payload":"tap_twice","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":340,"wires":[["7e0bf332.2d5bcc"]]},{"id":"68a2ba0b.d05c54","type":"inject","z":"57d252ac.ecc8ac","name":"Rotate","topic":"","payload":"rotate","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":380,"wires":[["7e0bf332.2d5bcc"]]},{"id":"7e0bf332.2d5bcc","type":"switch","z":"57d252ac.ecc8ac","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"flip90","vt":"str"},{"t":"eq","v":"tap_twice","vt":"str"},{"t":"eq","v":"rotate","vt":"str"},{"t":"eq","v":"shake","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":330,"y":380,"wires":[["df5a8e61.946cf"],["223a0bcb.83bf14","606e9a9.c404b64","64e1caa6.3479c4","897b1e79.a0d6"],["7172102f.1d59e","c9348085.480de","68d84eb4.cd39d","594b61fb.1de12"],["4023fb56.157574"]]},{"id":"df5a8e61.946cf","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Input Selection","server":"1b36a1cc.1e72ee","service_domain":"input_select","service":"select_next","data":"{ \"entity_id\" : \"input_select.room_selection\" }","mergecontext":"","x":560,"y":120,"wires":[[]]},{"id":"897b1e79.a0d6","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":220,"wires":[["f57b7780.8817b8"]]},{"id":"f57b7780.8817b8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":220,"wires":[["fc052e39.28b76"]]},{"id":"fc052e39.28b76","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":220,"wires":[["440d5e3e.e4387"]]},{"id":"f6cc8f59.de638","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":970,"y":340,"wires":[["f05be7c1.728818"]]},{"id":"b302164b.367a38","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":340,"wires":[["f6cc8f59.de638"]]},{"id":"684e4d9d.feff74","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":260,"wires":[["abe5da13.d6f5c8"]]},{"id":"abe5da13.d6f5c8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":260,"wires":[["4f28a800.84ea28"]]},{"id":"bb98ec2f.c27f8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":300,"wires":[["1619c786.30f138"]]},{"id":"223a0bcb.83bf14","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":260,"wires":[["684e4d9d.feff74"]]},{"id":"606e9a9.c404b64","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":300,"wires":[["54f6b0e8.8395b"]]},{"id":"54f6b0e8.8395b","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":300,"wires":[["bb98ec2f.c27f8"]]},{"id":"64e1caa6.3479c4","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":340,"wires":[["b302164b.367a38"]]},{"id":"cdd514ce.639278","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Kitchen","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Kitchen Selected\"}","mergecontext":"","x":1370,"y":980,"wires":[[]]},{"id":"1ec7f64a.9f41ea","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Family Room","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Family Room Selected\"}","mergecontext":"","x":1390,"y":900,"wires":[[]]},{"id":"7e23d838.5af7b8","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Dining Room","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Dining Room Selected\"}","mergecontext":"","x":1390,"y":940,"wires":[[]]},{"id":"73e949a8.68f508","type":"api-call-service","z":"57d252ac.ecc8ac","name":"TTS Living Room","server":"1b36a1cc.1e72ee","service_domain":"tts","service":"google_say","data":"{\"entity_id\":\"media_player.living_room_speaker\", \"message\":\"Living Room Selected\"}","mergecontext":"","x":1390,"y":860,"wires":[[]]},{"id":"4f28a800.84ea28","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Family Room Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.family_room\" }","mergecontext":"","x":1230,"y":260,"wires":[[]]},{"id":"ea2d9fed.94922","type":"server-state-changed","z":"57d252ac.ecc8ac","name":"TTS","server":"1b36a1cc.1e72ee","entityidfilter":"input_select.room_selection","entityidfiltertype":"substring","haltifstate":"","x":350,"y":880,"wires":[["ee16292.adbead8"]]},{"id":"f6f2892b.7bcb28","type":"switch","z":"57d252ac.ecc8ac","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Living Room","vt":"str"},{"t":"eq","v":"Family Room","vt":"str"},{"t":"eq","v":"Dining Room","vt":"str"},{"t":"eq","v":"Kitchen","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":1170,"y":880,"wires":[["73e949a8.68f508"],["1ec7f64a.9f41ea"],["7e23d838.5af7b8"],["cdd514ce.639278"]]},{"id":"1614cb4f.08d575","type":"comment","z":"57d252ac.ecc8ac","name":"Light Toggle","info":"","x":550,"y":180,"wires":[]},{"id":"60eb0889.80ad88","type":"comment","z":"57d252ac.ecc8ac","name":"Light Dimming","info":"","x":550,"y":400,"wires":[]},{"id":"f05be7c1.728818","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Kitchen Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.kitchen\" }","mergecontext":"","x":1240,"y":340,"wires":[[]]},{"id":"1619c786.30f138","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Dining Room Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.dining_room\" }","mergecontext":"","x":1230,"y":300,"wires":[[]]},{"id":"440d5e3e.e4387","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Living Room Light Toggle","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"{ \"entity_id\" : \"light.living_room\" }","mergecontext":"","x":1230,"y":220,"wires":[[]]},{"id":"7172102f.1d59e","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":440,"wires":[["75028ae.de18d74"]]},{"id":"75028ae.de18d74","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":440,"wires":[["ac81d5ab.fd5a48"]]},{"id":"ac81d5ab.fd5a48","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":440,"wires":[["bb422442.46e978"]]},{"id":"b718bc1c.05147","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":970,"y":560,"wires":[["3f80fd9a.583ae2"]]},{"id":"2a1b8eba.94a0b2","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":560,"wires":[["b718bc1c.05147"]]},{"id":"42747e6a.d1c58","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Dining Room on?","server":"1b36a1cc.1e72ee","halt_if":"Dining Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":480,"wires":[["725c4c99.f177f4"]]},{"id":"725c4c99.f177f4","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":480,"wires":[["e1f8508f.00857"]]},{"id":"8380b5a1.4276a8","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Kitchen on?","server":"1b36a1cc.1e72ee","halt_if":"Kitchen","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":950,"y":520,"wires":[["d967ad03.a97d5"]]},{"id":"c9348085.480de","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":480,"wires":[["42747e6a.d1c58"]]},{"id":"68d84eb4.cd39d","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Living Room on?","server":"1b36a1cc.1e72ee","halt_if":"Living Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":520,"wires":[["c43efe3d.f0eb9"]]},{"id":"c43efe3d.f0eb9","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":770,"y":520,"wires":[["8380b5a1.4276a8"]]},{"id":"594b61fb.1de12","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Family Room on?","server":"1b36a1cc.1e72ee","halt_if":"Family Room","override_topic":true,"override_payload":true,"entity_id":"input_select.room_selection","x":570,"y":560,"wires":[["2a1b8eba.94a0b2"]]},{"id":"e1f8508f.00857","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Family Room Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1220,"y":480,"wires":[[]]},{"id":"3f80fd9a.583ae2","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Kitchen Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1240,"y":560,"wires":[[]]},{"id":"d967ad03.a97d5","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Dining Room Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1220,"y":520,"wires":[[]]},{"id":"bb422442.46e978","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Living Room Light Dimming","server":"1b36a1cc.1e72ee","service_domain":"light","service":"toggle","data":"","mergecontext":"","x":1220,"y":440,"wires":[[]]},{"id":"be88fab2.994e38","type":"server-state-changed","z":"57d252ac.ecc8ac","name":"Xiaomi Cube","server":"1b36a1cc.1e72ee","entityidfilter":"binary_sensor.xiaomicube1","entityidfiltertype":"substring","haltifstate":"","x":110,"y":480,"wires":[["7e0bf332.2d5bcc","f913aba3.22c688"]]},{"id":"4023fb56.157574","type":"api-call-service","z":"57d252ac.ecc8ac","name":"All off","server":"1b36a1cc.1e72ee","service_domain":"light","service":"turn_off","data":"{ \"entity_id\": [\"light.living_room\", \"light.family_room\", \"light.dining_room\", \"light.kitchen\" ] }","mergecontext":"","x":530,"y":640,"wires":[[]]},{"id":"f323c764.9fb568","type":"inject","z":"57d252ac.ecc8ac","name":"Shake","topic":"","payload":"shake","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":420,"wires":[["7e0bf332.2d5bcc"]]},{"id":"d04457f4.6c9f58","type":"traffic","z":"57d252ac.ecc8ac","name":"","property_allow":"payload","filter_allow":"on","ignore_case_allow":false,"negate_allow":false,"send_allow":false,"property_stop":"payload","filter_stop":"off","ignore_case_stop":false,"negate_stop":false,"send_stop":false,"default_start":false,"differ":false,"x":690,"y":880,"wires":[["f6f2892b.7bcb28","eab1ebab.653568","eaa2e437.e8e238"]]},{"id":"eab1ebab.653568","type":"stoptimer","z":"57d252ac.ecc8ac","duration":"5","units":"Second","payloadtype":"str","payloadval":"","name":"5 Sec","x":630,"y":980,"wires":[["b6bc170.73bfee8"],[]]},{"id":"b6bc170.73bfee8","type":"change","z":"57d252ac.ecc8ac","name":"Off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":980,"wires":[["d04457f4.6c9f58"]]},{"id":"4597c763.682aa8","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Set volume to 50%","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{\"entity_id\": \"media_player.living_room_speaker\", \"volume_level\": 0.5 }","mergecontext":"","x":1130,"y":740,"wires":[[]]},{"id":"cd27457f.5dc038","type":"switch","z":"57d252ac.ecc8ac","name":"50% ?","property":"data.attributes.volume_level","propertyType":"msg","rules":[{"t":"neq","v":"0.5","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":950,"y":800,"wires":[["4597c763.682aa8","d340d651.4f1da8"]]},{"id":"eaa2e437.e8e238","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Volume","server":"1b36a1cc.1e72ee","halt_if":"","override_topic":true,"override_payload":true,"entity_id":"media_player.living_room_speaker","x":800,"y":800,"wires":[["cd27457f.5dc038"]]},{"id":"f913aba3.22c688","type":"api-current-state","z":"57d252ac.ecc8ac","name":"Playing already?","server":"1b36a1cc.1e72ee","halt_if":"playing","override_topic":true,"override_payload":true,"entity_id":"media_player.living_room_speaker","x":410,"y":800,"wires":[["9756293.cd8b2d8","eb541190.fb817"]]},{"id":"9756293.cd8b2d8","type":"change","z":"57d252ac.ecc8ac","name":" ","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":800,"wires":[["d04457f4.6c9f58"]]},{"id":"d340d651.4f1da8","type":"function","z":"57d252ac.ecc8ac","name":"","func":"msg.payload =\n{\n    \"data\":{\n      \"entity_id\":\"media_player.living_room_speaker\",\n      \"volume_level\": msg.data.attributes.volume_level\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":1090,"y":800,"wires":[["66b7e333.1ea42c"]]},{"id":"66b7e333.1ea42c","type":"delay","z":"57d252ac.ecc8ac","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1220,"y":800,"wires":[["40e2f97c.56fd28"]]},{"id":"40e2f97c.56fd28","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Set volume to Previous","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"volume_set","data":"{}","mergecontext":"","x":1410,"y":800,"wires":[[]]},{"id":"dc5cd9f2.0463e8","type":"comment","z":"57d252ac.ecc8ac","name":"Google TTS","info":"","x":390,"y":740,"wires":[]},{"id":"fcff31f8.300f1","type":"api-call-service","z":"57d252ac.ecc8ac","name":"Turn on Speaker","server":"1b36a1cc.1e72ee","service_domain":"media_player","service":"turn_on","data":"{ \"entity_id\" : \"media_player.living_room_speaker\" }","mergecontext":"","x":830,"y":740,"wires":[[]]},{"id":"eb541190.fb817","type":"api-current-state","z":"57d252ac.ecc8ac","name":"On already?","server":"1b36a1cc.1e72ee","halt_if":"idle","override_topic":true,"override_payload":true,"entity_id":"media_player.living_room_speaker","x":590,"y":740,"wires":[["fcff31f8.300f1"]]},{"id":"ee16292.adbead8","type":"delay","z":"57d252ac.ecc8ac","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":490,"y":880,"wires":[["d04457f4.6c9f58"]]}]

1 Like

So after receiving my xiaomi cube, and discovering how it actually works, I have had to amend my flow.

  • Tap Twice changes the selection and announces selected room on TTS
  • Flip 90 toggles the selected light
  • Flip 180 turns the selected light to full brightness
  • Rotate clockwise/anticlockwise turns selected light brightness up or down
  • Move toggles through different temperature settings of the selected light
  • Shake in the air turns off ALL lights

I can’t insert the code here because the body is too long.
So let me know if you would like it and I’ll send it to you.


Here is the finished product:

yes! very curious of your (json) solution.
Looking to combine the cube for switching light and for controlling my receiver. Using the (double) tap for switching between… Any thoughts of how to control volume up/down when rotating the cube?

This looks amazing! please could you send me the flow?

Hey, I’m between houses atm, so my home assistant is not being used.
I’ll have to share the flow once I’m up and running again.