Two Tone Detect and Batch file - Alert System

Status
Not open for further replies.

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,545
Location
Massachusetts
King,

It sounds like you are a Windows man and I am not. My Windows experience, as limited as it was, ended with WinXP. I guess that makes me deprecated, right? I run TTD, node-red, and MQTT all on my raspberry pis. I did a little googling on installing an MQTT broker/server in Windows and it seemed rather complicated (How to Install The Mosquitto MQTT Broker- Windows and Linux). You don't need anything fancy at all, no WebSockets, probably none of any other options he addresses. Three command line entries are all it takes to set it up on a pi (Install Mosquitto Broker Raspberry Pi). If you have a pi, you could set that up as your server and run all your other programs on your windows computers if you like. The raspberry pi tutorial linked above has a pretty good graphic outlining the mqtt process.

1551728812611.png

When coupled with TTD, a simple python script becomes one of the devices on the right. When ttd decodes, the python code publishes a bit of information to a topic on the broker/server. Then every device on the left which has subscribed to this topic receives this bit of information. These devices can be smart outlets, light switches, etc. or an instance of node-red. Using node-red allows you to further process the information. There is a node-red node that subscribes to topics from an mqtt server. This all sounds complicated but is actually quite simple. The mqtt server is the heart of it. This server really retains none of the information bits that it serves up.

So the first step is to set up a MQTT server. There are several available free of charge on the internet that say they are available for "testing purposes" Maybe use one of those to start?

Here is the python code (mqtt.py) that I run from the alert_command option in TTD:

#!/usr/bin/python3

import os, glob, time, sys, datetime, json, time
import paho.mqtt.publish as publish
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("description")
args = parser.parse_args()

desc = args.description
split = desc.split('_')
town = split[0]
service = split[1]

publish.single("cmnd/sonoff/"+town+"/"+service+"/POWER", "on", hostname="pi_ip_address", auth = {'username':"UN", 'password':"PWD"})

quit()


I have formatted all my descriptions in TTD to be Town_Service. For example Boston_Fire or Boston_EMS. The above code then parses this description and publishes to a topic cmnd/sonoff/Town/Service/POWER on. That turns on a Sonoff smart outlet (S20) or any other sonoff device subscribed to that topic. This allows subscriptions to individual services or to all services connected to a town. The options are limitless.

In TTD tones.cfg the entry is alert_command = python mqtt.py [d]

For testing purposes if you get that far, subscribe to all topics on your mqtt server using the mqtt node in your node-red, pipe them to the debug window to see what the server is processing. The topic wildcard that gets you everything is #. So subscribe to # and you will see everything passing through your server.

Good luck, I hope that I have helped rather than discouraged you.

Jim
 
Joined
Oct 23, 2009
Messages
844
Location
Lincoln, NE
I got this going tonight. super awesome to have going!
I installed my broker with the built in MQTT in HASS.io
I am using a SDR with SDR# for the radio.
I installed mosquitto.org on windows 10. then by CMD i run mosquitto_pub

Here is what I have so far setup in my house. I rent right now so can't do much.

flow.PNG

And a Video.
 

davidVT

Member
Feed Provider
Joined
Aug 29, 2010
Messages
138
Location
Washington County,Vermont
Ah yes, nice to see progress with TTD , Node-red and MQTT!!

I still have my SONOFF 4 channel set up as a simple panel of lights to tell me if any of my 3 squads have had a call ‘today’.

Most of my Node-red and MQTT hobby work is drifting towards HOME ASSISTANT integration rather than TTD efforts of late.

One thing I have learned that may be relevant is how to bridge the MQTT brokers. I have two brokers inside my home network and an additional broker on the internet I built on a digital ocean server. The internet broker can be reached from anywhere while my home brokers are behind my paranoid firewall.

Example:
A temperature sensor system I built and loaned a friend is connected at his home. It will MQTT temperatures to my “internet” MQTT broker on a regular basis.

Having one of my home “private” brokers bridge subscribed to my “internet” broker, the friends data will automatically show up on the secure broker inside my home and then my NODE-RED and HASS systems. ** No router funny business or router forwarding is needed!!

If interested in MQTT bridge, let me know or do some google searching. Really quite handy.

David



Sent from my iPad using Tapatalk
 
Status
Not open for further replies.
Top