Hi,
I'd like to loop my devices and collect the names of those that are active and concatenate them I to one string. Looping and getting names is working but I am having trouble to put them I to one string and print it to log.
I'd like to something like this:
d.devices().filter(Geräte).forEach(function(device)
if (device.state=='On') then
string==string .. device.name
end
end
d.log(string)
How can I achieve this?
Thx,
zavjah
Concatenate string through a loop [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Concatenate string through a loop
Try thiszavjah wrote: Thursday 12 September 2019 14:15 I'd like to loop my devices and collect the names of those that are active and concatenate them I to one string. Looping and getting names is working but I am having trouble to put them I to one string and print it to log.
How can I achieve this?
Code: Select all
return
{
on =
{
timer =
{
'every minute', -- causes the script to be called every minute
},
},
execute = function(dz)
local string = ''
local myList = {2381, 2382, 2383, "mySensor" } -- List of idx or "names" of your devices
dz.devices().filter(myList).forEach(function(dv)
dz.log("Found: " .. dv.name .. "; nValue=" .. dv.nValue .. "; sValue=" .. dv.sValue,dz.LOG_DEBUG)
if dv.state =='On' then
string = string .. '\n' .. dv.name .. ', '
end
end)
dz.log('All devices from table myList with state = "On" : ' .. string, dz.LOG_FORCE)
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
zavjah
- Posts: 36
- Joined: Tuesday 13 August 2019 10:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
Re: Concatenate string through a loop [Solved]
Hi waaren,
thanks here again, it work perfectly
Cheers,
zavjah
thanks here again, it work perfectly
Cheers,
zavjah
Who is online
Users browsing this forum: No registered users and 1 guest