Hello everyone,
I’m facing a persistent issue with a command_line
sensor in my Home Assistant configuration and, despite extensive troubleshooting, I can’t get it to work correctly. The sensor entity seems to be registered, the command appears to be triggered, but the sensor’s state does not reflect the expected command output.
My Goal : Create a sensor to get the state of the Matterbridge add-on using the command ha addons info a1b84aa7_matterbridge | grep 'state' | awk '{print $2}' | tr -d '"'
.
My current yaml configuration
command_line:
- sensor:
name: etat_matterbridge
unique_id: etat_matterbridge
command: "echo START_MATTERBRIDGE_STATE && ha addons info a1b84aa7_matterbridge | grep 'state' | awk '{print $2}' | tr -d '\"' 2>&1 && echo END_MATTERBRIDGE_STATE"
scan_interval: 60
command_timeout: 15 # Added during debugging
When I go into Developper/States, the sensor state is :
START_MATTERBRIDGE_STATE END_MATTERBRIDGE_STATE
No error in the logs, just this.
(We should be seeing the command return in the middle. It also doesn’t work without these “start” and “end” parts, It’s just the result of a lot of testing)
When I run the command " ha addons info a1b84aa7_matterbridge | grep ‘state’ | awk ‘{print $2}’ | tr -d ‘"’ " in the terminal module, the return is « started » or « stopped » accordingly.
I use HAOS in a VM, and I’ve read some posts pointing out this note in the documentation: :
Note
If you are using Home Assistant Operating System, the commands are executed in the homeassistant container context. So if you test or debug your script, it might make sense to do this in the context of this container to get the same runtime environment.
As I’m not trying to get out of the homeassistant container to get things like the PC specs or such, I think my command should be working.
Also, I tested the “badlogin” sensor example in the documentation but this time it’s working!
My yaml :
command_line:
- sensor:
name: Badlogin
command: "grep -c 'Login attempt' home-assistant.log"
scan_interval: 60
(You will see that I adjusted the path part to fit my directories structure)
What am I missing?
Thank you for your time.