goodnight script

Moderator: leecollings

Post Reply
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

goodnight script

Post 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
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
pvm
Posts: 550
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: 4.10538
Location: NL
Contact:

Re: goodnight script

Post 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.
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
BakSeeDaa
Posts: 485
Joined: Thursday 17 September 2015 10:13
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: goodnight script

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests