Email Alert when Input Threshold Reached

I found python mqtt not too hard to setup - I used paho.mqtt.client and found some useful hints on the web. If you are using mqtt on emoncms you’ll need the standard user and password if you’ve not changed them. This is how I’ve used it - my data is in a python dictionary data_dict[“A9val”] which publishes to emon/rain:

import paho.mqtt.client as mqttClient

def on_connect(client, userdata, flags, rc):
    if rc == 0:
        print("Connected to broker")
        global Connected
        Connected = True
    else:
        print("Connection failed")

Connected = False # for state value

broker_address = "192.168.20.xxx" # your broker address
port = 1883
user = 'emonpi'
password = 'emonpimqtt2016'
client = mqttClient.Client("Python")
client.username_pw_set(user, password=password)
client.on_connect = on_connect
client.connect(broker_address, port = port)
client.loop_start()

client.publish("emon/rain/rainfall",data_dict["A9val"])

``