#!/bin/bash

#This script is provided by Chiunownow https://github.com/Chiunownow
#Thank you very much for providing this script
#This script is

#use e.g with that script: MySensor.sh
#!/bin/bash
#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
#./speedtest.py -d a4:c1:38:10:88:d5 -b 1000 -r --debounce --skipidentical 50 --name MySensor -c 1 --callback sendToMQTT

mosquitto_pub -h 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2_ping/config" -i "mibridge" -m '{"device_class": "ping", "name": "'$2'_ping", "unique_id": "speedtest_'$2'_ping", "device": { "name":"speedtest_'$2'", "identifiers": "speedtest_'$2'", "model": "speedtest", "manufacturer": "Ookla"}, "state_topic": "homeassistant/sensor/'$2'/state", "unit_of_measurement": "ms", "value_template": "{{ value_json.ping}}","platform": "mqtt" }'
mosquitto_pub -h 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2_upload/config" -i "mibridge" -m '{"device_class": "upload", "name": "'$2'_upload", "unique_id": "speedtest_'$2'_upload", "device": { "name":"speedtest_'$2'", "identifiers": "speedtest_'$2'", "model": "speedtest", "manufacturer": "Ookla"}, "state_topic": "homeassistant/sensor/'$2'/state", "unit_of_measurement": "Mbps", "value_template": "{{ value_json.upload}}","platform": "mqtt" }'
mosquitto_pub -h 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2_download/config" -i "mibridge" -m '{"device_class": "download", "name": "'$2'_download", "unique_id": "speedtest_'$2'_download", "device": { "name":"speedtest_'$2'", "identifiers": "speedtest_'$2'", "model": "speedtest", "manufacturer": "Ookla"}, "state_topic": "homeassistant/sensor/'$2'/state", "unit_of_measurement": "Mbps", "value_template": "{{ value_json.download}}","platform": "mqtt" }'
mosquitto_pub -h 192.168.0.150 -p 1883 -t "homeassistant/sensor/$2/state" -i "mibridge" -m '{ "ping": '$3', "upload": '$4', "download": '$5' }'
