Page 1 of 1
Lua : how to read and update a text device?
Posted: Tuesday 01 March 2016 15:28
by Westcott
Hello,
I've got a Dummy device of Sensor type 'Text'
Unlike all my other devices, it does not respond to any Lua commands -
otherdevices[<text sensor>] returns nil
otherdevices[<text_sensor_idx>] returns nil
otherdevices_idx[<text sensor>] returns 0
commandArray[<text sensor>] = 'abc' is ignored
commandArray[<text_ensor_idx>] = 'abc' is ignored
Does anyone know how to use these devices with Lua?
Re: Lua : how to read and update a text device?
Posted: Tuesday 01 March 2016 19:27
by simonrg
otherdevices_svalue['device] retrieves the value
commandArray['UpdateDevice'] = idxoftext..'|0|'..'New Text' set the text
Code: Select all
-- script_device_text.lua
commandArray = {}
print('TextTest '..otherdevices_svalues['TextTest'])
ttidx = otherdevices_idx['TextTest']
print('TextTest idx '..ttidx)
newtext = 'Something New'
commandArray['UpdateDevice'] = ttidx..'|0|'..newtext
--commandArray['Study'] = 'Set Level 100'
return commandArray
Re: Lua : how to read and update a text device?
Posted: Tuesday 01 March 2016 20:19
by Westcott
SimonRG thanks!
It seems that my real problem was that this new device had somehow not made it into the event system after I added it.
It showed up in the GUI OK, and in a json output.
Restarting Domoticz fixed it.
Re: Lua : how to read and update a text device?
Posted: Saturday 25 November 2017 17:56
by manjh
The format of the update statement for the text suggests that there may be multiple strings stored in a text device:
idx|txtidx|text
for instant:
1250|0|text
But whichever txtidx I use, the text is always stored in the device in the same way.
So is there a way to store multiple text strings in one single text device?
Re: Lua : how to read and update a text device?
Posted: Tuesday 28 November 2017 19:15
by manjh
manjh wrote: ↑Saturday 25 November 2017 17:56
The format of the update statement for the text suggests that there may be multiple strings stored in a text device:
idx|txtidx|text
for instant:
1250|0|text
But whichever txtidx I use, the text is always stored in the device in the same way.
So is there a way to store multiple text strings in one single text device?
Anyone???
Re: Lua : how to read and update a text device?
Posted: Tuesday 28 November 2017 22:33
by Nautilus
Seems you've had a small misunderstanding here. The format refers to the general "UpdateDevice" syntax:
To modify an otherdevice value, you should use commandArray['UpdateDevice']='idx|nValue|sValue' where idx is the device index, nValue and sValue the values to modify (see json page for details - Domoticz API/JSON URL's)
(
https://www.domoticz.com/wiki/Events)
For text sensors nValue is always 0 and sValue holds the string to be updated. And idx is of course the sensors to be updated (the unique idx of the sensor). With that said, nothing is stopping you to combine multiple strings to the same text device, you just need to include them all in the "sValue" part of the syntax. You can even use basic html formatting (and if I remember correctly, in latest beta it also respects \n for newline etc.) to have a nice link or something else in the web gui...

Re: Lua : how to read and update a text device?
Posted: Tuesday 28 November 2017 22:50
by manjh
Nautilus wrote: ↑Tuesday 28 November 2017 22:33
Seems you've had a small misunderstanding here. The format refers to the general "UpdateDevice" syntax:
To modify an otherdevice value, you should use commandArray['UpdateDevice']='idx|nValue|sValue' where idx is the device index, nValue and sValue the values to modify (see json page for details - Domoticz API/JSON URL's)
(
https://www.domoticz.com/wiki/Events)
For text sensors nValue is always 0 and sValue holds the string to be updated. And idx is of course the sensors to be updated (the unique idx of the sensor). With that said, nothing is stopping you to combine multiple strings to the same text device, you just need to include them all in the "sValue" part of the syntax. You can even use basic html formatting (and if I remember correctly, in latest beta it also respects \n for newline etc.) to have a nice link or something else in the web gui...
OK, clear. Only one string per text device. Do you know the max length of that string?
Re: Lua : how to read and update a text device?
Posted: Tuesday 28 November 2017 23:48
by Nautilus
I am able to use quite long strings (e.g. google map link to a specific location with additional address text), but there's been some issues I guess:
viewtopic.php?t=18822
Re: Lua : how to read and update a text device?
Posted: Wednesday 29 November 2017 8:39
by dannybloe
Why don't you use dzVents? Does it all for you and a lot easier.