Sensor command_line not show on entity list

Hi,
HA 2025.1

Trying to configure for the first time few command_line sensors.

Put on my sensor.yaml the code below and restart.
But the entity does not show on the entity list.
Then I add the unique_id and still not show after the restart.
Checking the syntax on the developer tools , all is fine.
What could be wrong?

at home assistant log, do not show anything about.

sensors.yaml:

- platform: command_line
  name: CPFL Tarifa Vigencia Inicio
  unique_id: cpfl_tarifa_vigencia_inicio
  command: 'bash /config/root.bin/cpfl.tarifas/cpfl.tarifas.sh -s VigenciaIni '

- platform: command_line
  name: CPFL Tarifa Vigencia Fim
  unique_id: cpfl_tarifa_vigencia_fim
  command: 'bash /config/root.bin/cpfl.tarifas/cpfl.tarifas.sh -s Vigenciafimi '


This is the legacy format which might still work but do look here
Command line - Home Assistant

EDIT: and you can upscale to debug log to see if anything odd is happening

EDIT2: if you expect value back then you have to add a value_template, see the doc

Hi @vingerha ,

I checked the documentation multiple times.
It shows the syntax to use on the configuration.yaml

As far I know, when we split the yaml (use the !include), the syntax changes.
Also, I have other sensors for other platforms which work fine.

About the value_template, as far I understand reading the documentation, itā€™s useful only to format the data incoming. My intention is save the data in raw format .
It Isnā€™t required for sensors.

Iā€™ve enabled the debug mode and restarted.
It appears the engine ignored my declarations.

This is the part of my sensors.yaml (with linenumber).
Notice have a ā€œintegrationā€ platform before "command_line

 98
 99 - platform: integration
100   source: sensor.tomada_j_potencia
101   name: Energia consumida acumulada - Tomada J Lava e Seca 8kg
102   unit_prefix: k
103   round: 2
104
105 - platform: integration
106   source: sensor.tomada_k_potencia
107   name: Energia consumida acumulada - Tomada K
108   unit_prefix: k
109   round: 2
110
111 - platform: command_line
112   name: CPFL Tarifa Vigencia Inicio
113   unique_id: cpfl_tarifa_vigencia_inicio
114   command: 'bash /config/root.bin/cpfl.tarifas/cpfl.tarifas.sh -s VigenciaIni '
115
116 - platform: command_line
117   name: CPFL Tarifa Vigencia Fim
118   unique_id: cpfl_tarifa_vigencia_fim
119   command: 'bash /config/root.bin/cpfl.tarifas/cpfl.tarifas.sh -s Vigenciafimi '
120

At the log, they just stopped to load my sensors on ā€œsensor.tomada_k_potenciaā€ .

2025-01-10 16:20:53.890 INFO (MainThread) [homeassistant.components.sensor] Setting up integration.sensor
2025-01-10 16:20:53.891 DEBUG (MainThread) [homeassistant.components.integration.sensor] Restored state 82.79 and last_valid_state 82.79000000000000000000000000
2025-01-10 16:20:53.893 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.energia_consumida_acumulada_tomada_j_lava_e_seca_8kg, old_state=None, new_state=<state sensor.energia_consumida_acumulada_tomada_j_lava_e_seca_8kg=82.79; state_class=total, source=sensor.tomada_j_potencia, unit_of_measurement=kWh, icon=mdi:chart-histogram, friendly_name=Energia consumida acumulada - Tomada J Lava e Seca 8kg @ 2025-01-10T16:20:53.892624-03:00>>
2025-01-10 16:20:53.896 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for integration (281473211205888) took 5.81s (elapsed=5.81s) (wait_time=0.00s)
2025-01-10 16:20:53.899 DEBUG (MainThread) [homeassistant.components.mqtt.client] 192.168.5.2: unregister write 51
2025-01-10 16:20:53.900 INFO (MainThread) [homeassistant.components.sensor] Setting up integration.sensor
2025-01-10 16:20:53.902 DEBUG (MainThread) [homeassistant.components.integration.sensor] Restored state 178.45 and last_valid_state 178.4500000000000000000000000
2025-01-10 16:20:53.903 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.energia_consumida_acumulada_tomada_k, old_state=None, new_state=<state sensor.energia_consumida_acumulada_tomada_k=178.45; state_class=total, source=sensor.tomada_k_potencia, unit_of_measurement=kWh, icon=mdi:chart-histogram, friendly_name=Energia consumida acumulada - Tomada K @ 2025-01-10T16:20:53.902902-03:00>>
2025-01-10 16:20:53.906 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for integration (281473211206128) took 5.82s (elapsed=5.82s) (wait_time=0.00s)
2025-01-10 16:20:53.907 DEBUG (MainThread) [paho.mqtt.client] Received SUBACK
2025-01-10 16:20:53.908 DEBUG (MainThread) [homeassistant.helpers.translation] Cache miss for en: {ā€˜smartthinq_sensorsā€™}
2025-01-10 16:20:53.909 DEBUG (MainThread) [paho.mqtt.client] Sending SUBSCRIBE (d0, m37) [(bā€™homeassistant/event/+/+/configā€™, 0)]
2025-01-10 16:20:53.910 DEBUG (MainThread) [homeassistant.components.mqtt.client] 192.168.5.2: register write 51

Iā€™m missing something here?

Why would it do that? Again this is a legacy setup and it may work, I cannot comment on the content as I donot run the same scripts. Maybe someone else can chime in tomorrow (CET-time here) ?

Well, itā€™s a standard of organization , which everyone does and is quite common.

have yaml file for sensors, templates, secure, etcā€¦
configuration.yaml:

logger:
  default: info
  logs:
    homeassistant.setup: debug
    homeassistant.components.command_line.sensor: debug

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensors.yaml
template: !include template.yaml
input_select: !include input_select.yaml
input_text: !include input_text.yaml
input_boolean: !include input_boolean.yaml

So, looking better on the log , found this.
but I donā€™t see anything wrong, appear they processed

$ grep -i "command_line" home-assistant.log.1

2025-01-10 16:20:14.981 DEBUG (MainThread) [homeassistant.loader] Importing platforms for command_line executor=['sensor'] loop=[] took 1.85s
2025-01-10 16:20:15.018 DEBUG (MainThread) [homeassistant.loader] Component command_line import took 0.000 seconds (loaded_executor=False)
2025-01-10 16:20:15.020 INFO (MainThread) [homeassistant.setup] Setting up command_line
2025-01-10 16:20:15.041 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event service_registered[L]: domain=command_line, service=reload>
2025-01-10 16:20:15.042 INFO (MainThread) [homeassistant.setup] Setup of domain command_line took 0.02 seconds
2025-01-10 16:20:15.043 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=command_line>
2025-01-10 16:20:15.065 DEBUG (MainThread) [homeassistant.helpers.translation] Cache miss for en: {'command_line'}
2025-01-10 16:20:15.139 INFO (MainThread) [homeassistant.components.sensor] Setting up command_line.sensor
2025-01-10 16:20:15.140 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for command_line (281473211102560) took 0.08s (elapsed=0.08s) (wait_time=0.00s)
2025-01-10 16:20:15.149 INFO (MainThread) [homeassistant.components.sensor] Setting up command_line.sensor
2025-01-10 16:20:15.150 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for command_line (281473211102720) took 0.08s (elapsed=0.08s) (wait_time=0.00s)
2025-01-10 16:20:15.174 INFO (MainThread) [homeassistant.components.sensor] Setting up command_line.sensor
2025-01-10 16:20:15.175 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for command_line (281473211102880) took 0.11s (elapsed=0.11s) (wait_time=0.00s)
2025-01-10 16:20:15.178 INFO (MainThread) [homeassistant.components.sensor] Setting up command_line.sensor
2025-01-10 16:20:15.179 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for command_line (281473211103040) took 0.11s (elapsed=0.11s) (wait_time=0.00s)
2025-01-10 16:20:15.247 INFO (MainThread) [homeassistant.components.sensor] Setting up command_line.sensor
2025-01-10 16:20:15.250 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for command_line (281473211103120) took 0.18s (elapsed=0.18s) (wait_time=0.00s)
2025-01-10 16:20:15.267 INFO (MainThread) [homeassistant.components.sensor] Setting up command_line.sensor
2025-01-10 16:20:15.268 DEBUG (MainThread) [homeassistant.setup] Phase platform_setup for command_line (281473211103280) took 0.20s (elapsed=0.20s) (wait_time=0.00s)
2025-01-10 16:20:15.275 INFO (MainThread) [homeassistant.components.sensor] Setting up command_line.sensor

Please link the documentation that shows the use of platform: command_line.

Your syntax is outdated: it was deprecated in 2023.6 and removed in 2023.12. Instead of:

sensor:
  - platform: command_line

you should now use:

command_line:
  - sensor:

If you want to split the config, use:

command_line: !include command_line.yaml

then start that file with:

- sensor:
1 Like

Hi @Troon ,

Thanks for your answer , I use your suggestion to separate the command_file.yaml.
That works , where I need to use like :

- sensor:
    name: CPFL Tarifa Vigencia Inicio
    unique_id: cpfl_tarifa_vigencia_inicio
    command: 'bash /config/root.bin/cpfl.tarifas/cpfl.tarifas.sh -s VigenciaIni '

- sensor:
    name: CPFL Tarifa Vigencia Fim
    unique_id: cpfl_tarifa_vigencia_fim
    command: 'bash /config/root.bin/cpfl.tarifas/cpfl.tarifas.sh -s Vigenciafimi '


Abou where I get the previous syntax I was using, there is no clear documentation about it, I consider what I already done with others integration like I put on previous example (platform: integration) which works fine.
I donā€™t like this YAML standard, it is very confusing and not intuitive.
Indentation is a nice thing, but sometimes makes no sense like the code below, where they donā€™t work.
However, on another part of my YAMLs, this worksā€¦ really messy and annoying.

- sensor:
  name: CPFL Tarifa Vigencia Inicio
  unique_id: cpfl_tarifa_vigencia_inicio
  command: 'bash /config/root.bin/cpfl.tarifas/cpfl.tarifas.sh -s VigenciaIni '