Page 1 of 1
goodnight script
Posted: Thursday 30 November 2017 22:40
by markjgabb
hi everyone
im after a way to concantenate a string for use in a goodnight script
currently i have a welcome home that welcomes people home by name when they arrive
Code: Select all
local delay = 30
local name = device.name
if (device.state == 'On') then
os.execute('(sleep '..delay..';tts welcome home "'..name..'" > /dev/null)&')
end
end
what im after now is a way to do a goodnight concant for saying goodnight by name for the group of people home
so if out of 4 person 2 and 3 are home it would say
goodnight 2 and 3
if 3 people were home it would say goodnight 2,3, and 4....
im sure this is possible using local settings but im just not sure how to get the concant to work the way i want it to...
also how to get it to only say it for devices that are turned on
Re: goodnight script
Posted: Thursday 30 November 2017 23:56
by pvm
You will have to check all 4 persons and concatenate these names to the string when they are in.
psuedo code:
string = "welcome home "
if person1 = in then string = string + name1
if person2 = in then string = string + name2
etc.
Re: goodnight script
Posted: Friday 01 December 2017 7:32
by BakSeeDaa
In case you'd like to develop that idea a bit further, below is an example code snippet. It can probably be improved a lot but it might give some ideas.
Code: Select all
-- Greetings to the inhabitants of the house
if device.name == 'SomeDevice' then -- This device triggers the greeting to be spoken
math.randomseed(os.time()) -- so that the results are always different
local function FYShuffle( tInput )
local tReturn = {}
for i = #tInput, 1, -1 do
local j = math.random(i)
tInput[i], tInput[j] = tInput[j], tInput[i]
table.insert(tReturn, tInput[i])
end
return tReturn
end
local t = os.date('*t')
local hour = tostring(t.hour)
local min = tostring(t.min)
local current_second = t.hour * 3600 + t.min * 60 -- number of sec since midnight
local morning = 0 * 3600 + 0 * 60 -- 00:00
local afternoon = 10 * 3600 + 0 * 60 -- 10:00
local evening = 18 * 3600 + 0 * 60 -- 18:00
local greeting = 'Good'
local timeOfDay = ''
if (current_second > morning) and (current_second < afternoon) then
timeOfDay = 'morning'
else
if (current_second > afternoon) and (current_second < evening) then
timeOfDay = 'day'
else
timeOfDay = 'evening'
end
end
greeting = greeting..' '..timeOfDay..' '
local greetings = {}
table.insert(greetings, greeting)
table.insert(greetings, 'Hello')
table.insert(greetings, 'Hi')
table.insert(greetings, 'What\'s up')
greetings = FYShuffle(greetings) -- shuffle the table and save it
greeting = greetings[3]..'... '
local peopleAtHome = {}
if (domoticz.devices('John @ Home').active) then table.insert(peopleAtHome, 'John') end
if (domoticz.devices('Charlie @ Home').active) then table.insert(peopleAtHome, 'Charlie') end
if (domoticz.devices('Anna @ Home').active) then table.insert(peopleAtHome, 'Anna') end
peopleAtHome = FYShuffle(peopleAtHome) -- shuffle the table and save it
for i,v in ipairs(peopleAtHome) do
greeting = greeting..(v)
if i < #peopleAtHome - 1 then
greeting = greeting..', '
elseif i == #peopleAtHome - 1 then
greeting = greeting..' and '
end
end
domoticz.helpers.speak(domoticz, greeting..'...')
end