@Kermit I am using a modified version of your function here to make an array of areas that map to entities in that area which are lights. My goal is if there is a motion in an area I want to turn on lights in that area. Perhaps this is even covered in some presence tutorial somewhere I was not able to find. This would be similar to having music follow you room-to-room or lights.
As I states what I am trying to accomplish is to get all of the sister entities in an area that detects motion which are lights. Thus I found this code to work perfectly but, new to this, I am wondering if there is a much easier and cleaner way without using any JS or as minimal as possible:
Not sure if or where it is in the docs for HA it is but you use area_id in place of entity_id it should do all the lights if you use the light domain. light.turn_on