Help with JSon Somfy Command

Posted on
Wed Jun 13, 2018 10:00 am
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Help with JSon Somfy Command

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"}
Attachments
2018-06-13_08-47-58.jpeg
2018-06-13_08-47-58.jpeg (62.79 KiB) Viewed 449 times
2018-06-13_08-50-08.jpeg
2018-06-13_08-50-08.jpeg (34.4 KiB) Viewed 449 times
2018-06-13_08-50-35.jpeg
2018-06-13_08-50-35.jpeg (202.9 KiB) Viewed 449 times
Last edited by norcoscia on Wed Jun 13, 2018 1:10 pm, edited 1 time in total.

_______
Norm

Posted on
Wed Jun 13, 2018 10:17 am
jay (support) offline
Site Admin
User avatar
Posts: 14237
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with JSon Somfy Command

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 13, 2018 10:55 am
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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}
Attachments
2018-06-13_09-51-16.jpeg
2018-06-13_09-51-16.jpeg (131.15 KiB) Viewed 435 times
Last edited by norcoscia on Wed Jun 13, 2018 1:09 pm, edited 1 time in total.

_______
Norm

Posted on
Wed Jun 13, 2018 12:00 pm
jay (support) offline
Site Admin
User avatar
Posts: 14237
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with JSon Somfy Command

Afraid I can't help with the authentication failed message. Post the entire script and maybe something will jump out.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 13, 2018 1:18 pm
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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"

_______
Norm

Posted on
Wed Jun 13, 2018 1:53 pm
jay (support) offline
Site Admin
User avatar
Posts: 14237
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with JSon Somfy Command

Wait, what? I'm confused...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 13, 2018 1:59 pm
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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

_______
Norm

Posted on
Wed Jun 13, 2018 2:29 pm
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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.....

_______
Norm

Posted on
Wed Jun 13, 2018 3:01 pm
jay (support) offline
Site Admin
User avatar
Posts: 14237
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with JSon Somfy Command

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()

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 13, 2018 3:21 pm
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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()

_______
Norm

Posted on
Wed Jun 13, 2018 3:25 pm
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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)"

_______
Norm

Posted on
Wed Jun 13, 2018 3:38 pm
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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?

_______
Norm

Posted on
Wed Jun 13, 2018 3:47 pm
FlyingDiver offline
Posts: 2279
Joined: Jun 07, 2014
Location: Cape Coral, FL

Re: Help with JSon Somfy Command

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.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Jun 13, 2018 3:50 pm
norcoscia offline
User avatar
Posts: 474
Joined: Sep 09, 2015

Re: Help with JSon Somfy Command

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()

_______
Norm

Posted on
Wed Jun 13, 2018 5:01 pm
jay (support) offline
Site Admin
User avatar
Posts: 14237
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Help with JSon Somfy Command

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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 0 guests