Create sensor from curl

OK so I solved this… 123 is getting the credit here for pointing me in the right direction.

My script running on the host via a cronjob every 5 minutes:

#!/bin/bash

curl -c cookie.txt -b cookie.txt -sf -L -d 'login_username=***username***' -d 'login_password=***pass***' --url 'https://my.aussiebroadband.com.au/usage.php?xml=yes' -k -o abbusage.log

# This next bit builds JSON out of the XML 

grep "down1" abbusage.log | sed 's/<down1>/{"download":/g' | sed 's/<[/]down1>/,/g' > abbusageedit.log
grep "up1" abbusage.log | sed 's/<up1>/"upload":/g' | sed 's/<[/]up1>/,/g' >> abbusageedit.log
grep "allowance1_mb" abbusage.log | sed 's/<allowance1_mb>/"allowance":/g' | sed 's/<[/]allowance1_mb>/,/g' >> abbusageedit.log
grep "lastupdated" abbusage.log | sed 's/<lastupdated>/"updated":"/g' | sed 's/<[/]lastupdated>/",/g' | sed 's/[ ]/T/g' | sed 's/T"/ "/g' >> abbusageedit.log
grep "rollover" abbusage.log | sed 's/<rollover>/"rollover":/g' | sed 's/<[/]rollover>/}/g' >> abbusageedit.log

# Publish to MQTT Broker

mosquitto_pub -h 10.90.11.100 -u ***username**** -P '***password***' -t abb/abbusage -f abbusageedit.log -r

This then creates 1 sensor with attributes if I include this in config yaml:

sensor:

# ABB Usage
  - platform: mqtt
    name: "ABB Last Updated"
    state_topic: "abb/abbusage"
    device_class: timestamp
    value_template: "{{ value_json.updated }}"
    json_attributes_topic: "abb/abbusage"

Result:
image

Now onto a lovelace card…

(I’m running the script on the host and I had to install mosquitto-clients package. From memory, the last time I tried a mosquitto_pub command via ssh addon, it is not available)