Weird problem

If you have a question or need help, this is the place to be.
Post Reply
Morten.T
Posts: 4
Joined: Fri Sep 06, 2019 8:33 am

Weird problem

Post by Morten.T » Fri Sep 06, 2019 8:52 am

Hi.

I have a problem with my EG. I have tried to explain my troubles here:
1) I turn on my Pioneer receiver, which sends this Event: Pioneer_AV_NET.PWR0.Pioneer_LX59.
2) A Python script turns on my JVC projector via LAN, without problem.

When done watching movies.
3) I turn off my receiver, which sends this Event: Pioneer_AV_NET.PWR1.Pioneer_LX59.
4) Another Python script should turn off my projector, but it does not. The script action is shown as executed in the log window, but nothing happens.
5) The script works fine, because If I manually right-click on the Macro where the turn off script is under, and chooses Execute Item, then it works and my projector turns off.
2019-09-06_10h03_30.png
Do anyone know what the problem could be? If you need more information, please tell me. :-)

Thank you and regards

Morten, Denmark.

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weird problem

Post by kgschlosser » Fri Sep 06, 2019 3:38 pm

can you do me a favor please..

i need you to right click on the folder that contains the 2 macros. then click on copy..

in a forum post add the "bb code" or tag before and after the data you paste. (remove the spaces from the tag) this is going to keep the formatting of the information.

[ code ]
PASTE HERE
[ /code ]

I am thinking we can compile your 2 scripts into a single script and do away with the enabling and disabling of macros. but i need to see the whole setup a code first.
If you like the work I have been doing then feel free to Image

Morten.T
Posts: 4
Joined: Fri Sep 06, 2019 8:33 am

Re: Weird problem

Post by Morten.T » Fri Sep 06, 2019 5:33 pm

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc6">
    <Folder Name="JVC LAN Control" XML_Guid="{6DA21C04-E765-4A98-B262-59F23C8BDA3F}" Expanded="True">
        <Macro Name="Tænd" id="6" XML_Guid="{7C755916-9730-4673-8DB4-66123CE84FE2}" Expanded="True">
            <Event Name="Pioneer_AV_NET.PWR0.Pioneer_LX59" XML_Guid="{B8AD7F3B-51B0-4360-B0B2-80EBD728B939}" />
            <Action Name="Tænd" XML_Guid="{22B547C9-3FC1-4F7C-BFE1-50D1FD9CD8E7}">
                EventGhost.PythonScript(u"import socket\nimport time\n\nclient_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\nclient_socket.connect(('192.168.1.15', 20554))\nclient_socket.send('PJREQ')\ntime.sleep(0.5)\nclient_socket.send('\\x21\\x89\\x01\\x50\\x57\\x31\\x0A')\ntime.sleep(0.5)\nclient_socket.close()")
            </Action>
            <Action XML_Guid="{3DCDF909-1549-4BEE-89EA-B6D0016305E9}">
                EventGhost.EnableItem(XmlIdLink(11))
            </Action>
            <Action XML_Guid="{09857493-FC75-4D26-A06F-E272F2A62DD3}">
                EventGhost.DisableItem(XmlIdLink(6))
            </Action>
        </Macro>
        <Macro Name="Sluk" id="11" Enabled="False" XML_Guid="{673380B3-A493-4DAA-A1FD-44733ADF53F9}" Expanded="True">
            <Event Name="Pioneer_AV_NET.PWR1.Pioneer_LX59" XML_Guid="{68360B47-D8F3-41E7-9F6F-5B17C1BC2F58}" />
            <Action Name="Sluk" XML_Guid="{22B547C9-3FC1-4F7C-BFE1-50D1FD9CD8E7}">
                EventGhost.PythonScript(u"import socket\nimport time\n\nclient_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\nclient_socket.connect(('192.168.1.15', 20554))\nclient_socket.send('PJREQ')\ntime.sleep(0.5)\nclient_socket.send('\\x21\\x89\\x01\\x50\\x57\\x30\\x0A')\ntime.sleep(0.5)\nclient_socket.close()")
            </Action>
            <Action XML_Guid="{C61CB6DA-552E-44BE-A892-6ADCA5FB26F7}">
                EventGhost.EnableItem(XmlIdLink(6))
            </Action>
            <Action XML_Guid="{4DF72A65-CF9D-4950-91D7-8BFFD4346C04}">
                EventGhost.DisableItem(XmlIdLink(11))
            </Action>
        </Macro>
    </Folder>
</EventGhost>
Like this?

Thank you :)

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weird problem

Post by kgschlosser » Sat Sep 07, 2019 2:13 am

that was perfect..

any time you paste any code you need to use the tag before and after. It keeps the formatting.


I just noticed this.. you have a different event in each of the macros.. there is no need for you to enable and disable macros.

I went ahead and condensed the whole thing into a single macro. so hopefully it will work for you now.
Read the comments in the script.


Copy all of the code below then go into EventGhost. single click on the PC icon at the top of the tree. then right click on it. select paste.
This is going to create a new folder and in that folder is the new macro.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="WIP-2018.05.25-17.43.19">
    <Folder Name="JVC LAN Control - condensed" Expanded="True">
        <Macro Name="Tænd" Expanded="True">
            <Event Name="Pioneer_AV_NET.PWR0.Pioneer_LX59" EventType="Event" />
            <Event Name="Pioneer_AV_NET.PWR1.Pioneer_LX59" EventType="Event" />
            <Action Name="Tænd / Sluk">
                EventGhost.PythonScript(u'\nimport socket\nimport time\n\ndef send():\n    # This is where we parse the event string\n    # we split it on the "." and grab the second\n    # item in the list. which is at index 1\n    cmd = eg.event.string.split(\'.\')[1]\n    \n    if cmd == \'PWR0\':\n        msg = \'\\x31\'\n    if cmd == \'PWR1\':\n        msg = \'\\x30\'\n    else:\n        # this is here just in case something is horribly amiss\n        print \'This should not happen\'\n        return\n        \n    client_socket.send(\'PJREQ\')\n    time.sleep(0.5)\n    # both commands are identical except for a single byte or hox code\n    # so we only need to add that one byte to the message\n    client_socket.send(\'\\x21\\x89\\x01\\x50\\x57\' + msg + \'\\x0A\')\n\n# this is going to seem kind of odd.\n# each time a python script gets run a snapshot is taken of all of the \n# variables in the script. So the next time it gets run the variables \n# are already there. The thing is when it is run for the first time\n# the variables do not exist. that is what we are testing for. \n# if the variable does not exist then we create it. \n# The purpose to this is to keep the connection open. so it does not \n# have to get recreated each and every time the script runs.\n# the benifit to this is speed. Creating a socket connection is expensive\n# in terms of performance. so if we use a connection that is already open\n# it is going to run much faster (except for the first time the script gets run)\ntry:\n    _ = client_socket\nexcept NameError:\n    # ok so the connection does not exist. now we make it.\n    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    client_socket.connect((\'192.168.1.15\', 20554))\n    \n    # this next bit is so that the socket gets closed when EG closes\n    # otherwise we can end up with an orphaned socket connection\n    # and this is something we do not want.\n    def close(_):\n            try:\n                client_socket.close()\n            except:\n                pass\n    \n            eg.Unbind(\'Main.OnClose\', close)\n        \n        eg.Bind(\'Main.OnClose\', close)\n\n# this next exception catching routine recreates the socket if it\n# happens to be closes. the other end terminated the connection \n# due to a timeout for example.\ntry:\n    send()\nexcept:\n    client_socket.connect((\'192.168.1.15\', 20554))\n    send()\n')
            </Action>
        </Macro>
    </Folder>
</EventGhost>
If you like the work I have been doing then feel free to Image

Morten.T
Posts: 4
Joined: Fri Sep 06, 2019 8:33 am

Re: Weird problem

Post by Morten.T » Sat Sep 07, 2019 9:58 am

Thank you very much. :D

I get this error in the log, when I try:

---> Welcome to EventGhost <---
Error compiling script.
Traceback (most recent call last):
IndentationError: unindent does not match any outer indentation level (2, line 55)
Autostart
Plugin: Pioneer_AV_NET
Pioneer_AV_NET: Add Host: 192.168.1.5
Pioneer_AV_NET: Host "Pioneer_LX59" added!
Pioneer_AV_NET: Host "Pioneer_LX59" found on the network, trying to connect to 192.168.1.5:8102 ...
Pioneer_AV_NET.PWR0.Pioneer_LX59
Pioneer_AV_NET: Send Command: host
Wait: 10.0 sec(s)
Auto Surround
Tænd
Tænd / Sluk
Error compiling script.
Traceback (most recent call last):
IndentationError: unindent does not match any outer indentation level (3, line 55)

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weird problem

Post by kgschlosser » Sun Sep 08, 2019 7:31 am

sorry about that. this should fix the problem

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="WIP-2018.05.25-17.43.19">
    <Folder Name="JVC LAN Control - condensed" Expanded="True">
        <Macro Name="Tænd" Expanded="True">
            <Event Name="Pioneer_AV_NET.PWR0.Pioneer_LX59" EventType="Event" />
            <Event Name="Pioneer_AV_NET.PWR1.Pioneer_LX59" EventType="Event" />
            <Action Name="Tænd / Sluk">
                EventGhost.PythonScript(u'\nimport socket\nimport time\n\ndef send():\n    # This is where we parse the event string\n    # we split it on the "." and grab the second\n    # item in the list. which is at index 1\n    cmd = eg.event.string.split(\'.\')[1]\n    \n    if cmd == \'PWR0\':\n        msg = \'\\x31\'\n    if cmd == \'PWR1\':\n        msg = \'\\x30\'\n    else:\n        # this is here just in case something is horribly amiss\n        print \'This should not happen\'\n        return\n        \n    client_socket.send(\'PJREQ\')\n    time.sleep(0.5)\n    # both commands are identical except for a single byte or hox code\n    # so we only need to add that one byte to the message\n    client_socket.send(\'\\x21\\x89\\x01\\x50\\x57\' + msg + \'\\x0A\')\n\n# this is going to seem kind of odd.\n# each time a python script gets run a snapshot is taken of all of the \n# variables in the script. So the next time it gets run the variables \n# are already there. The thing is when it is run for the first time\n# the variables do not exist. that is what we are testing for. \n# if the variable does not exist then we create it. \n# The purpose to this is to keep the connection open. so it does not \n# have to get recreated each and every time the script runs.\n# the benifit to this is speed. Creating a socket connection is expensive\n# in terms of performance. so if we use a connection that is already open\n# it is going to run much faster (except for the first time the script gets run)\ntry:\n    _ = client_socket\nexcept NameError:\n    # ok so the connection does not exist. now we make it.\n    client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    client_socket.connect((\'192.168.1.15\', 20554))\n    \n    # this next bit is so that the socket gets closed when EG closes\n    # otherwise we can end up with an orphaned socket connection\n    # and this is something we do not want.\n    def close(_):\n        try:\n            client_socket.close()\n        except:\n            pass\n    \n        eg.Unbind(\'Main.OnClose\', close)\n        \n    eg.Bind(\'Main.OnClose\', close)\n\n# this next exception catching routine recreates the socket if it\n# happens to be closes. the other end terminated the connection \n# due to a timeout for example.\ntry:\n    send()\nexcept:\n    client_socket.connect((\'192.168.1.15\', 20554))\n    send()\n')
            </Action>
        </Macro>
    </Folder>
</EventGhost>
If you like the work I have been doing then feel free to Image

Morten.T
Posts: 4
Joined: Fri Sep 06, 2019 8:33 am

Re: Weird problem

Post by Morten.T » Sun Sep 08, 2019 8:10 am

:-) I get this now:

---> Welcome to EventGhost <---
Autostart
Plugin: Pioneer_AV_NET
Pioneer_AV_NET: Add Host: 192.168.1.5
Pioneer_AV_NET: Host "Pioneer_LX59" added!
Pioneer_AV_NET: Host "Pioneer_LX59" found on the network, trying to connect to 192.168.1.5:8102 ...
Pioneer_AV_NET.PWR0.Pioneer_LX59
Pioneer_AV_NET: Send Command: host
Wait: 10.0 sec(s)
Auto Surround
Tænd
Tænd / Sluk
This should not happen

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weird problem

Post by kgschlosser » Sun Sep 08, 2019 12:57 pm

yes it should.

in your macros you had 2 events...

Pioneer_AV_NET.PWR0.Pioneer_LX59
Pioneer_AV_NET.PWR1.Pioneer_LX59

This is why your macros did not work. because you had each event in a different macro. and it would disable the macro with the other event. so when the other event triggered the macro was disabled so it would not run.

do you see the difference between the 2 events?

go and look at your old macros. I set the new script up so it would do exactly the same as what you had but with only a single script.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weird problem

Post by kgschlosser » Sun Sep 08, 2019 12:59 pm

maybe you had the events ass backwards? because i just realized you said the event PWR0 is when you turn your receiver on.. and that is not the case PWR1 is for when the receiver turns on I would imagine.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 5508
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: Weird problem

Post by kgschlosser » Sun Sep 08, 2019 1:00 pm

its an easy fix. locate in the script where you see 'PWR0' and PWR1' and switch them.
If you like the work I have been doing then feel free to Image

Post Reply