Frigate storage usage sensor

Frigate integration creates whole bunch of sensors, but I missed storage usage sensors.
In case somebody else need the same here are how I did.
Frigate published MQTT topic: frigate/stats and data is JSON:

{
	"FRIG_2_NAPRIJED": {
		"camera_fps": 5.0,
		"process_fps": 5.0,
		"skipped_fps": 0.0,
		"detection_fps": 0.0,
		"detection_enabled": 1,
		"pid": 695,
		"capture_pid": 705,
		"ffmpeg_pid": 710
	},
	"FRIG_3_PRILAZ": {
		"camera_fps": 5.0,
		"process_fps": 5.0,
		"skipped_fps": 0.0,
		"detection_fps": 0.0,
		"detection_enabled": 1,
		"pid": 696,
		"capture_pid": 707,
		"ffmpeg_pid": 717
	},
	"FRIG_4_PROLAZ": {
		"camera_fps": 5.1,
		"process_fps": 5.1,
		"skipped_fps": 0.0,
		"detection_fps": 0.0,
		"detection_enabled": 1,
		"pid": 698,
		"capture_pid": 711,
		"ffmpeg_pid": 726
	},
	"FRIG_5_SJENICA": {
		"camera_fps": 5.1,
		"process_fps": 5.1,
		"skipped_fps": 0.0,
		"detection_fps": 0.0,
		"detection_enabled": 1,
		"pid": 699,
		"capture_pid": 716,
		"ffmpeg_pid": 724
	},
	"FRIG_1_ULAZ": {
		"camera_fps": 5.0,
		"process_fps": 5.0,
		"skipped_fps": 0.0,
		"detection_fps": 0.0,
		"detection_enabled": 1,
		"pid": 701,
		"capture_pid": 721,
		"ffmpeg_pid": 23720
	},
	"FRIG_6_KOTLOVNICA": {
		"camera_fps": 5.1,
		"process_fps": 5.1,
		"skipped_fps": 0.0,
		"detection_fps": 0.0,
		"detection_enabled": 1,
		"pid": 702,
		"capture_pid": 725,
		"ffmpeg_pid": 740
	},
	"FRIG_7_GARAZA": {
		"camera_fps": 5.1,
		"process_fps": 5.1,
		"skipped_fps": 0.0,
		"detection_fps": 0.0,
		"detection_enabled": 1,
		"pid": 704,
		"capture_pid": 729,
		"ffmpeg_pid": 79879
	},
	"detectors": {
		"coral": {
			"inference_speed": 7.65,
			"detection_start": 0.0,
			"pid": 686
		}
	},
	"detection_fps": 0.0,
	"gpu_usages": {
		"intel-vaapi": {
			"gpu": "15.43 %",
			"mem": "- %"
		}
	},
	"cpu_usages": {
		"top": {
			"cpu": "users,",
			"mem": "load"
		},
		"Tasks:": {
			"cpu": "stopped,",
			"mem": "0"
		},
		"%Cpu(s):": {
			"cpu": "id,",
			"mem": "0.6"
		},
		"MiB": {
			"cpu": "27412.3",
			"mem": "avail"
		},
		"PID": {
			"cpu": "%CPU",
			"mem": "%MEM"
		},
		"23719": {
			"cpu": "16.6",
			"mem": "0.3"
		},
		"711": {
			"cpu": "0.3",
			"mem": "0.3"
		},
		"725": {
			"cpu": "1.0",
			"mem": "0.3"
		},
		"726": {
			"cpu": "2.7",
			"mem": "0.2"
		},
		"22035": {
			"cpu": "3.3",
			"mem": "0.1"
		},
		"79879": {
			"cpu": "1.0",
			"mem": "0.2"
		},
		"100018": {
			"cpu": "2.7",
			"mem": "0.1"
		},
		"1": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"15": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"17": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"24": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"25": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"26": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"27": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"28": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"29": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"30": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"31": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"32": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"39": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"42": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"79": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"81": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"82": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"86": {
			"cpu": "3.0",
			"mem": "0.1"
		},
		"95": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"100": {
			"cpu": "2.7",
			"mem": "1.1"
		},
		"117": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"134": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"135": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"136": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"137": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"140": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"153": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"169": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"187": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"202": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"207": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"208": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"209": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"210": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"226": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"248": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"272": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"679": {
			"cpu": "0.0",
			"mem": "0.2"
		},
		"685": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"686": {
			"cpu": "0.0",
			"mem": "0.3"
		},
		"688": {
			"cpu": "1.3",
			"mem": "0.4"
		},
		"694": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"695": {
			"cpu": "0.7",
			"mem": "0.4"
		},
		"696": {
			"cpu": "0.0",
			"mem": "0.4"
		},
		"697": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"698": {
			"cpu": "0.3",
			"mem": "0.3"
		},
		"699": {
			"cpu": "0.3",
			"mem": "0.4"
		},
		"700": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"701": {
			"cpu": "0.3",
			"mem": "0.4"
		},
		"702": {
			"cpu": "0.7",
			"mem": "0.4"
		},
		"703": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"704": {
			"cpu": "0.3",
			"mem": "0.3"
		},
		"705": {
			"cpu": "1.0",
			"mem": "0.3"
		},
		"706": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"707": {
			"cpu": "1.3",
			"mem": "0.3"
		},
		"710": {
			"cpu": "3.7",
			"mem": "0.3"
		},
		"712": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"716": {
			"cpu": "1.0",
			"mem": "0.3"
		},
		"717": {
			"cpu": "3.7",
			"mem": "0.3"
		},
		"718": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"721": {
			"cpu": "1.7",
			"mem": "0.3"
		},
		"724": {
			"cpu": "4.3",
			"mem": "0.3"
		},
		"729": {
			"cpu": "0.3",
			"mem": "0.3"
		},
		"740": {
			"cpu": "3.3",
			"mem": "0.3"
		},
		"741": {
			"cpu": "0.7",
			"mem": "0.3"
		},
		"762": {
			"cpu": "0.7",
			"mem": "0.1"
		},
		"763": {
			"cpu": "0.7",
			"mem": "0.1"
		},
		"765": {
			"cpu": "0.3",
			"mem": "0.1"
		},
		"767": {
			"cpu": "0.7",
			"mem": "0.1"
		},
		"23720": {
			"cpu": "4.0",
			"mem": "0.3"
		},
		"79442": {
			"cpu": "0.0",
			"mem": "0.1"
		},
		"100329": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"100368": {
			"cpu": "0.0",
			"mem": "0.0"
		},
		"100370": {
			"cpu": "0.0",
			"mem": "0.0"
		}
	},
	"service": {
		"uptime": 60143,
		"version": "0.12.1-367d724",
		"latest_version": "0.12.1",
		"storage": {
			"/media/frigate/recordings": {
				"total": 539981.8,
				"used": 224441.6,
				"free": 288035.6,
				"mount_type": "ext4"
			},
			"/media/frigate/clips": {
				"total": 539981.8,
				"used": 224441.6,
				"free": 288035.6,
				"mount_type": "ext4"
			},
			"/tmp/cache": {
				"total": 16797.1,
				"used": 5904.7,
				"free": 10016.6,
				"mount_type": "overlay"
			},
			"/dev/shm": {
				"total": 2147.5,
				"used": 26.2,
				"free": 2121.3,
				"mount_type": "tmpfs"
			}
		},
		"temperatures": {},
		"last_updated": 1690609534
	}
}

Interesting was last section, “service”:
It was little bit tricky to extract values which I needed because of slashes in JSON dictionary names, but there are my sensors:

mqtt:
  sensor:
    - name: "frigate_storage_free_recordings"
      unique_id: "frigate_storage_free_recordings"
      state_topic: "frigate/stats"
      value_template: "{{ value_json.service['storage']['/media/frigate/recordings']['free'] / value_json.service['storage']['/media/frigate/recordings']['total'] * 100 }}"
      unit_of_measurement: '%'
      icon: mdi:database

    - name: "frigate_storage_free_clips"
      unique_id: "frigate_storage_free_clips"
      state_topic: "frigate/stats"
      value_template: "{{ value_json.service['storage']['/media/frigate/clips']['free'] / value_json.service['storage']['/media/frigate/clips']['total'] * 100 }}"
      unit_of_measurement: '%'
      icon: mdi:database

    - name: "frigate_storage_free_cache"
      unique_id: "frigate_storage_free_cache"
      state_topic: "frigate/stats"
      value_template: "{{ value_json.service['storage']['/tmp/cache']['free'] / value_json.service['storage']['/tmp/cache']['total'] * 100 }}"
      unit_of_measurement: '%'
      icon: mdi:database

    - name: "frigate_storage_shm"
      unique_id: "frigate_storage_free_shm"
      state_topic: "frigate/stats"
      value_template: "{{ value_json.service['storage']['/dev/shm']['free'] / value_json.service['storage']['/dev/shm']['total'] * 100 }}"
      unit_of_measurement: '%'
      icon: mdi:database

Hope that I helped somebody…

4 Likes

How would you create a GPU sensor?

I tried:

- sensor:
    name: "GPU - intel-vaapi"
    state_topic: "frigate/stats"
    value_template: "{{ value_json.service['gpu_usages']['intel-vaapi']['gpu'] }}
- sensor:
    name: "GPU - intel-vaapi"
    state_topic: "frigate/stats"
    value_template: "{{ value_json.gpu_usages.intel-vaapi.gpu }}"

didn’t work

I did!

- sensor:
    name: "GPU - intel-vaapi"
    state_topic: "frigate/stats"
    value_template: "{{ value_json.gpu_usages['intel-vaapi'].gpu }}"

Can you explain this with a little more detail on where this goes? I would like to see all this in home assistant.

This is what i need to detect the NAS storage is successfully connected. Because i had some issues, and Frigate start to use the internal storage, because when it started, the external storage was not available. And some days later i was shocked, when the internal ssd was full.
Thank you very much!
BR,
Zsolt

1 Like