Skip to content

Instantly share code, notes, and snippets.

@aderusha
Created April 25, 2025 12:34
Show Gist options
  • Save aderusha/313c03c492270f1c54d0f1c3445be5c2 to your computer and use it in GitHub Desktop.
Save aderusha/313c03c492270f1c54d0f1c3445be5c2 to your computer and use it in GitHub Desktop.
command_line:
- sensor:
name: xl_tools_materials # sensor.xl_tools_materials
command: |-
bash -c '
USER="maker"
KEY="password"
IP="10.1.2.3"
JOB=$(curl -s --digest -u "$USER:$KEY" http://"$IP"/api/v1/job)
DL=$(echo "$JOB" | jq -r .file.refs.download)
readarray -t LINES < <( curl -s --digest -u "$USER:$KEY" http://"$IP""$DL" | strings | grep -m2 -E "^(filament_type=|filament used \[mm\]=)")
TYPES=${LINES[0]#filament_type=}
MMRAW=${LINES[1]##*]=}
IFS=";" read -ra MAT <<< "$TYPES"
IFS="," read -ra MM <<< "$MMRAW"
OUTPUT=""
for i in "${!MAT[@]}"
do
MM_TRIM=$(echo "${MM[$i]}" | xargs)
if echo "$MM_TRIM > 0" | bc -l | grep -q 1
then
OUTPUT+="T${i}:${MAT[$i]} "
fi
done
echo "${OUTPUT:-__none__}"
'
scan_interval: 86400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment