Page 1 of 1

How to get the IDX in bash ?

Posted: Friday 12 February 2016 11:45
by warp
How to get the IDX by the name of a device in bash?

Re: How to get the IDX in bash ?

Posted: Friday 12 February 2016 11:51
by paulvha
the best advice I can give is to use json connection: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL's
It is a very strong interface and good documented + a number of examples to start in the wiki

Re: How to get the IDX in bash ?

Posted: Friday 12 February 2016 12:05
by Egregius
Not really by name, but by sequence in a roomplan:
Part of a script I use to shutdown the NAS, except if one of these 2 switches is ON:
jq -r '.result[0].Status' = first switch in roomplan
jq -r '.result[1].Status' = second
...

Code: Select all

#!/usr/bin/bash
DOMOTICZ=`curl -s "http://192.168.0.8:8080/json.htm?type=devices&used=true&plan=6"`
KODI=`echo $DOMOTICZ | jq -r '.result[0].Status'`
if [[ $KODI = "On" ]]; then log "Kodi online, exiting"; exit; fi
log "Kodi Offline"

TOBI=`echo $DOMOTICZ | jq -r '.result[1].Status'`
if [[ $TOBI = "On" ]]; then log "TOBI online, exiting"; exit; fi
log "TOBI Offline"

Re: How to get the IDX in bash ?

Posted: Friday 12 February 2016 12:22
by jvdz
This should work based on the devicename. Save in a file like getidx.sh:

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
Then run: sh getidx.sh "switchname"

Jos

Re: How to get the IDX in bash ?

Posted: Friday 12 February 2016 16:44
by deennoo
Wrap post the same in a french forum, dont say hello, thanx or please and this the same here....un minimum de politesse !

Re: How to get the IDX in bash ?

Posted: Saturday 13 February 2016 17:16
by Catullus
V. Nov
V

M n.


Verzonden vanaf mijn iPhone met Tapatalk

Re: How to get the IDX in bash ?

Posted: Monday 15 February 2016 12:49
by warp
deennoo wrote:Wrap post the same in a french forum, dont say hello, thanx or please and this the same here....un minimum de politesse !
Désolé d'avoir oublié de dire bonjour, je pense que cela a du surement t'arriver aussi !
Il n'est pas n'nécessaire de me suivre a la trace pour me le faire remarquer !! C'est presque du harcèlement ! :cry: