Read the status of a lamp via command line

Hello everyone,

I’m trying to read the status of my bedside lamp to trigger a ‘good night’ status in HA.

Since the Xiaomi Bedside lamp 2 doesn’t allow lan control anymore, i do it like this:

  - platform: command_line
    name: Yeelight Power
    command: "miiocli yeelight --ip 10.0.1.172 --token 4556445544545455454 status | grep 'Power' | awk '{print $2}'"
    scan_interval: 60  # Set the desired update interval in seconds

  - platform: template
    sensors:
      yeelight_on_off:
        friendly_name: "Yeelight On/Off"
        value_template: "{{ is_state('sensor.yeelight_power', 'true') or is_state('sensor.yeelight_power', 'True') }}"

Even though the command is giving me a “True” it doesn’t seen to trigger the yeelight_on_off

Can you post the output of the API call?

Do you mean from the shell command? That’s True when the light is on, False when it’s off.

It’s in the picture with the command. That why i use grep and awk.