Page 1 of 1

Readout Lightsensors in Lua

Posted: Thursday 26 November 2020 14:45
by Toulon7559
{The svalue-list of Domoticz shows for the various devices number-strings of defined layout per type of device.}
Readout from a device-string can usually be done by means of otherdevices_svalues[.....]:
for a single value-device

Code: Select all

value = otherdevices_svalues[.....]
for a multiple-value device with elements separated by ;

Code: Select all

value1, value2 = otherdevices_svalues[.....]:match("([^;]+);([^;]+)")
{In the device-list} Lux-devices not only have a number in an element-field, but also a related text for the unit (see example below for a device-list):
{that may also -accidentially- occur in the svalue-list for 'home-made' virtual devices.}
For extraction of values then you could also use a construction like below, which 'differently' looks at the string

Code: Select all

sLux5_string = otherdevices_svalues[SI1145Lux]
sLux5, sLux_txt = sLux5_string:match("(.*)% (.*)")
List of Lux-devices
List of Lux-devices
screenshot-Domoticz_LuxDevices-2020.11.26-14_10_27.png (81.14 KiB) Viewed 313 times
A lot of 'main' device-strings (like temp, hum, barometer and wind) have a dedicated version of 'otherdevices', enabling direct extraction of a specific element from a string with several elements, like examples below

Code: Select all

otherdevices_winddir[WindMeter1]
otherdevices_windspeed[WindMeter1]
otherdevices_windgust[WindMeter1]
otherdevices_uv[SI1145UVI]
For latter an example list of devices.
List of UV-devices
List of UV-devices
screenshot-Domoticz_UVDevices-2020.11.26-14_09_11.png (91.36 KiB) Viewed 313 times
First aspect that surprises, is that Light has no dedicated, easy 'otherdevices' to extract the Lux-value, equivalent to otherdevices_uv:
is a specific reason for this absence? If no specific reason, suggestion to add a variant otherdevices_lux
Second aspect, which puzzles (operating with the example-lists for Lux-devices and UV-devices), is that dependent on the device sometimes you have to choose a different version of 'otherdevices' to get the desired element.
Because all devices look as if 'obeying the format'-rules, what could be reason for that?

Re: Readout Lightsensors in Lua

Posted: Thursday 26 November 2020 18:28
by waaren
Toulon7559 wrote: Thursday 26 November 2020 14:45 Lux-devices not only have a number in an element-field, but also a related text for the unit(see example below for a device-list):
The unit is not a part of the svalue. The svalue contains only a number for Lux type devices
Light has no dedicated, easy 'otherdevices' to extract the Lux-value
For Lux and a number of other device-types that have only 1 numeric value in svalue you can use otherdevices_utility[deviceName])

Or to make it easier; use dzVents and get the Lux without a need to know from which table this value comes.

Re: Readout Lightsensors in Lua

Posted: Friday 27 November 2020 16:30
by Toulon7559
waaren,

You are right that svalues is numbers only:
I confused from Domoticz the device-list with the svalue-list.

Taking into account your response, tried to correct my first message in this thread to reduce risk of confusion:
added some text { }

Any explanation possible for the second aspect?
[No clear coincidence visible related to load or to type of software:
All Raspberries have same Raspian_Buster,
3 Raspberries (for 'Production') have stable Domoticz, others have latest beta-Domoticz,
2 Raspberries (for 'Production') have many scripts to run (most lua, some python, some dzVents, few PHP), others not]