Cours:InfoEmbarquee : Différence entre versions
Ligne 12 : | Ligne 12 : | ||
<source lang=bash> | <source lang=bash> | ||
− | + | /usr/local/bin/createHaSensor : | |
+ | #!/bin/bash | ||
+ | echo "name : $1" | ||
+ | echo "device class : $2" | ||
+ | echo "unit : $3" | ||
+ | |||
+ | topic="homeassistant/sensor/$1/config" | ||
+ | payload="{\"name\": \"$1\", \ | ||
+ | \"unique_id\": \"$1\", \ | ||
+ | \"state_topic\": \"homeassistant/sensor/$1/state\", \ | ||
+ | \"device_class\":\"$2\", \ | ||
+ | \"unit_of_measurement\":\"$4\" \ | ||
+ | }" | ||
+ | |||
+ | |||
+ | mosquitto_pub -t "$topic" -m "$payload" -h 192.168.0.7 | ||
+ | |||
+ | |||
+ | /usr/local/bin/deleteHaSensor : | ||
+ | #!/bin/bash | ||
+ | |||
+ | echo "name : $1" | ||
+ | echo "device class : $2" | ||
+ | echo "unit : $3" | ||
+ | |||
+ | topic="homeassistant/sensor/$1/config" | ||
+ | |||
+ | mosquitto_pub -t "$topic" -m "" -h 192.168.0.7 | ||
− | |||
− | |||
− | |||
</source> | </source> |
Version du 4 septembre 2023 à 20:33
Attiny10
script shell
mqtt
/usr/local/bin/createHaSensor :
#!/bin/bash
echo "name : $1"
echo "device class : $2"
echo "unit : $3"
topic="homeassistant/sensor/$1/config"
payload="{\"name\": \"$1\", \
\"unique_id\": \"$1\", \
\"state_topic\": \"homeassistant/sensor/$1/state\", \
\"device_class\":\"$2\", \
\"unit_of_measurement\":\"$4\" \
}"
mosquitto_pub -t "$topic" -m "$payload" -h 192.168.0.7
/usr/local/bin/deleteHaSensor :
#!/bin/bash
echo "name : $1"
echo "device class : $2"
echo "unit : $3"
topic="homeassistant/sensor/$1/config"
mosquitto_pub -t "$topic" -m "" -h 192.168.0.7