nordeep
(Nordeep)
January 17, 2021, 11:34am
1
Hi All!
Can’t figure out. Why first curl
switch works perfect and second rest
not?
switch:
- platform: command_line
switches:
loved_track:
command_on: "/usr/bin/curl -X PUT -d 'loved=true' http://itunes.api.ip:8181/loved_track"
command_off: "/usr/bin/curl -X PUT -d 'loved=false' http://itunes.api.ip:8181/loved_track"
command_state: "/usr/bin/curl -k --silent http://itunes.api.ip:8181/loved_track"
command_timeout: 10
value_template: '{{ value_json.loved }}'
friendly_name: Loved Track
- platform: rest
resource: http://itunes.api.ip:8181/loved_track
method: put
name: Loved Track Rest
body_on: 'loved=true'
body_off: 'loved=false'
is_on_template: '{{ value_json.loved }}'
On REST API side I may see request body when curl
put request come. And empty request body when rest
switch request come.
Am I missing something?
fedot
January 17, 2021, 11:53am
2
Are you using https://github.com/maddox/itunes-api as the API server?
If so, I can’t find the loved_track
endpoint
nordeep
(Nordeep)
January 17, 2021, 1:32pm
3
Yes. I’m working on some useful features like - search, mark tracks as loved. I’ll think about Pull requests to the @maddox repository.
fedot
January 17, 2021, 1:41pm
4
Ah, I was wondering.
Reading about the upstream library, shouldn’t JSON work here as well?
- platform: rest
resource: http://itunes.api.ip:8181/loved_track
method: put
name: Loved Track Rest
body_on: '{"loved":"true"}'
body_off: '{"loved":"false"}'
headers:
Content-Type: application/json
is_on_template: '{{ value_json.loved }}'
nordeep
(Nordeep)
January 17, 2021, 1:49pm
5
For me it’s like hobby. I’m not expert in Javascript and especially AppleScript
About JSON - Nope.
Like shuffle
, volume
, etc - it’s simple variable=value
in the body.
fedot
January 17, 2021, 1:57pm
6
Well, look at that, there’s actually an example for your use-case in the RESTful Command Integration
So if you can’t get the switch working, you could at least try setting up a command, however I don’t think that sould give a different result
So this should work I guess:
- platform: rest
resource: http://itunes.api.ip:8181/loved_track
method: put
name: Loved Track Rest
body_on: 'loved=true'
body_off: 'loved=false'
content_type: "application/x-www-form-urlencoded"
is_on_template: '{{ value_json.loved }}'
nordeep
(Nordeep)
January 17, 2021, 4:15pm
7
Thank you! You are right. Must specify right content-type in header! Final version is:
- platform: rest
resource: http://itunes.api.ip:8181/loved_track
method: put
name: Loved Track Rest
body_on: 'loved=true'
body_off: 'loved=false'
headers:
Content-Type: application/x-www-form-urlencoded
is_on_template: '{{ value_json.loved }}'
PS: About additional itunes-api
endpoints. It would be great to integrate itunes-api
and Media Browser
. It doesn’t seem as impossible as how it looks first But a lot of work here.
JoaoM
(Joao)
January 26, 2021, 12:06pm
8
Hello,
Anyone knows why I’m get command failed?
thanks
switch:
- platform: command_line
switches:
cam_motion:
command_on: "/usr/bin/curl -u user:pass -X PUT -d '<PrivacyMask><enabled>true</enabled><normalizedScreenSize><normalizedScreenWidth>704</normalizedScreenWidth><normalizedScreenHeight>576</normalizedScreenHeight></normalizedScreenSize><PrivacyMaskRegionList><PrivacyMaskRegion><id>1</id><enabled>true</enabled><RegionCoordinatesList><RegionCoordinates><positionX>9</positionX><positionY>124</positionY></RegionCoordinates><RegionCoordinates><positionX>698</positionX><positionY>124</positionY></RegionCoordinates><RegionCoordinates><positionX>698</positionX><positionY>558</positionY></RegionCoordinates><RegionCoordinates><positionX>9</positionX><positionY>558</positionY></RegionCoordinates></RegionCoordinatesList></PrivacyMaskRegion></PrivacyMaskRegionList></PrivacyMask>' --digest http://192.168.X.X/ISAPI/System/Video/inputs/channels/1/privacyMask"