Command_line sensors broken for me in Home Assistant versions after 2023.3.6

I have created command_line switches to enable/disable Hue Motion Sensors and everything has been perfect for ages. It seems now that any version I upgrade to beyond 2023.3.6 breaks the switches.

The strange thing is they work most of the time but then randomly go haywire and either show a broken icon or just show status as off when they are on.

I have verified they are on when they do this in the Hue app.

The code for one of them is below:

  - platform: command_line
    switches:
      garage_sensor:
        friendly_name: Garage Sensor
        command_on: >
          curl -X PUT -d '{"on":true}' -k "https://192.168.0.253/api/XXXXXXXXXXXXXXXXXXXXXXXXXXX/sensors/31/config/"
        command_off: >
          curl -X PUT -d '{"on":false}' -k "https://192.168.0.253/api/XXXXXXXXXXXXXXXXXXXXXXXXXXX/sensors/31/config/"
        command_state: curl -k "https://192.168.0.253/api/XXXXXXXXXXXXXXXXXXXXXXXXXXX/sensors/31/"
        value_template: >
          {{value_json.config.on}}'

This works 100% in 2023.3.6, everything beyond that breaks it and I cannot figure out why. As mentioned the switches still work just the status randomly goes haywire then will recover again and it’s random as to which of the 7 command_line switches will play up. It’s like it fails to get the status however it never fails in HA 2023.3.6.

I am assuming something has changed in the later HA builds but so far I haven’t been able to figure out what and it’s stopping me upgrading at the moment as I need that functionality to continue working. It did improve at one point as one build showed messy icons for the switches and the next was fine but still with status of the switches not working correctly all the time.

Any help is appreciated.

The new format is as follows, took a couple tries before they posted the new layout.

Example configuration.yaml entry

command_line:
  - switch:
      name: Kitchen Light
      command_on: switch_command on kitchen
      command_off: switch_command off kitchen

Thanks I’ll give that a try. Have they changed the command_state and value_template format at all do you know?

But the old format should still work, and it will keep on working until at least release 2023.08, so for now nothing changed and the are just warning’s :wink:

Looking at the docs command_state and value_template remain the same.

1 Like

I did hear something about the value_template in the latest version not being valid but I don’t remember the details from the thread I saw about it.

also something to try is that I see you have an extra ` at the end of the template in the value_template. try removing that first.

1 Like

That’s just a typo in the post rather than the code but well spotted anyway. :slight_smile:

1 Like

Even with the suggested changes I still get inconsistant readings from the switches.

All the sensors are currently on yet:

The ones that are on or off will randomly change which is the bizarre thing.

I am having the same problems. Had multiple working switches with state setup and now cannot get any of those switches working after converting to the new yaml format. Getting command line 127 errors or taking too long to respond. Everything just worked in the old syntax, so why did we need to switch?

Yeah I have no idea why it’s all broken. It’s definitely Home Assistant changes that have done it. If I query Hue manually all the correct replies are returned. It’s really annoying as I have been sat on an old version of Home Assistant now for ages as a result.

The newer versions also destroyed all the colour customisations I made. I know they made it clear they were changing them but they seem to remove more things than they fix lately.

I’m not sure if this will help with your issues but I discovered that my command line Hue Motion Sensor switches (to enable and disable the sensors) were working with say 1, 2 or possibly 3 switches but when I added more it started to play up. I since had the thought that maybe it was triggering all the switch queries at the same time and the Hue bridge was blocking some of them because all of a sudden 6 queries were being done at the same time.

I have now set the scan_interval of each one to a slightly different value (ie. 15 secs, 16 secs, etc.). This appears to be solving the issue here. Obviously it means some of them take slightly longer to detect a change but I can live with that if they stop randomly showing off when they are on!