I have 7 defined colors and with math.rand(1,7) for each lamp this should give diferent colors for every lamp (or sometimes the same bij change).
The outcome is that every time most of the lamps have the same color.
On sites about LUA I learned there is a math.randomseed(xxx) to prevent the same results.
With or without math.randomseed results in same colors.
I think calling math.rand in the same second is the reason for giving same numbers. For disco effect i need to do this in a second.

Is it posible to get real random numbers?
Code: Select all
local hueRoze=53201
local hueBlauw=46793
local hueRood=53201
local hueOranje=65451
local hueGeel=5159
local hueGroen=26035
local hueWit=41490
local hueWarmwit=8276
local kleur=1
math.randomseed(os.clock()*100000000000)
-- lamp 1
local deUrl='https://1.2.3.4/api/huekey/lights/18/state'
-- Kies een kleur
kleur=math.random(1, 7)
domoticz.log('Kleur = '..kleur)
if (kleur==1) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRoze }
end
if (kleur==2) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueBlauw }
end
if (kleur==3) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRood }
end
if (kleur==4) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueOranje }
end
if (kleur==5) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueGeel }
end
if (kleur==6) then
postD = { on = true, sat = 254 , bri = 254 , hue = huegroen }
end
if (kleur==7) then
postD = { on = true, sat = 78 , bri = 254 , hue = hueWit }
end
domoticz.openURL({
url = deUrl,
method = 'PUT',
postData = postD,
callback = 'return', -- see httpResponses above.
})
-- lamp 2
deUrl='https://12.3.4/api/huekey/lights/19/state'
-- Kies een kleur
kleur=math.random(1, 7)
domoticz.log('Kleur = '..kleur)
if (kleur==1) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRoze }
end
if (kleur==2) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueBlauw }
end
if (kleur==3) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRood }
end
if (kleur==4) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueOranje }
end
if (kleur==5) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueGeel }
end
if (kleur==6) then
postD = { on = true, sat = 254 , bri = 254 , hue = huegroen }
end
if (kleur==7) then
postD = { on = true, sat = 78 , bri = 254 , hue = hueWit }
end
domoticz.openURL({
url = deUrl,
method = 'PUT',
postData = postD,
callback = 'return', -- see httpResponses above.
})
-- lamp 3
deUrl='https://1.2.3.4/api/huekey/lights/20/state'
-- Kies een kleur
kleur=math.random(1, 7)
domoticz.log('Kleur = '..kleur)
if (kleur==1) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRoze }
end
if (kleur==2) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueBlauw }
end
if (kleur==3) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRood }
end
if (kleur==4) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueOranje }
end
if (kleur==5) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueGeel }
end
if (kleur==6) then
postD = { on = true, sat = 254 , bri = 254 , hue = huegroen }
end
if (kleur==7) then
postD = { on = true, sat = 78 , bri = 254 , hue = hueWit }
end
domoticz.openURL({
url = deUrl,
method = 'PUT',
postData = postD,
callback = 'return', -- see httpResponses above.
})
-- lamp 4
deUrl='https://1.2.3.4/api/huekey/lights/21/state'
-- Kies een kleur
kleur=math.random(1, 7)
domoticz.log('Kleur = '..kleur)
if (kleur==1) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRoze }
end
if (kleur==2) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueBlauw }
end
if (kleur==3) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRood }
end
if (kleur==4) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueOranje }
end
if (kleur==5) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueGeel }
end
if (kleur==6) then
postD = { on = true, sat = 254 , bri = 254 , hue = huegroen }
end
if (kleur==7) then
postD = { on = true, sat = 78 , bri = 254 , hue = hueWit }
end
domoticz.openURL({
url = deUrl,
method = 'PUT',
postData = postD,
callback = 'return', -- see httpResponses above.
})
-- lamp 5
deUrl='https://1.2.3.4/api/huekey/lights/23/state'
-- Kies een kleur
kleur=math.random(1, 7)
domoticz.log('Kleur = '..kleur)
if (kleur==1) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRoze }
end
if (kleur==2) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueBlauw }
end
if (kleur==3) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRood }
end
if (kleur==4) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueOranje }
end
if (kleur==5) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueGeel }
end
if (kleur==6) then
postD = { on = true, sat = 254 , bri = 254 , hue = huegroen }
end
if (kleur==7) then
postD = { on = true, sat = 78 , bri = 254 , hue = hueWit }
end
domoticz.openURL({
url = deUrl,
method = 'PUT',
postData = postD,
callback = 'return', -- see httpResponses above.
})
-- lamp 6
deUrl='https://1.2.3.4/api/huekey/lights/24/state'
-- Kies een kleur
kleur=math.random(1, 7)
domoticz.log('Kleur = '..kleur)
if (kleur==1) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRoze }
end
if (kleur==2) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueBlauw }
end
if (kleur==3) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueRood }
end
if (kleur==4) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueOranje }
end
if (kleur==5) then
postD = { on = true, sat = 254 , bri = 254 , hue = hueGeel }
end
if (kleur==6) then
postD = { on = true, sat = 254 , bri = 254 , hue = huegroen }
end
if (kleur==7) then
postD = { on = true, sat = 78 , bri = 254 , hue = hueWit }
end
domoticz.openURL({
url = deUrl,
method = 'PUT',
postData = postD,
callback = 'return', -- see httpResponses above.
})