How to get the IDX in bash ?

Moderator: leecollings

Post Reply
User avatar
warp
Posts: 33
Joined: Thursday 07 May 2015 12:51
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Fr
Contact:

How to get the IDX in bash ?

Post by warp »

How to get the IDX by the name of a device in bash?
Raspberry 2B:RaZberry Z-Wave+:Edimax EW-7811UN:Huawei E220 3G
4xQubino ZMNHCA2
Everspring SE812 & ST812
Mcohome MH-S411 & MH-S412
2xAEON LABS ZW-100
2xFibaro FGSD-002:Fibaro FGFS-101:Fibaro FGS-221 & KLF-050
paulvha
Posts: 40
Joined: Friday 29 January 2016 16:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: How to get the IDX in bash ?

Post 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
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: How to get the IDX in bash ?

Post 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"
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How to get the IDX in bash ?

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
deennoo
Posts: 784
Joined: Wednesday 10 December 2014 13:06
Target OS: Linux
Domoticz version: beta
Location: Bordeaux France
Contact:

Re: How to get the IDX in bash ?

Post 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 !
Domoticz stable 3.5877 for real & Domoticz beta for test
Rfxtrxe / RFLink / Milight / Yeelight / Tasmota / MQTT / BLE / Zigate
http://domo-attitude.fr
Catullus
Posts: 1
Joined: Thursday 07 January 2016 16:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How to get the IDX in bash ?

Post by Catullus »

V. Nov
V

M n.


Verzonden vanaf mijn iPhone met Tapatalk
User avatar
warp
Posts: 33
Joined: Thursday 07 May 2015 12:51
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Fr
Contact:

Re: How to get the IDX in bash ?

Post 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:
Raspberry 2B:RaZberry Z-Wave+:Edimax EW-7811UN:Huawei E220 3G
4xQubino ZMNHCA2
Everspring SE812 & ST812
Mcohome MH-S411 & MH-S412
2xAEON LABS ZW-100
2xFibaro FGSD-002:Fibaro FGFS-101:Fibaro FGS-221 & KLF-050
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest