Construct JSON for based on input boolean

Hello:
I am trying to set up a way to have individual input_boolean entries for different rooms of my house that i can check on/off and then run a flow in NR to check which input_booleans are turned on and construct the JSON to tell my Roborock S6 where to vacuum.

I’ve set up the following:

input_boolean.spot_kitchen
input_boolean.spot_family
input_boolean.spot_foyer
etc

From Home Assistant, I can send the following to choose which rooms to vacuum (rooms set up in Mi Home App):

Service: vacuum.send_command
Entity: vacuum.spot
Data: 
  command: app_segment_clean
  entity_id: vacuum.spot
  params:
  - 16
  - 17
  - 18

The numbered list corresponds to the rooms that are selected and would be different depending on which input_booleans are activated.

I should be able to call the service in Node-Red and alter the JSON data to choose which rooms to send to the vacuum. I tested the following JSON data and it works for the specific rooms listed (16 and 17):

{
	"command": "app_segment_clean",
	"entity_id": "vacuum.spot",
	"params": [
		16,
		17
	]
}

I am trying to figure out how to modify the “params” based on which input booleans are activated. The way i am picturing it is once the flow is activated, it would check status of each input_boolean (7 total) and if activated, add that specific room number to the end of a list, then pass the entire list to the service call. Any ideas?

A join node can help. here is a mock flow. you can use your own booleans but make sure they are filtered like this in the current state node: image

[{"id":"b7afe772.a6e858","type":"inject","z":"294e4f5f.46b07","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":820,"wires":[["146bb685.480a49","41cbc945.be5408","588330ba.fda99"]]},{"id":"146bb685.480a49","type":"api-current-state","z":"294e4f5f.46b07","name":"","server":"e447d17a.16a64","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.alarm_clock","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":420,"y":800,"wires":[["c60e503c.88e84"],[]]},{"id":"41cbc945.be5408","type":"api-current-state","z":"294e4f5f.46b07","name":"","server":"e447d17a.16a64","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.musical_statues","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":430,"y":840,"wires":[["50cfcb12.7956f4"],[]]},{"id":"700b2328.415a7c","type":"join","z":"294e4f5f.46b07","name":"","mode":"custom","build":"array","property":"payload.data.params","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"0.5","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":930,"y":860,"wires":[["92a264ed.8037e8"]]},{"id":"92a264ed.8037e8","type":"debug","z":"294e4f5f.46b07","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1090,"y":860,"wires":[]},{"id":"588330ba.fda99","type":"api-current-state","z":"294e4f5f.46b07","name":"","server":"e447d17a.16a64","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.alarm_clock","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":420,"y":900,"wires":[["56c77c6b.ac34f4"],[]]},{"id":"c60e503c.88e84","type":"change","z":"294e4f5f.46b07","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"16","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":800,"wires":[["700b2328.415a7c"]]},{"id":"50cfcb12.7956f4","type":"change","z":"294e4f5f.46b07","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"17","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":840,"wires":[["700b2328.415a7c"]]},{"id":"56c77c6b.ac34f4","type":"change","z":"294e4f5f.46b07","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"18","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":900,"wires":[["700b2328.415a7c"]]},{"id":"e447d17a.16a64","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

@serkank Bingo! You got me far enough on the right track to figure it out. Thanks a ton! I had to change the type from “string” to “number” in the switch nodes. After joining, I called the service with the following data:

{"command":"app_segment_clean","entity_id":"vacuum.spot","params":[{{payload.data.params}}]}

And it dropped the paramters in the service call.

For anyone interested, here’s my total flow:

[{"id":"c8adbc04.d8121","type":"tab","label":"Vacuum","disabled":false,"info":""},{"id":"966fe494.58f008","type":"server-state-changed","z":"c8adbc04.d8121","name":"Room Cleaning","server":"870b7bd0.404b48","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.spot_room","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":120,"y":60,"wires":[["45076586.c8f59c","f53ba184.6e883","c4fe46bd.6f2928","43e43ee1.93faa","9c9f683a.156a88","4118ef3d.8694","5c1c57a2.6ed2f8","acd116c7.b9fae8"],[]]},{"id":"a8012698.35f428","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Start","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_room","data":"{\"entity_id\":\"input_boolean.spot_room\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":360,"wires":[[]]},{"id":"acd116c7.b9fae8","type":"delay","z":"c8adbc04.d8121","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":310,"y":360,"wires":[["a8012698.35f428","62ab02d7.1edddc","9035446e.741998","687f44e5.98a54c","f58c4c1b.96d5","31762d7f.d21562","7b7be3cd.95cffc","d4d0e213.bbb65"]]},{"id":"62ab02d7.1edddc","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Kitchen","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_kitchen","data":"{\"entity_id\":\"input_boolean.spot_kitchen\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":400,"wires":[[]]},{"id":"9035446e.741998","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Family","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_family","data":"{\"entity_id\":\"input_boolean.spot_family\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":440,"wires":[[]]},{"id":"687f44e5.98a54c","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Living","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_living","data":"{\"entity_id\":\"input_boolean.spot_living\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":480,"wires":[[]]},{"id":"f58c4c1b.96d5","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Dining","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_dining","data":"{\"entity_id\":\"input_boolean.spot_dining\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":520,"wires":[[]]},{"id":"7b7be3cd.95cffc","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Powder","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_powder","data":"{\"entity_id\":\"input_boolean.spot_powder\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":560,"wires":[[]]},{"id":"31762d7f.d21562","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Laundry","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_laundry","data":"{\"entity_id\":\"input_boolean.spot_laundry\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":500,"y":600,"wires":[[]]},{"id":"d4d0e213.bbb65","type":"api-call-service","z":"c8adbc04.d8121","name":"Turn Off Foyer","server":"870b7bd0.404b48","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.spot_foyer","data":"{\"entity_id\":\"input_boolean.spot_foyer\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":490,"y":640,"wires":[[]]},{"id":"9cc7377b.fc8598","type":"join","z":"c8adbc04.d8121","name":"","mode":"custom","build":"array","property":"payload.data.params","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"0.5","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":660,"y":60,"wires":[["6809aef2.d4d6b"]]},{"id":"74ef0e2e.1da48","type":"change","z":"c8adbc04.d8121","name":"Kithchen 16","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"16","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":60,"wires":[["9cc7377b.fc8598"]]},{"id":"126bfd31.b98363","type":"change","z":"c8adbc04.d8121","name":"Living 20","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":220,"wires":[["9cc7377b.fc8598"]]},{"id":"d2d79768.d3d6c8","type":"change","z":"c8adbc04.d8121","name":"Foyer 17","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"17","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":100,"wires":[["9cc7377b.fc8598"]]},{"id":"45076586.c8f59c","type":"api-current-state","z":"c8adbc04.d8121","name":"Check Kitchen","server":"870b7bd0.404b48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.spot_kitchen","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":330,"y":60,"wires":[["74ef0e2e.1da48"],[]]},{"id":"f53ba184.6e883","type":"api-current-state","z":"c8adbc04.d8121","name":"Check Living","server":"870b7bd0.404b48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.spot_living","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":320,"y":220,"wires":[["126bfd31.b98363"],[]]},{"id":"c4fe46bd.6f2928","type":"api-current-state","z":"c8adbc04.d8121","name":"Check Foyer","server":"870b7bd0.404b48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.spot_foyer","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":320,"y":100,"wires":[["d2d79768.d3d6c8"],[]]},{"id":"6809aef2.d4d6b","type":"api-call-service","z":"c8adbc04.d8121","name":"Vacuum Rooms","server":"870b7bd0.404b48","version":1,"debugenabled":true,"service_domain":"vacuum","service":"send_command","entityId":"vacuum.spot","data":"{\"command\":\"app_segment_clean\",\"entity_id\":\"vacuum.spot\",\"params\":[{{payload.data.params}}]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":830,"y":60,"wires":[[]]},{"id":"43e43ee1.93faa","type":"api-current-state","z":"c8adbc04.d8121","name":"Check Family","server":"870b7bd0.404b48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.spot_family","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":330,"y":180,"wires":[["77046673.df7f28"],[]]},{"id":"9c9f683a.156a88","type":"api-current-state","z":"c8adbc04.d8121","name":"Check Dining","server":"870b7bd0.404b48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.spot_dining","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":320,"y":140,"wires":[["ba029e4e.7d69"],[]]},{"id":"4118ef3d.8694","type":"api-current-state","z":"c8adbc04.d8121","name":"Check Powder","server":"870b7bd0.404b48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.spot_powder","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":330,"y":260,"wires":[["7abc5d6f.facb94"],[]]},{"id":"5c1c57a2.6ed2f8","type":"api-current-state","z":"c8adbc04.d8121","name":"Check Laundry","server":"870b7bd0.404b48","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.spot_laundry","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":330,"y":300,"wires":[["a5a646ca.8c2508"],[]]},{"id":"77046673.df7f28","type":"change","z":"c8adbc04.d8121","name":"Family 19","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"19","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":180,"wires":[["9cc7377b.fc8598"]]},{"id":"ba029e4e.7d69","type":"change","z":"c8adbc04.d8121","name":"Dining 18","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"18","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":140,"wires":[["9cc7377b.fc8598"]]},{"id":"7abc5d6f.facb94","type":"change","z":"c8adbc04.d8121","name":"Powder 21","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"21","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":260,"wires":[["9cc7377b.fc8598"]]},{"id":"a5a646ca.8c2508","type":"change","z":"c8adbc04.d8121","name":"Laundry 22","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"payload.data.params","pt":"msg","to":"22","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":300,"wires":[["9cc7377b.fc8598"]]},{"id":"870b7bd0.404b48","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Here’s a screenshot of my flow

And here’s a shot of my Lovelace setup