<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Module Sending notification to a python project]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">can someone help me to create a simple module that send all notification from the magic mirror module to a python script. I need also some help to create the code in python to intercept the notification.</p>
<p dir="auto">Which goal ? I have a google assistant develop in python, i am using the facial recognition and i want to send notification from MMM-facial or other module to the google assistant which is develop in python to say something when a notification is received.</p>
<p dir="auto">here is the link of the google assistant project : <a href="https://github.com/shivasiddharth/GassistPi" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/shivasiddharth/GassistPi</a></p>
<p dir="auto">One other way is to create a module based on the python project but i do not know how to do it, and then it will received all the notification.</p>
<p dir="auto">I know there is a lot of assistant module for the magic mirror, but this one works very well, it has a lot of functionnality and  i can configure it easyly in french.</p>
<p dir="auto">thanks so much.</p>
]]></description><link>https://forum.magicmirror.builders/topic/7283/module-sending-notification-to-a-python-project</link><generator>RSS for Node</generator><lastBuildDate>Fri, 12 Jun 2026 05:09:45 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/7283.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 31 May 2018 14:45:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Module Sending notification to a python project on Mon, 04 Jun 2018 11:30:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bimbim2401" aria-label="Profile: bimbim2401">@<bdi>bimbim2401</bdi></a> Congratulations!</p>
]]></description><link>https://forum.magicmirror.builders/post/40188</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/40188</guid><dc:creator><![CDATA[idoodler]]></dc:creator><pubDate>Mon, 04 Jun 2018 11:30:04 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Mon, 04 Jun 2018 10:11:06 GMT]]></title><description><![CDATA[<p dir="auto">Hey,</p>
<p dir="auto">i have succeed to make it works with the following in the <a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow ugc">main.py</a>, my problem was due to the port which was already in use, and then i have to take another one.</p>
<p dir="auto">add the import</p>
<pre><code>from threading import Thread
from urllib.parse import unquote
</code></pre>
<p dir="auto">then just before the main function add</p>
<pre><code>class WebSocketsListener(Thread):
"""Thread chargé d'ecouter les messages sur la websocket."""

def __init__(self, assistant):
    Thread.__init__(self)
    self.websocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.websocket.bind(('127.0.0.1', 8081))
    self.assistant = assistant


def run(self):
    print ("Open socket")

    while True:
        self.websocket.listen(5)
        client, address = self.websocket.accept()
        print (format( address ))

        response = client.recv(255)
        if response != "":
            print (response)
            str_response = response.decode("utf-8")
            if 'assistant' in str_response:
                
                if 'mode' in str_response:
                    if 'start' in str_response:
                        print("start the assistant") 
                        self.assistant.start_conversation()
                    if 'stop' in str_response: 
                        print("stop  the assistant") 
                        self.assistant.stop_conversation()

                elif 'say' in str_response:
                    token = str_response[str_response.find("say=")+4:str_response.find("HTTP")-1]
                    token = unquote(token)
                    say(token)

    print ("Close socket")
    client.close()
    stock.close()
</code></pre>
<p dir="auto">in the main function just before the for event in events</p>
<pre><code>    webSocketsListener = WebSocketsListener(assistant)
    webSocketsListener.start()
</code></pre>
<p dir="auto">With this, open a web browser and write<br />
<a href="http://127.0.0.1:8081/assistant?mode=start" target="_blank" rel="noopener noreferrer nofollow ugc">http://127.0.0.1:8081/assistant?mode=start</a><br />
it will start manually the assistant like with the hotword"ok google"<br />
<a href="http://127.0.0.1:8081/assistant?mode=stop" target="_blank" rel="noopener noreferrer nofollow ugc">http://127.0.0.1:8081/assistant?mode=stop</a><br />
to stop the assistant if the conversation is too long<br />
<a href="http://127.0.0.1:8081/assistant?say=Hello" target="_blank" rel="noopener noreferrer nofollow ugc">http://127.0.0.1:8081/assistant?say=Hello</a> karim how are you<br />
and then gassistPI will say what you write</p>
<p dir="auto">in the magic mirror module, you have to send this request in the node helper.js</p>
<pre><code> socketNotificationReceived: function(notification, payload) {

    var res = "";
    var ipadress = "127.0.0.1";
    var port = "8081";


console.log("google assistant Node Helper Received a socket notification: " + notification + " payload:" + payload);
if (notification === "ASSISTANT_START"){
	request("http://"+ipadress+":"+port+"/assistant?mode=start", { json: true }, (err, res, body) =&gt; {
		if (err) { return console.log(err); }
		console.log(body.url);
		console.log(body.explanation);
	});
}
else if (notification === "ASSISTANT_STOP"){
	request("http://"+ipadress+":"+port+"/assistant?mode=stop", { json: true }, (err, res, body) =&gt; {
		if (err) { return console.log(err); }
		console.log(body.url);
		console.log(body.explanation);
	});
	
}
else if (notification === "ASSISTANT_SAY"){
	console.log("assistant payload:"+payload);
	request("http://"+ipadress+":"+port+"/assistant?say="+payload, { json: true }, (err, res, body) =&gt; {
		if (err) { return console.log(err); }
		console.log(body.url);
		console.log(body.explanation);
	});
}		
}	
</code></pre>
<p dir="auto">Thanks for your help</p>
]]></description><link>https://forum.magicmirror.builders/post/40187</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/40187</guid><dc:creator><![CDATA[bimbim2401]]></dc:creator><pubDate>Mon, 04 Jun 2018 10:11:06 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Sat, 02 Jun 2018 14:03:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bimbim2401" aria-label="Profile: bimbim2401">@<bdi>bimbim2401</bdi></a> I am not a Python guy either. Start small, create a simple Python script that establishes a Websocket connection, then interprete the websocket messages and so on…</p>
]]></description><link>https://forum.magicmirror.builders/post/40114</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/40114</guid><dc:creator><![CDATA[idoodler]]></dc:creator><pubDate>Sat, 02 Jun 2018 14:03:13 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Sat, 02 Jun 2018 13:52:16 GMT]]></title><description><![CDATA[<p dir="auto">Sorry but i cannot succeed to launch multiple script i found to intercept the get request from the module in python.</p>
<p dir="auto">i need some help … sorry this is my first program in python language</p>
<p dir="auto">Here is the script i want to modify : <a href="https://github.com/shivasiddharth/GassistPi/blob/master/src/main.py" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/shivasiddharth/GassistPi/blob/master/src/main.py</a></p>
]]></description><link>https://forum.magicmirror.builders/post/40111</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/40111</guid><dc:creator><![CDATA[bimbim2401]]></dc:creator><pubDate>Sat, 02 Jun 2018 13:52:16 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Fri, 01 Jun 2018 07:24:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bimbim2401" aria-label="Profile: bimbim2401">@<bdi>bimbim2401</bdi></a> Yep, on Windows its <code>F12</code>, on macOS its <code>alt</code> + <code>cmd</code> + <code>i</code>.</p>
<ul>
<li>Open the <code>Network</code>-Tab</li>
<li>Look for the status code <code>101</code> (Switching Protocols) or just look for the type <code>websocket</code></li>
<li>Open the request</li>
<li>Inspect the Socket as you wish (View frames, headers…)</li>
</ul>
]]></description><link>https://forum.magicmirror.builders/post/40060</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/40060</guid><dc:creator><![CDATA[idoodler]]></dc:creator><pubDate>Fri, 01 Jun 2018 07:24:07 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Thu, 31 May 2018 21:31:33 GMT]]></title><description><![CDATA[<p dir="auto">F12 and then network ? Right ?</p>
]]></description><link>https://forum.magicmirror.builders/post/40031</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/40031</guid><dc:creator><![CDATA[bimbim2401]]></dc:creator><pubDate>Thu, 31 May 2018 21:31:33 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Thu, 31 May 2018 17:36:25 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bimbim2401" aria-label="Profile: bimbim2401">@<bdi>bimbim2401</bdi></a> Well, my Python times are a long time ago. Just try to run this script ans log the output. I also highly recogmend you to open Chrome and look at the Websocket frames.</p>
]]></description><link>https://forum.magicmirror.builders/post/40004</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/40004</guid><dc:creator><![CDATA[idoodler]]></dc:creator><pubDate>Thu, 31 May 2018 17:36:25 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Thu, 31 May 2018 16:13:29 GMT]]></title><description><![CDATA[<p dir="auto">Thanks both for your response</p>
<p dir="auto">Do you think that the python code I have wrote is ok or can you give me the direction for the python code for listening to the notification</p>
]]></description><link>https://forum.magicmirror.builders/post/39998</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/39998</guid><dc:creator><![CDATA[bimbim2401]]></dc:creator><pubDate>Thu, 31 May 2018 16:13:29 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Thu, 31 May 2018 15:34:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bimbim2401" aria-label="Profile: bimbim2401">@<bdi>bimbim2401</bdi></a> Well, in Chrome I can see. That the MagicMirror Webclient establishes a Websocket connection to <code>ws://IP:8080/socket.io/?EIO=3&amp;transport=websocket&amp;sid=SOME_ID</code>. You can clearly see the communication, as the communication is not encrypted at all.</p>
]]></description><link>https://forum.magicmirror.builders/post/39993</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/39993</guid><dc:creator><![CDATA[idoodler]]></dc:creator><pubDate>Thu, 31 May 2018 15:34:57 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Thu, 31 May 2018 15:27:57 GMT]]></title><description><![CDATA[<p dir="auto">so i just need to create a websocket in a python script like this below ? and it will listen to all notification from the magic mirror sending by the method sendnotification ?</p>
<p dir="auto">import SocketServer</p>
<p dir="auto">class MyTCPHandler(SocketServer.BaseRequestHandler):<br />
“”"<br />
The RequestHandler class for our server.</p>
<pre><code>It is instantiated once per connection to the server, and must
override the handle() method to implement communication to the
client.
"""

def handle(self):
    # self.request is the TCP socket connected to the client
    self.data = self.request.recv(1024).strip()
    print "{} wrote:".format(self.client_address[0])
    print self.data
    # just send back the same data, but upper-cased
    self.request.sendall(self.data.upper())
</code></pre>
<p dir="auto">if <strong>name</strong> == “<strong>main</strong>”:<br />
HOST, PORT = “localhost”, 8080</p>
<pre><code># Create the server, binding to localhost on port 8080
server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)

# Activate the server; this will keep running until you
# interrupt the program with Ctrl-C
server.serve_forever()
</code></pre>
<p dir="auto">or do i have to add the MMM-WEBSOCKET module found here :<br />
<a href="https://github.com/JanLoebel/MMM-websocket" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/JanLoebel/MMM-websocket</a></p>
]]></description><link>https://forum.magicmirror.builders/post/39992</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/39992</guid><dc:creator><![CDATA[bimbim2401]]></dc:creator><pubDate>Thu, 31 May 2018 15:27:57 GMT</pubDate></item><item><title><![CDATA[Reply to Module Sending notification to a python project on Thu, 31 May 2018 15:20:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bimbim2401" aria-label="Profile: bimbim2401">@<bdi>bimbim2401</bdi></a> You just have to establish a Websocket connection from your Python module to the MagicMirror at port <code>8080</code>.</p>
]]></description><link>https://forum.magicmirror.builders/post/39991</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/39991</guid><dc:creator><![CDATA[idoodler]]></dc:creator><pubDate>Thu, 31 May 2018 15:20:31 GMT</pubDate></item></channel></rss>