Run command_line at a fixed time and store output in entity?

Team,
After searching and testing like crazy I just have to consult your experience:

Goal: every day at 11:55 & 23:55 run a Python script that returns 3 values. These 3 values all have to be stored in their own entity.

  • command_line platform: is working except that it does not run at 2 specific times each day but way more often. Here’s what it looks like right now:
  - platform: command_line
    name: Recording_Count_DoorCam
    json_attributes:
      - DoorCam
    command: "python3 /config/python_scripts/synology_surveillance_station_countrecordings.py"
    value_template: "{{ value_json.DoorCam }}"

The python script relies on external libraries like requests.

Any idea how I can ‘run something’ at 11:55 and 23:55 and populate the 3 entities?
It feels like I missed a super obvious solution :slight_smile:

(BTW, once finished I will share the script & documentation.)

If you want to store the result you should be using a command line sensor.

Set the scan interval to a huge time (months).

Then use the update entity service in an automation triggered at the times you want it updated.

1 Like

That sounds like a great idea @tom_l !
I have

  1. added scan_interval = 315360000 (10 years) to the command_line sensor and
  2. created an automation with the service homeassistant.update_entity

Cheers
DJ