How can I change device name in LUA

Moderator: leecollings

Post Reply
artblue
Posts: 4
Joined: Wednesday 29 March 2017 21:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

How can I change device name in LUA

Post by artblue »

How can I change the name of the device in LUA? Is it possible at all?
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: How can I change device name in LUA

Post by lonebaggie »

You can use a json call :-

[url]http://IPADDRESS:PORT/json.htm?type=command&param=renamedevice&idx=IDX&name=DEVICENAME[/url]

replace uppercase chars with params

You can call the Json from within LUA use 127.0.0.1 as IP address

Beware command&param may cause ¶ error see

https://www.domoticz.com/forum/viewtopi ... 61&t=16912
artblue
Posts: 4
Joined: Wednesday 29 March 2017 21:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How can I change device name in LUA

Post by artblue »

Thanks. But... In browser is OK but in LUA not working :( I reordering indeed but still not working. Any ideas?
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How can I change device name in LUA

Post by jvdz »

It probably would help to show your LUA script so we can see whether that is indeed correct or not.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
artblue
Posts: 4
Joined: Wednesday 29 March 2017 21:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How can I change device name in LUA

Post by artblue »

If I set the switch action with link to json it doesn't work
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How can I change device name in LUA

Post by jvdz »

Understood something doesn't work, but you need to provide more information when you want anybody to help. ;)

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
artblue
Posts: 4
Joined: Wednesday 29 March 2017 21:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: How can I change device name in LUA

Post by artblue »

I'm a beginner and I'm just trying to write a script. I started with an switch action for test. And it does not work.
I need a simple script to check if a device is available. If so, it changes its name to $newdevicename so it is invisible.


I would like to customize this script to change the device name

Code: Select all


commandArray = {}

ping_success=os.execute('ping -c1 192.168.0.113') --tablet
if ping_success then
print("tablet online")
  here link to json to change device name 
else
print("tablet offline")
    here link to json to change device name 
end

return commandArray

What should I put in the script to work?
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: How can I change device name in LUA

Post by lonebaggie »

try

HttpPart=("curl 'http://127.0.0.1:8080/json.htm?param=re ... mmand&idx=" .. IDX .. "&name=" .. DEVICENAME .. "' &")
os.execute(HttpPart)

Where the variable IDX is the switch id you want to change and variable DEVICENAME is the new name of the device
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: How can I change device name in LUA

Post by jvdz »

I fail to understand why one would want to rename a device to reflect a status. I would simply have a device and set it to On or Off depending on whether it's online or not.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: How can I change device name in LUA

Post by lonebaggie »

I think it quite a neat idea by renaming the device $name you can make it disappear from the dashboard and then reappear when its available again.

I might use that to get round the 10 device limit on selector switches if i have 10 selector switches I can have 100 choices super selector and hide the 9 switches that have not been selected
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests