Command line Sensor: Template passed on to python script?

Hi everybody,

I am trying to utilize this.

There are these two sensors:

  - platform: command_line
    name: "Test/Tuertag"
    command: "python3 /config/packages/ -t {{ states('sensor.00test_coinslot_keypad_tag') }}"
  - platform: command_line
    name: "Test/Code"
    command: "python3 /config/packages/ -c {{ states('sensor.00test_coinslot_keypad_code') }}"

Let’s focus on Test/Code here. When I copy the command into developer-tools > templates, I get this command: "python3 /config/packages/ -c 1224". So the yaml itself should be correct.

However, sensor.test_code is unknown. The sensor will not change its status when manually updated (service: homeassistant.update_entity or service: command_line.reload).

When I manually run /config/packages/ -c 1224, it will return 1224 Testcode. So the python script itself works, too.

I added a print("ok") at the bottom of the script, so even if it were to run without the -c 1224 argument, it would return ok. But it stays unknown at all times.


I have a Wiegand 26 keypad connected to an ESPHome device. This will update the sensor.00test_* sensors whenever an RFID tag is scanned or a keycode has been collected.

Whenever this happens, I want to check the tag / code against a database I created (this is handled by the python script). If the tag / code exists, return some value (currently, the key and its value). This will later determine whether or not to open a door (via ESPHome output component connected to a 12V relay).

So far, everything works, except these sensors that are supposed to read the output of that python script.

While writing this, I created a third sensor, which runs the python script without any parameters; this stays unknown as well, so this doesn’t seem to be related to incorrect handling of the parameters. What else can I try to fix this?

Thank you in advance for your input :slight_smile:

  1. Obviously, check the HA logs for any error messages
  2. Obviously, check that /config/packages/ is actually available to the HA docker container

How did you do that? Did you actually entered the HA docker container (docker exec -it home-assistant bash or equivalent on your system) to execute the command?

Thank you.

2.: I have another (unrelated) python script as sensor in the same folder. This one works fine.

3.: I use hassOS, so I did not test this on the machine running it itself (which, when I ssh into it, doesn’t show anything for which python or which python3); the test was on my desktop pc, just confirming that the script itself worked fine.

Also, that other python script I mentioned does work on the same machine (hassOS), so while I cannot access it directly, python must be running on it somehow.