Cleaning 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

u01pei

Re: Cleaning IDX

Post by u01pei »

I found it also impossible to work with and remember all the idx numbers when writing a script. the first solution was to start referring to a idx number.
for instance: smoke="123", now i can create a script line such as: if [ $smoke = On ]; then......
Problem with this method was when a IDX changed I had to check all the scripts where this device might be used and change the idx number. This problem also had a solution: creating a source file.
the source file is just another .sh file stating all of the idx references. every script I create the first thing to enter is:
source /home/pi/domoticz/scripts/Config.sh (the file extension does not really matter, it can also be .txt etc)
Now it is no longer needed to enter all the idx references separately. just start creating the script, using the references such as $smoke.
In the source file you can arrange your devices by type or location, whatever pleases you.
When you replace a device because it failed or needs upgrading, you just need to replace the idx number in one location: the source file.

Another benefit from the source file is the use of standard functions. The source file states:
# Format: SWITCHDEVICE $IDXdevice NewState
SWITCHDEVICE() {
curl -s "$SERVER/json.htm?type=command&param=switchlight&idx=$1&switchcmd=$2"
}

In a script i type this line for switching a light on:
SWITCHDEVICE $Livingroom On

I find it keeps the script more readable and I use this for just about everything you can find in the domoticz API/JSON wiki page. Also great for notification messages. Instead of a long url line I use one word (PUSHDOORBELL) for triggering the notification when the doorbell rings. again when debugging or just making changes to a script I don't have to scan trough each line to see what it's function is. Just one word tells me all (and does it all).
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Cleaning IDX

Post by gizmocuz »

I am closing this topic as this does not make sense anymore.
We explained why/how it is used, and why you can not clean/reindex the IDX value of the tables, and this was the OP question.
Quality outlives Quantity!
Locked

Who is online

Users browsing this forum: No registered users and 1 guest