Command line sensor not showing up after moving config to sensors/ folder

Hello everyone,

I’m facing an issue with a command_line sensor in Home Assistant that works when defined directly in configuration.yaml but fails to appear when included from a separate YAML file. I’ve been troubleshooting this for a while and would appreciate some guidance.

What I’ve Done So Far:

I have a sensor defined in /homeassistant/configuration.yaml using
sensor: !include sensors/bitcoin_sensor.yaml.

The bitcoin_sensor.yaml file contains

- platform: command_line
  name: "BitcoinSensorRaw"
  command: "/bin/echo 123"
  value_template: "{{ value }}"

I confirmed the file is included correctly by intentionally adding a syntax error, which resulted in a log error: 2025-07-08 22:51:41.220 ERROR (SyncWorker_0) [annotatedyaml.loader] mapping values are not allowed here in “/config/sensors/bitcoin_sensor.yaml”, line 2, column 7.

I tested simpler commands like touch /tmp/test.txt, /bin/echo 123, and date, but none of them work – e.g., the file /tmp/test.txt is not created.

I switched the sensor to a template platform in the same file, and it worked fine:

- platform: template
    sensors: bitcoin_sensor_raw:
      value_template: "123"

When I moved the command_line sensor directly into configuration.yaml, it worked as expected.

I’m running Home Assistant as root (confirmed with ps aux | grep homeassistant), and file permissions are -rw-r–r-- for bitcoin_sensor.yaml.

I checked logs with tail -f /homeassistant/home-assistant.log, but there are no errors or mentions of the sensor when using command_line in the included file.

The Problem:

The command_line sensor does not appear in “Developer Tools > States” when defined in the included bitcoin_sensor.yaml file, even with simple commands like touch or echo. However, it works perfectly when placed directly in configuration.yaml. The logs are silent about any issues, and no files are created (e.g., /tmp/test.txt). I suspect it might be related to how included files are processed or the execution environment, but I’m out of ideas.

Request for Help:

Can anyone suggest why this might be happening or what I should check next? I’ve been testing this for more then 10 days already and I feel like I am dying, it should be very simple but I can’t make it work.
Any insights into differences between direct configuration and included files would be greatly appreciated. Please let me know if you need more details or log excerpts!

Thanks in advance!

start by using the proper format, the one above is quite old
Command line - Home Assistant

I’ve read the page and modified the test a bit.
In /homeassistant/configuration.yaml I have put:
sensor: !include_dir_merge_list /homeassistant/sensors/

and in /homeassistant/sensors/bitcoin_sensor.yaml :

- platform: command_line
  name: "test1001"
  command: "/bin/echo 123"
  value_template: "{{ value }}"

After restarting HA, I still don’t see test1001

What am I missing?

What you are showing above is still not (!) the format as described in the doc…

And I recommend to use packages instead of the above split-out, much easier as you donot need to refer to each yaml.

create folder config/packages
add this to config.yaml

homeassistant:
  packages: !include_dir_named packages 

and in the folder you can put files that each can contain any number of any types
Example: when you want to have a template, a command_line and a rest that all serve (say) “lights” you just created a mylights.yaml (name as you like) and put all three setups in that file.
I have a file that supports all my climate stuff, a file for my solar stuff, a file for location, etc.

Packages - Home Assistant

1 Like

Thank you, thank you, thank you!!!
I moved to packages and did the:
command_line:

  • sensor:
    name: “test1001”
    command: “/bin/echo 123”

and it now works :slightly_smiling_face:
I can move on with my life… you saved me !

Great, I am not sure why ‘packages’ seems to get little attention as for me it makes it a lot easier to maintain my yaml based stuff grouped in a file of my liking :slight_smile:
I have dozens of those yaml entities

1 Like