How can I trigger a Python script on a remote RPi with HASS.IO?

why are you splitting files up anyway?
but a few things to notice:
you call myFunction() but you named it myfunction

and you use an arg inside myfunction and create it twice.

if you want it to be combined you need something like

import hdmi
def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.qos)+" "+str(msg.payload))
    print("Calling script to turn monitor off...")
    hdmi.myFunction(msg.payload.decode())

and hdmi.py

def myFunction(setting):
  if setting == "turn_monitor_off":
    print ( "I turned the screen off!" )
  elif setting == "turn_monitor_on":
    print ( "I turned the screen on!" )
  else:
    print ( "I got an unexpected setting!" )

and to show you how it would look as AD app:

import appdaemon.plugins.hass.hassapi as hass
class hdmi(hass.Hass):

  def initialize(self):
    self.listen_state(self.hdmi,"input_boolean.hdmi")

  def hdmi((self, entity, attribute, old, new, kwargs):
  if new == "off":
    print ( "I turned the screen off!" )
  else:
    print ( "I turned the screen on!" )

when you use an input_boolean to turn the tv on or off, but it could be done with any entity.

1 Like