INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: Script, URL or MCWS to Remotely Trigger a Switch?  (Read 5915 times)

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
Script, URL or MCWS to Remotely Trigger a Switch?
« on: February 21, 2019, 05:06:40 am »

As per the subject, how to do this ...  ?

I'm using MC25 and I want to set up a shortcut on the desktop so that I can switch off three different switches with one click.


I found this piece of intel from a search (hopefully I haven't missed the obvious):
   https://yabb.jriver.com/interact/index.php/topic,105422.0.html
but I'm not seeing sub-folder /Engen1/ under the JRiver/Media Center 25/ program folder. I gather it was withdrawn at some stage in the past and the thread is simply out of sync?

I can see the limited detail at <IdPi Address>:52125/docs but I'm not sharp enough to make what I want to do happen from that advice without a whole heap of trial and error. The Wiki normally offers a start but not in this case.


When I run <IdPi Address>:52125/api/v1/nodes/ I get the following (trimmed down for convenience):
Quote
>result   
0:5   
association   
1   
command_list   {}
info   {}
name   {}
nodes   
maxnode   5
nodes   
0   1
2   
command_list   {}
info   {}
name   {}
nodes   
maxnode   5
nodes   []
association_groupings   
groupings   2
basic   {}
...
ident   
address   "0:5"
name   "ACA 2"
manufacturer_specific   
manufacturer_id   "aeon_labs"
product_id   96
product_type_id   515
...
generic_type   "switch_binary"
listening   true
security   28
sensor1000   false
sensor250   false
specific_type   "power_switch_binary"
switch_binary   
value   false

I've tried executing:
Code: [Select]
http://<IdPi Address>:52125/api/v1/nodes/5/switch_binary/value/truewhich seems logical to me given what I know but I get nothing from the switch and this from the browser:
Quote
{
  "params": {},
  "response": "0.00755",
  "result": {
    "error": "An internal error occurred.",
    "info": "result must be present"
  },
  "url": "http://<IdPi Address>:52125/api/v1/nodes/5/switch_binary/value/true",
  "url_path": "/api/v1/nodes/5/switch_binary/value/true"
}

Thanks in advance for any useful advice.
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #1 on: February 21, 2019, 05:24:20 am »

Found some clues from further searching (but no result).

I tried http://<IdPi Address>:52125/api/v1/nodes/5?name=switch_binary&value=true and got this in response:
Quote
   
params   
name   "switch_binary"
value   "true"
response   "0.00456"
result   
association   
1   
command_list   {}
info   {}
name   {}
nodes   
maxnode   5
nodes   
0   1
2   
command_list   {}
info   {}
name   {}
nodes   
maxnode   5
nodes   []
association_groupings   
groupings   2
basic   {}
color_supported   
colors   
0   "red"
1   "green"
2   "blue"
configuration   {}
health   
command_ack_time   
0   0.027976130761362177
1   "s"
2   "green"
command_error_rate   
0   0
1   "%"
2   "green"
command_response_time   
0   0.02094023721789946
1   "s"
2   "green"
commands_per_minute   
0   26.466583024685118
1   ""
2   "green"
log   0
report_dup_rate   
0   0
1   "%"
2   "green"
reports_per_hour   
0   0
1   ""
2   "green"
response_dup_rate   
0   2.658437009489782
1   "%"
2   "green"
response_error_rate   
0   0
1   "%"
2   "green"
response_success_rate   
0   100.05399279244192
1   "%"
2   "green"
ident   
address   "0:5"
name   "ACA 2"
manufacturer_specific   
manufacturer_id   "aeon_labs"
product_id   96
product_type_id   515
meter   
A   
meter   "electric"
precision   3
rate   "import"
scale   "A"
size   4
value   0
V   
meter   "electric"
precision   3
rate   "import"
scale   "V"
size   4
value   239.313
W   
meter   "electric"
precision   3
rate   "import"
scale   "W"
size   4
value   0
kWh   
meter   "electric"
precision   3
rate   "import"
scale   "kWh"
size   4
value   1.291
meter_supported   
meter   "electric"
reset   1
scales   
0   "kWh"
1   "W"
2   "V"
3   "A"
node_info   
cmdclasses   
0   "zwaveplus_info"
1   "switch_binary"
2   "switch_multilevel"
3   "switch_color"
4   "configuration"
5   "switch_all"
6   "meter"
7   "clock"
8   "association"
9   "association_grp_info"
10   "manufacturer_specific"
11   "version"
12   "firmware_update_md"
13   "powerlevel"
controlclasses   
0   "device_reset_locally"
1   "hail"
protocol   
basic_type   "routing_slave"
cap   83
generic_type   "switch_binary"
listening   true
security   28
sensor1000   false
sensor250   false
specific_type   "power_switch_binary"
switch_binary   
value   false
switch_color   
blue   
value   27
green   
value   20
red   
value   27
switch_multilevel   
value   0
version   
application   1
application_subversion   1
library   "slave_enhanced"
protocol   4
protocol_subversion   54
version_command   
association   
version   2
association_grp_info   
version   1
clock   
version   1
configuration   
version   1
firmware_update_md   
version   2
manufacturer_specific   
version   2
meter   
version   3
powerlevel   
version   1
switch_all   
version   1
switch_binary   
version   1
switch_color   
version   1
switch_multilevel   
version   2
version   
version   2
zwaveplus_info   
version   2
url   "http://<IdPi Address>:52125/api/v1/nodes/5?name=switch_binary&value=true"
url_path   "/api/v1/nodes/5"

At least no error but, still no result.
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

JimH

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 72536
  • Where did I put my teeth?
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #2 on: February 21, 2019, 06:19:35 am »

Did you try adding a scene in Panel?
Logged

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #3 on: February 21, 2019, 04:50:25 pm »

Did you try adding a scene in Panel?

No, because:
  • a Scene will flick the switch at the same time. I'm turning off a pre-amp and two power amps. Good practice recommends turning off the power amps first, then the pre-amp to minimise speaker thump. So, what I'm after is to run a sequence of steps with a time delay in between.
  • This still doesn't address the question of how to run this as script/batch file that I can associate with a desktop icon. If I can get the URL command to work, then I could potentially enlist this kind of thinking to get the job done - https://stackoverflow.com/questions/36947181/execute-a-url-from-a-command-line-without-opening-a-browser-in-windows

I realise that there's probably scope to use PowerPlay to run a shutdown action when I stop playback or move away from my playback zone but this seems a bit brutal if I'm just wanting to quickly change tack, when I know I'll head back to music playback. 
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

drmimosa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 691
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #4 on: February 26, 2019, 05:22:44 am »

The urls look wrong.

Device off:

http://<IdPi Address>:52125/alpha000/basic_set?node=<node of device>&value=0

Device on:

http://<IdPi Address>:52125/alpha000/basic_set?node=<node of device>&value=1

You can find the device node from the Engen Panel, I think. [Edit: it's in the 'address:' field in your previous calls, looks like you want node 5.]

If I recall, this just about was the first functionality built into Engen, the thread with this info is somewhere in the early days. There are a lot of scripting possibilities available, type

http://<IdPi Address>:52125/alpha000/

for a very basic API.

Probably goes without saying dude, but all ip addresses are in your LAN.
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #5 on: April 09, 2019, 02:11:59 pm »

I found when I was building a number of Engen events into my Home Assistant setup that the alpha000 was much slower to update the state of the device vs the /api/v1/.  That might have been a random thing, but I moved to using the api address instead with post events.  If you can do that, it might be better:

Code: [Select]
rest_command:
  engen_api:
    url:  http://<engenIP>:52125/api/v1/nodes/{{ node }}/{{ path }}
    method: POST
    headers:
      content-type: application/json; charset=UTF-8
    payload: '{{ value }}'

Code: [Select]
{
  "node": 3,
  "path": "switch_binary/value",
  "value": 1
}

Logged

drmimosa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 691
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #6 on: April 30, 2019, 02:09:02 pm »

Hoyt, if you had time could you write the syntax for a couple examples using the API?

For example, I'm trying to turn a scene on and off called Outside.

This works:

curl -s 'http://192.168.1.200:52125/alpha000/scene?name=Outside'

But this doesn't:

curl -s 'http://192.168.1.200:52125/api/v1/scenes/Outside/on'

Also, do you know a good resource I can read to learn how to make sense of POST and GET commands? Thanks a lot, cheers!
Logged

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #7 on: May 04, 2019, 06:23:45 pm »

Sorry I didn't see this earlier.  Your curl isn't posting any data.  When you call an API that expects POST data, you need to do it with the --data parameter for a curl command line request.  I haven't done much with scenes, but I just tried this and it worked:

Code: [Select]
curl  --data '' http://192.168.2.12:52125/api/v1/scenes/Living%20Room%20Fan%20Light%20On/on
That's odd and not how I have any of my switches setup, but I haven't done much with scenes, so perhaps they're different.  Typically what I do with an individual switch is this (I have to include header data or I get an error):

Code: [Select]
curl  --data '{"value":0}' --header "content-type: application/json; charset=UTF-8" http://192.168.2.12:52125/api/v1/nodes/0:4/switch_binary
You asked about how to figure this out, and what I typically do is open up Chrome, open the developer tab, and hit the links, then view the information to see what Engen's page just did.  Then I try to mimic that in a curl command.  Once I get it all worked up, then I'll put it into whatever other program I'm using to actually send the data to Engen.

Hopefully that helps a bit.  I'm sure JRiver can answer a lot more questions about how the API works than I can, I've just figured out how to mess around with and figure out what works for me...
Logged

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #8 on: May 12, 2019, 08:06:06 am »

Thanks for the responses.

I'll give this a digest and see what I can work out.

Don't be surprised if I ask follow on questions.
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

drmimosa

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 691
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #9 on: June 23, 2019, 05:16:41 pm »

hoyt, thanks for posting the correct Engen curl commands above. Finally had some time to try them and they worked as expected.

Cheers!
Logged

astromo

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2251
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #10 on: September 22, 2019, 04:26:30 am »

Just to round this out for my future reference, this is what I found worked from drmimosa's intel via a Window's cmd command line:

Turn Switch On:
Code: [Select]
curl -s "http://<IdPi Address>:52125/alpha000/basic_set?node=<node of device>&value=1"
Turn Switch Off
Code: [Select]
curl -s "http://<IdPi Address>:52125/alpha000/basic_set?node=<node of device>&value=0"
hoyt's advice didn't work for me ... yet.
Logged
MC33, Win10 x64, HD-Plex H5 Gen2 Case, HD-Plex 400W Hi-Fi DC-ATX / AC-DC PSU, Gigabyte Z370 ULTRA Gaming 2.0 MoBo, Intel Core i7 8700 CPU, 4x8GB GSkill DDR4 RAM, Schiit Modi Multibit DAC, Freya Pre, Nelson Pass Aleph J DIY Clone, Ascension Timberwolf 8893BSRTL Speakers, BJC 5T00UP cables, DVB-T Tuner HDHR5-4DT

hoyt

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 867
Re: Script, URL or MCWS to Remotely Trigger a Switch?
« Reply #11 on: October 03, 2019, 12:48:45 pm »

Just to round this out for my future reference, this is what I found worked from drmimosa's intel via a Window's cmd command line:

Turn Switch On:
Code: [Select]
curl -s "http://<IdPi Address>:52125/alpha000/basic_set?node=<node of device>&value=1"
Turn Switch Off
Code: [Select]
curl -s "http://<IdPi Address>:52125/alpha000/basic_set?node=<node of device>&value=0"
hoyt's advice didn't work for me ... yet.

I should have pointed out that what I do is typically on mac or linux.  So it very well could be different using window's curl command... I can't say I've ever tried that.  My only windows desktop these days is my MC server itself. 

It also may be different using the alpha000 vs the api/v1 location.  I had a number of things setup with alpha000, but when I tried to get the status of the event (ie, turn on the lights, and now check to see if the lights are on to toggle the light on switch), I noticed a good delay.  When I got the api/v1 address working, the response was much faster. 

I do clarify all of this by saying, I don't really know what I'm doing, I just guess and figure out what works :)
Logged
Pages: [1]   Go Up