#Need Help with Home Assistant Command Line Sensors for Proxmox Backup Server API

1 messages · Page 1 of 1 (latest)

zealous patrol
#

Hi,

I’m trying to retrieve information from my Proxmox Backup Server (PBS) via API to check if a task (such as a backup or sync) is currently running. Below is my current configuration:

configuration.yaml

shell_command:
  pbscookie: "curl --silent --insecure --data 'username=root@pam&password=*REDACTED*' https://192.168.178.4:8007/api2/json/access/ticket | jq --raw-output '.data.ticket' | sed 's/^/PVEAuthCookie=/' > /config/pbsapi.yaml"

command_line:
  - sensor:
      name: "PBS Read"
      command: >-
        curl --insecure --cookie "PBSAuthCookie=$(cat /config/pbsapi.yaml | cut -d'=' -f2)" https://192.168.178.4:8007/api2/json/admin/datastore/Internal_Backup/active-operations
      command_timeout: 10
      scan_interval: 60
      json_attributes:
        - data
      value_template: "{{ value_json.data.read | default(0) }}"

  - sensor:
      name: "PBS Write"
      command: >-
        curl --insecure --cookie "PBSAuthCookie=$(cat /config/pbsapi.yaml | cut -d'=' -f2)" https://192.168.178.4:8007/api2/json/admin/datastore/Internal_Backup/active-operations
      command_timeout: 10
      scan_interval: 60
      json_attributes:
        - data
      value_template: "{{ value_json.data.write | default(0) }}"```

**automations.yaml**
```YAML
- id: '1742383537191'
  alias: Get PBS Cookie
  description: ''
  trigger:
    - platform: time_pattern
      hours: /1
  condition: []
  action:
    - service: shell_command.pbscookie
  mode: single```

**What Works**
When running the curl command manually in the terminal, the desired output is successfully retrieved.
The pbsapi.yaml file is created, the token is correctly stored inside it.

**Issue**
The problem is that the sensors (sensor.pbs_read and _write) are not being created in Home Assistant. No matter what attributes I try to modify, the sensors do not show up.

Has anyone encountered a similar issue or have any idea how to fix this? Any help would be greatly appreciated!

Thanks!
vale frigate
#

Do you see anything in the logs about errors encountered when setting up these sensors?

#

From a quick reading of your code, you're using json_attributes without specifying json_attributes_path. Not sure if that will work.

sturdy salmon
#

I don't have answer to your question, but have to say that nicely done! I tried to do something similar, but thought it to be impossible to store the cookie, but that would really work.

I ended up doing that all in python script which I call with command_line automation.

zealous patrol