Help needed for template light / value_template / CMD sensor

ok, i am going to make some template lights, i can manage those
but i am stuck with the state, i can read the state of my lights with a command line sensor like below :
First problem:
the output is more the 255 characters, this is not allowed in HA
see output here if i do it from putty:

but i only need the ID + value1
ID : id if my light
value1 : can be 0 = OFF , or 100 = ON
how can i make my sensor extra only that data , so i am below < 255 characters?

second question
how can i create my value_template on my light to represent ON/OFF for state?

thnx a lot!!

sensor:

  - platform: command_line
    host: xxx
    port: 8000
    name: Niko
    command: (echo '{"cmd":"listactions"}'; sleep 1) | nc XXXX 8000

I would have one command line sensor per light, using a command something like this:

command: (echo '{"cmd":"listactions"}'; sleep 1) | nc xxxxx 8000 | jq '.data[] | select(.id == 16) | .value1'

This shows getting the value for the light whose id is 16. Copy this for each light state command line sensor, changing the id number for each.

If you want to have just one command line sensor that outputs all the id’s and corresponding values, then something like this might be what you want:

command: (echo '{"cmd":"listactions"}'; sleep 1) | nc xxxxx 8000 | jq '.data[] | [.id,.value1]' -cj

This will produce output that looks like this:

[16,0][22,0]...

Thnx , going for option 2, otherwise I have an overload of commands to my controller

Yep. The only downside is trying to extract the appropriate pieces since this will just be a string. But there are some regex template filters that might help.

yes, i managed that with a split :slight_smile:

1 Like