Cours:BashScript : Différence entre versions

De troyesGEII
Aller à : navigation, rechercher
(Page créée avec « =script shell= ==mqtt== ===HA mqtt sensor=== * https://www.home-assistant.io/integrations/sensor/ * https://github.com/home-assistant/core/blob/dev/homeassistant/const... »)
 
Ligne 1 : Ligne 1 :
=script shell=
 
  
  
==mqtt==
+
=script pour homeAssistant avec broker mqtt==
  
  
Ligne 9 : Ligne 8 :
 
* https://github.com/home-assistant/core/blob/dev/homeassistant/const.py#L489
 
* https://github.com/home-assistant/core/blob/dev/homeassistant/const.py#L489
  
 +
/usr/local/bin/createHaSensor
 
<source lang=bash>
 
<source lang=bash>
 
/usr/local/bin/createHaSensor :
 
 
#!/bin/bash
 
#!/bin/bash
  
Ligne 25 : Ligne 23 :
 
           \"unit_of_measurement\":\"$3\" \
 
           \"unit_of_measurement\":\"$3\" \
 
         }"
 
         }"
 
  
 
mosquitto_pub -t "$topic" -m "$payload" -h 192.168.0.7
 
mosquitto_pub -t "$topic" -m "$payload" -h 192.168.0.7
 +
</source>
  
 
+
/usr/local/bin/deleteHaSensor :
/usr/local/bin/deleteHaSensor :
+
<source lang=bash>
 
#!/bin/bash
 
#!/bin/bash
  
Ligne 40 : Ligne 38 :
  
 
mosquitto_pub -t "$topic" -m "" -h 192.168.0.7
 
mosquitto_pub -t "$topic" -m "" -h 192.168.0.7
 +
</source>
  
 
+
/usr/local/bin/publishHaSensor :
/usr/local/bin/publishHaSensor :
+
<source lang=bash>
 
#!/bin/bash
 
#!/bin/bash
  
Ligne 58 : Ligne 57 :
  
 
mosquitto_pub -t "$topic" -m "$2" -h 192.168.0.7
 
mosquitto_pub -t "$topic" -m "$2" -h 192.168.0.7
 
 
 
</source>
 
</source>
  
 
'''Exemples''' :
 
'''Exemples''' :
 
*createHaSensor testCreate battery %
 
*createHaSensor testCreate battery %

Version du 22 novembre 2023 à 11:33


script pour homeAssistant avec broker mqtt=

HA mqtt sensor

/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\":\"$3\" \
         }"

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
/usr/local/bin/publishHaSensor :
#!/bin/bash

echo "name : $1"
echo "valeur : $2"

topic="homeassistant/sensor/$1/state"
payload="{\"name\": \"$1\", \
          \"unique_id\": \"$1\", \
          \"state_topic\": \"homeassistant/sensor/$1/state\", \
          \"device_class\":\"$2\", \
          \"unit_of_measurement\":\"$4\" \
         }"


mosquitto_pub -t "$topic" -m "$2" -h 192.168.0.7

Exemples :

  • createHaSensor testCreate battery %