mqtt_01.py

#!/usr/bin/python3
# ===================================================================
# From: www.steves-internet-guide.com/into-mqtt-python-client/
# ===================================================================

import paho.mqtt.client as mqtt


broker   = 'localhost'
instance = 'tom'
topic    = '/test/house/main_light'


print(f'creating new client instance {instance}')
client = mqtt.Client(instance)

print(f'connecting to broker {broker}')
client.connect(broker)

print(f'publish message to {topic}')
client.publish(topic,"OFF")