Command_line Output

I need to bring the output of a command on a router and it is only showing me

value_template: >-
  {%- set leases = [] -%}
  {%- for line in value.split('\n') -%}
      {%- set parts = line.split() -%}
      {%- set lease = {
            'ip': parts[2],
            'mac': parts[3],
            'hostname': parts[4]
        } -%}
      {%- set _ = leases.append(lease) -%}
  {%- endfor -%}
  {{ leases | tojson }}

The output of the SSH command brings me an output like this on multiple lines

          IP                                 MAC                            HOSTNAME    

XXX.XXX.XXX.XXX XXXX.XXXX.XXXX.XXXX ANY CONNECTED

You have to use namespace and jinja syntax. YOu can’t create lists in jinja and append to them.

value_template: >-
  {%- set ns = namespace(items=[]) %}
  {%- for line in value.split('\n') %}
    {%- set ip, mac, host = line.split()[2:5] %}
    {%- set ns.items = ns.items + [ dict(ip=ip, mac=mac, hostname=host) ] %}
  {%- endfor %}
  {{ ns.items | tojson }}

keep in mind that states are limited to 254 characters, so the result will most likely be truncated.

Any other ideas how I could list this?

I want to do a zero trust with mobile notifications of approval of connection to a public Wi-Fi without a password. With other automations depending on connected equipment.

I also want to see the devices that are connected and the status they are in (allowed or denied)

Have a mikrotik like a router.

I am making the connection via SSH with encryption keys to be able to execute commands to the router

The router can show me the approval or denied status without any problem.

But I need to first list the connected devices to detect changes and execute a notification to the mobile, with execution of approval or deny based on script defined in the router.