Lua : how to read and update a text device?

Moderator: leecollings

Post Reply
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Lua : how to read and update a text device?

Post 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?
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
simonrg
Posts: 329
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8807
Location: North East England
Contact:

Re: Lua : how to read and update a text device?

Post 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
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Lua : how to read and update a text device?

Post 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.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
manjh
Posts: 749
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Lua : how to read and update a text device?

Post 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?
Hans
manjh
Posts: 749
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Lua : how to read and update a text device?

Post 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???
Hans
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua : how to read and update a text device?

Post 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...:)
manjh
Posts: 749
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Lua : how to read and update a text device?

Post 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?
Hans
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Lua : how to read and update a text device?

Post 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
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua : how to read and update a text device?

Post by dannybloe »

Why don't you use dzVents? Does it all for you and a lot easier.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest