Nanoleaf seperate lights

I have nanoleaf shapes (18 in total) within home assistant they show up as 1 light. while you can actually control all 18 of them seperately.

I managed to control them all individualy using a rest command. But it would be allot nicer if the integration was edited to show all the shapes as individual lights in home assistant. It must be possible… Nanoleaf does support discovery of all the individual shapes with their id number after which they theoretically can be integrated as individual lights in home assistant. I will post the code i use to control all lights seperately down below. Maybe someone can take the time to add this to the integration?

nanoleaf:
  url: http://192.168.178.54:16021/api/v1/[api key]/effects
  method: PUT
  payload: >
    { "write" : {"command": "display", "animType": "static", "animData":
    {%- set all = [ 36776, 40379, 39889, 47065, 62644, 56943, 44929, 4212, 50749, 42705, 55753, 9801, 2975, 5181, 59276, 33852, 34713, 42845 ] %}
    {%- set ns = namespace(panels=[panels | count | string]) %}
    {%- for panel in panels %}
    {%- set ns.panels = ns.panels + [ '{} 1 {} {} {} 0 20'.format(all[panel.number-1], panel.r, panel.g, panel.b) ] %}
    {%- endfor %}
    "{{ ns.panels | join(' ') }}",
    "loop": false, "palette": [], "colorType": "HSB"}
    }
  content_type: 'application/json' 

the automation part looks something like this:

- id: '1618492041197'
  alias: Nanoleaf post
  description: ''
  trigger:
  - platform: state
    entity_id: input_select.post
    to: Er is post
  condition: []
  action:
  - service: rest_command.nanoleaf
    data:
      panels:
      - number: 1
        r: 100
        g: 0
        b: 100
      - number: 2
        r: 0
        g: 0
        b: 0
  mode: single

Maybe someone can take the time to add this to the integration?

Yes, please!

Just bought the nanoleafs, assuming this would be default only to find out you cannot address them individually. Thats the whole point for us “HA” users i would say. But above snippet will have to do for now.

I gave it a try, but got an error:

“The nanoleaf integration does not support YAML configuration”. What am I doing wrong?

Update:

It has to look like this now: (You have to use your own panel IDs in “set all”, of course):

rest_command:
  set_tile:
    url: http://192.168.x.x:16021/api/v1/[api key]/effects
    method: PUT
    payload: >
      { "write" : {"command": "display", "animType": "static", "animData":
      {%- set all = [ 36776, 40379, 39889, 47065, 62644, 56943, 44929, 4212, 50749, 42705, 55753, 9801, 2975, 5181, 59276, 33852, 34713, 42845 ] %}
      {%- set ns = namespace(panels=[panels | count | string]) %}
      {%- for panel in panels %}
      {%- set ns.panels = ns.panels + [ '{} 1 {} {} {} 0 20'.format(all[panel.number-1], panel.r, panel.g, panel.b) ] %}
      {%- endfor %}
      "{{ ns.panels | join(' ') }}",
      "loop": false, "palette": [], "colorType": "HSB"}
      }
    content_type: 'application/json'

A script making use of it looks like this:

alias: Set tile
sequence:
  - service: rest_command.set_tile
    data:
      panels:
        - number: 1
          r: 100
          g: 0
          b: 100
        - number: 2
          r: 0
          g: 0
          b: 0

You cannot use my tile id’s you have your own tile id’s

I know, thank you. I used my own IDs. Just didn’t want to make it more complicated by bringing new numbers into the mix.

Speaking of IDs: You can get your panel IDs if you paste this in your browser (IP and API key needed):

http://[ip]/api/v1/[api key]/

Is it possible to not overwrite states? For example, the script above sets panels 1 and 2, but switches off all the others. Sometimes I just want to change one tile while leaving the others as they are.