• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Send display status to MQTT

Scheduled Pinned Locked Moved Troubleshooting
1 Posts 1 Posters 272 Views 1 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    DaVinki
    last edited by DaVinki Feb 28, 2021, 3:58 PM Feb 28, 2021, 3:57 PM

    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()
    
    

    I Have never done it before, so I think I can do it.

    1 Reply Last reply Reply Quote 0
    • 1 / 1
    1 / 1
    • First post
      1/1
      Last post
    Enjoying MagicMirror? Please consider a donation!
    MagicMirror created by Michael Teeuw.
    Forum managed by Sam, technical setup by Karsten.
    This forum is using NodeBB as its core | Contributors
    Contact | Privacy Policy