Open URL when Raspberry Pin was set by motion sensor

#1

Hi,

I have a little problem and also a solution but it doesn't work.
I want to open a URL like www.google.com when a Raspberry Pin was set by a motion detector (for example). The GPIO Pin is connected to the function and I can see over the debug window that a 1 (number / not string) comes out.
I wrote a Python function like this:


import webbrowser

if (msg['payload'] == 1):
webbrowser.open_new_tab('http://www.google.de')

I also can see that the if condition was true because when I write something like "abc" inside a failure occurs when the motion sensor was set.
It seems that the function webbrowser.open_new_tab('...') simply doesn work. Do you know why? Is there another solution for this problem? Perhaps with an Java function?

Regards, Thomas

#3

Some basics first

  1. what versions of NR, node.js and npm? (NR and node.js fersions can be gotten from the NR log)
  2. what version of the OS on the Pi are you using?
  3. can you provide a tripped down version of the flow that shows the issue? if so please do.
  4. where are you using the python function?

and finally, NR uses javascript not java.

p.s. when posting a flow, first enter a line of three back tics (```) followed by the flow then another line of three back tics

#4

Hi zenofmud,

here are my answers:

  1. Versions
    NR: 0.19.4
    Node.js: 8.12.0
    npm: I don't know

  2. Raspian GNU Linux 9 (stretch)

  3. Here is the flow - hope I did like you wanted me to do :joy::

[{"id":"68b7278f.a2fcf8","type":"python3-function","z":"4edba657.744748","name":"","func":"import webbrowser\n\nif (msg['payload'] == 1):\n    webbrowser.open_new_tab('http://www.google.de')\n    ","outputs":1,"x":470,"y":240,"wires":[[]]}]'''

javascript, yes you are right, sorry.

Thomas

#5

When I omport your flow and add a inject node sending a numeric 1 to it, it opens the google page.

Are you sure you are sending a numeric 1 and not a string 1 to the function? Add a debug node to the optput node that is sending to the function node. That way you will see the data being sent.