Command line sensor not updating

Hi,

I’ve seen similar topics on this forum but nothing matched my case.

I have this very simple command line sensor:

- platform: command_line
  name: Sensor1
  command: "python3 /config/sensor1.py"

When I reload the command line platform via the developer tools, HA executes the command and populates the sensor correctly. But then it will not update the sensor in regular intervals.

In the HA container’s shell I’m executing ps -ef just to check the PID and each time I do it, the PID of ps increases by one, meaning that HA is not executing any commands in the meantime.

I’ve also tried setting scan_interval explicitly and that changes nothing.

Any ideas?

Just noticed that the sensor did refresh after 1 hour since reloading the configuration. Which made me thinking…

I already had two command line sensors previously and they had scan_interval set to 3600. So I have removed scan_interval from both of them and reloaded the configuration again - no change. Then I have restarted HA and voilà!

So it appears that:

  1. scan_interval is shared among all command line sensors
  2. It takes a HA restart for the new scan_interval value to take effect

Is that an expected behaviour? I’d say at least (1) is a bug.

I can confirm the same issue, reloading the command line sensor updates the sensor, but does not affect the “scan_interval”, a restart (to reload the config as a whole) does the trick.

Interestingly, I noticed (at How to access core and supervisor CPU + MEM usage (HA OS) - #6 by e-raser) my CL sensors seem to only update when

  • manually reloading CL sensors
  • HA starts (of course, as all sensors are initialized)
  • using the homeassistant.update_entity service

Many of them seem to ignore the scan_interval, at least as discovered at How to access core and supervisor CPU + MEM usage (HA OS) - #6 by e-raser.

  • Has there been any change for CL sensors back in 2022?
  • Do we now need to use the homeassistant.update_entity service?

I can confirm this behaviour as well.
Anyone got time to file a bug?!

I created a bug refering to this if you want to update with findings

What version are you all on?