Hi all,
Not sure if this is the right category to post this, so forgive me if I’m wrong. Basically, what I am trying to do is create a Python script to regularly check the outcome of “vcgencmd display_power” and send this status via MQTT.
This might allow me to sync the switch status on Home Assistent and Node Red. Using copy-paste, I have a start of a script, but it keeps giving error on the stdout variable. Could one of you please check?
#!/bin/bash
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
import subprocess
# This is the Subscriber
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
client.subscribe("thuis/woonkamer/scherm")
output = subprocess.check_output(['vcgencmd display_power'], stdout=subprocess.PIPE)
if stdout() == 'display_power 0':
client.publish(topic, msg)
client = mqtt.Client()
client.connect("192.168.2.150",1883,60)
#client.on_connect = on_connect
#client.on_message = on_message
client.loop_forever()