api-call only by idx or by device name as well

Python and python framework

Moderator: leecollings

Post Reply
Tukker
Posts: 674
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

api-call only by idx or by device name as well

Post by Tukker »

Hi,
In python I can do an api-call like this:

Code: Select all

SENSOR = "http://192.168.2.1:8080/json.htm?type=devices&rid=1"
In dzVents I can lookup a device by name like

Code: Select all

devices = { 'CV_switch_manual' }
Is it possible to do an api-call in python by name like:

Code: Select all

SENSOR = "http://192.168.2.1:8080/json.htm?type=devices&rid=Oregon"
Or didn't I search enough.
Bugs bug me.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: api-call only by idx or by device name as well

Post by waaren »

HvdW wrote: Thursday 23 April 2020 22:59 Is it possible to do an api-call in python by name like:

Code: Select all

SENSOR = "http://192.168.2.1:8080/json.htm?type=devices&rid=Oregon"
Not possible in one pass. Not from Python nor from any other language. It is not available as API call in domoticz

What you can do is call

Code: Select all

http://192.168.2.1:8080/json.htm?type=command&param=devices_list

to get a JSON of all deviceNames / idx and
process that list to extract the idx belonging to the name you want.

Or (probably quicker) just get all devices from domoticz using

Code: Select all

http://192.168.2.1:8080/json.htm?type=devices
and walk the list with the devicename as searchkey to find your device
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Tukker
Posts: 674
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: api-call only by idx or by device name as well

Post by Tukker »

Thanks @waaren
Bugs bug me.
Post Reply