kvvhost

ram.py

May 17th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import paho.mqtt.publish as publish
  3. from subprocess import check_output
  4. from re import findall
  5.  
  6. def get_data():
  7. data = check_output(["sudo","bash","/home/osmc/mqtt/ram.sh"]).decode("UTF-8")
  8. return(findall("\d+",data)[0])
  9.  
  10. def publish_message(topic, message):
  11. print("Publishing to MQTT topic: " + topic)
  12. print("Message: " + message)
  13.  
  14. publish.single(topic, message, hostname="192.168.1.101", port="1883", auth=auth)
  15.  
  16. data = get_data()
  17. auth= {"username":"mqttusername", "password":"mqttpassword"}
  18. publish_message("homeassistant/kodi_rpi_bedroom/ram", data)
Add Comment
Please, Sign In to add comment