cURL(ing) using Name vs IDX

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
liderbug
Posts: 20
Joined: Monday 02 January 2017 17:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

cURL(ing) using Name vs IDX

Post by liderbug »

I use:
http://sg53:8080/json.htm?type=command& ... itchcmd=On"
in place of "idx=" I would like to use "name=frontdoor" = ERR. I hope I'm just spelling 'name' wrong. If not, -> Suggestion Box

Thanks
User avatar
jvdz
Posts: 2269
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: cURL(ing) using Name vs IDX

Post by jvdz »

Not sure how you are scripting this, but I assume this all runs outside of the Domoticz events world.
This is a SH script I've played with to retrieve the IDX for a Name:

Code: Select all

#!/bin/bash
#--Get Domotics Device
IDX=`curl -s 'http://127.0.0.1:8080/json.htm?type=devices&order=name' | /usr/local/bin/jq -r '.result[]|select(.Name  == "'$1'")|.idx'`
if [ "$IDX" = "" ]; then
	echo "Switchname:$1 not found"
else
	echo "Switchname:$1 has IDX:$IDX"
fi


It can be run from the prompt like: scriptname.sh SwitchName
It does require jq to be installed.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
liderbug
Posts: 20
Joined: Monday 02 January 2017 17:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: cURL(ing) using Name vs IDX

Post by liderbug »

Ya, I see what you're doing in your script. I could do the same thing, sans jq (I'm not a json kind of guy), with a bash or php script. Kind of not the point though. Would be nice/cleaner if the internal dom code would accept "idx=" or "name=" or whatever. I'm assuming the internal code uses the database with a "select x from table where idx = 'n'" when a curl http:......idx=n happens.

Hello, code maintainers ....

Thanks
lost
Posts: 659
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: cURL(ing) using Name vs IDX

Post by lost »

liderbug wrote:Would be nice/cleaner if the internal dom code would accept "idx=" or "name=" or whatever.
In fact, implementation of JSON API looks sometimes a bit heterogenous!

See user variables related API:
getuservariable -> IDX required,
updateuservariable -> NAME required.

So if you need to read then update a user var from an external script using JSON API, you must know both (so you must at least check idx match name, as this is quite error prone)!

I think get and update were not implemented by the same guy, and they didn't had the same needs...
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest