Page 1 of 3

Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 10:00 am
by norcoscia
Hi, my new Somfy awning was installed yesterday - I hooked up a Somfy Mylink (IP to RTS bridge). I have the Mylink device working great and I can control the awning with my phone or alexa.

I'm trying to figure out how to control it with Indigo via JSon commands

I have been issuing commands via the terminal app and I can connect to the MYlink device fine - but when I try to issue a command I get a parsing error back.

See below for what I type and what comes back and examples from their API

Please help - been at it for hours and tried everything I can think of but I only get the same error back....

{
“METHOD” : “MYLINK.MOVE.DOWN”,
“PARAMS” : {"DEVICEID":“XXXXXX.1”},
“AUTH” : “Test”,
"ID" : 1
}
{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error"},"id":"null"}

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 10:17 am
by jay (support)
Looks like you might have some smart quotes in your JSON (at least that's what's showing in your post). If you typed that into the script text box then it's macOS being "helpful" and automatically converting them. Use a text editor that doesn't do smart substitutions then copy/paste it into the script edit dialog (or just run the script as an external script).

I think this is the JSON cleaned up:

Code: Select all
{
"METHOD" : "MYLINK.MOVE.DOWN",
"PARAMS" : {"DEVICEID":"CC1026D4.1"},
"AUTH" : "DeckAwning",
"ID" : 1
}


BTW, we'll have the "smart" quotes disabled in the script editor text field in the next release I think.

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 10:55 am
by norcoscia
Thank you so much Jay - that was the case - now I get a different error (below) - I have tried everything I can think of for the Authentication input but I always get the same message back.

I did also try this in a script - I seem to have it doing the same thing but I had to use the Cynical Network plug in to open the port (the terminal command "nc 192.168.1.55 44100") then I put the rest into a script - is there a way to send the "nc 192.168.1.55 44100" within an Indigo Python script and then also send the disconnect ("command C")?

Code: Select all
{
"METHOD" : "MYLINK.MOVE.DOWN",
"PARAMS" : {"DEVICEID":"XXXXXXXX.1"},
"AUTH" : "Test",
"ID" : 1
}
{"jsonrpc":"2.0","error":{"code":-32000,"message":"Authentication failed"},"id":1}

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 12:00 pm
by jay (support)
Afraid I can't help with the authentication failed message. Post the entire script and maybe something will jump out.

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 1:18 pm
by norcoscia
The whole script would look something like this if I did not make and break the connection using


nc 192.168.1.55
{
"METHOD" : "MYLINK.MOVE.DOWN",
"PARAMS" : {"DEVICEID":"XXXXXXXX.1"},
"AUTH" : "Test",
"ID" : 1
}
"control C"

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 1:53 pm
by jay (support)
Wait, what? I'm confused...

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 1:59 pm
by norcoscia
Sorry

two things need to happen to send the command from the terminal window

1st - the nc 192.168.1.55 44100 (this opens the telnet session to the Mylink device on its static IP on port 44100 (that is the port it listens on).

Then I type in the command which in my case is
{
"METHOD" : "MYLINK.MOVE.DOWN",
"PARAMS" : {"DEVICEID":"XXXXXXXX.1"},
"AUTH" : "Test",
"ID" : 1
}

then to close the telnet session I enter (control C) and hit enter

wondering if I can open the telnet (and close) via a script w/o using the Cynical Network plug in

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 2:29 pm
by norcoscia
I figured out the authentication problem - looks like it needs to be sent EXACTLY like this

{ "id":1, "method": "mylink.move.down", "params": { "auth": "YourSystemID", "targetID" : "AABBCC.1"} }

Down extends the awning and UP retracts it....

Happy to help if anyone else is having problems.....

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 3:01 pm
by jay (support)
norcoscia wrote:
wondering if I can open the telnet (and close) via a script w/o using the Cynical Network plug in


Yep, something like this is probably pretty close:

Code: Select all
import telnetlib
payload = '{ "id":1, "method": "mylink.move.down", "params": { "auth": "YourSystemID", "targetID" : "AABBCC.1"} }'
tn = telnetlib.Telnet(192.168.1.55, 44100)
# Write the JSON payload
tn.write(payload)
# Write the control-c - unclear if this is necessary or not
tn.write('\x03')
# Read the output if you want to look at it
reply = tn.read_all()
# You can then check the reply JSON for success/failure, etc.
# Close the connection
tn.close()

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 3:21 pm
by norcoscia
That will be cool - more question(s) :-)

If I need to wait a second or two for the telnet session to fully establish do I just insert a wait in the script (not sure how to do that) - will time.sleep work or do I need to import (time) for it to work in the script.

Then if I want to keep the reply do I need to pipe it into a indigo variable (or does it just go into the log - or somewhere else)?

Then (same question) to wait a few seconds before I close?

Something like this ?

Code: Select all
import telnetlib
import time
payload = '{ "id":1, "method": "mylink.move.down", "params": { "auth": "YourSystemID", "targetID" : "AABBCC.1"} }'
tn = telnetlib.Telnet(192.168.1.55, 44100)
time.sleep(2)
# Write the JSON payload
tn.write(payload)
time.sleep(6)
# Write the control-c - unclear if this is necessary or not
tn.write('\x03')
# Read the output if you want to look at it
reply = tn.read_all()
# You can then check the reply JSON for success/failure, etc.
# Close the connection
tn.close()

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 3:25 pm
by norcoscia
I get this compile error

Jun 13, 2018, 2:24:20 PM
Script Error embedded script: invalid syntax
Script Error around line 3 - "tn = telnetlib.Telnet (192.168.1.55, 44100)"

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 3:38 pm
by norcoscia
Seems to work when I add quotes around IP and port like this - not sure if I need the sleep stuff

tn = telnetlib.Telnet ("192.168.1.55", "44100")

But with or w/o the sleep stuff I get this

Jun 13, 2018, 2:36:20 PM
Schedule Test direct Sofy Extend
Error because embedded scripts execute sequentially they must complete their execution within 10 seconds.
Error modify the script to exit quickly or convert it to an external file (not embedded).
Stopping embedded script executor host (pid 2886)
Error process (pid 2886) failed to quit after polite request -- forcing it to quit now
Stopped "embedded script executor host"


But the awning is opening and closing?

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 3:47 pm
by FlyingDiver
Get rid of that tn.read_all() at the end, it's not doing anything for you. In fact, I expect all you really need is:

Code: Select all
import telnetlib
import time
payload = '{ "id":1, "method": "mylink.move.down", "params": { "auth": "YourSystemID", "targetID" : "AABBCC.1"} }'
tn = telnetlib.Telnet("192.168.1.55", 44100)
time.sleep(2)
# Write the JSON payload
tn.write(payload)
tn.close()


And I doubt you need that time.sleep(2) either.

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 3:50 pm
by norcoscia
Thanks Joe - looks like the sleep is not necessary either - working great with just this

import telnetlib
payload = '{ "id":1, "method": "mylink.move.down", "params": { "auth": "YourSystemID", "targetID" : "AABBCC.1"} }'
tn = telnetlib.Telnet ("192.168.1.55", "44100")
# Write the JSON payload
tn.write(payload)
# Close the connection
tn.close()

Re: Help with JSon Somfy Command

PostPosted: Wed Jun 13, 2018 5:01 pm
by jay (support)
The read is necessary to get the response if you want it (as I say in the script), and I also mentioned that the control-c might not be necessary.