[LUA] Sortir les poubelles

Vous avez créé un script LUA dont vous êtes fier, un .sh génial, un programme Python hors du commun, un Tuto, c'est ici que vous pouvez les partager.
judu
Messages : 24
Inscription : 11 févr. 2018, 20:34
Localisation : Yonne

Re: Sortir les poubelles

Message par judu »

Bonsoir,
sujet lu de A à Z mais toujours aucune notification, ni mail.
Quelqu'un pourrait il m'aider ?
Merci par avance pour vos réponses.
Keros
Messages : 6638
Inscription : 23 juil. 2019, 20:57

Re: Sortir les poubelles

Message par Keros »

Judu,

Le script est donner pour faire une notification par SMS avec lien donné en dessous du code : https://easydomoticz.com/une-plateforme ... omoticz-2/

Il y a un deuxième tuto, plus récent, ici : viewtopic.php?f=17&t=8167&hilit=notification+utilime

La ligne de la notification est :

Code : Tout sélectionner

commandArray[1]={['OpenURL']='http://192.168.22.70:41047/send.html?smsto=+33612345678&smsbody='..url_encode(msg)..'&smstype=sms'}
Tu peux la remplacer pour faire une autre notification directement dans le programme ou bien changer la valeur d'un switch et mettre une notification sur ce switch.
Comment bien utiliser le forum : Poser une question, Mettre un script, un fichier, une image ou des logs
Mes petits guides : Débuter en programmation, Le débogage, Le choix de matériel, Les sauvegardes
Ma présentation - Mes Tutos
Softdy
Messages : 6
Inscription : 24 févr. 2020, 12:21

Re: Sortir les poubelles

Message par Softdy »

vil1driver a écrit : 14 avr. 2016, 18:43 Salut,

juste un petit script pour m'avertir de sortir la poubelle et la bonne ;)
  • semaine impair = poubelle grise
  • semaine pair = poubelle jaune
j'utilise SmsGateway mais libre à vous d'utiliser le système de notification qui vous convient

Code : Tout sélectionner

--[[


name : script_time_poubelles.lua

ce script à pour but de déterminer si nous sommes en semaine pair ou impair
et fonction de cela, le jeudi en fin d'après midi,
de nous alerter par SMS de sortir la poubelle concernée.




--]]


-- Get day of a week at year beginning 
--(tm can be any date and will be forced to 1st of january same year)
-- return 1=mon 7=sun
function getYearBeginDayOfWeek(tm)
  yearBegin = os.time{year=os.date("*t",tm).year,month=1,day=1}
  yearBeginDayOfWeek = tonumber(os.date("%w",yearBegin))
  -- sunday correct from 0 -> 7
  if(yearBeginDayOfWeek == 0) then yearBeginDayOfWeek = 7 end
  return yearBeginDayOfWeek
end

-- tm: date (as retruned from os.time)
-- returns basic correction to be add for counting number of week
--  weekNum = math.floor((dayOfYear + returnedNumber) / 7) + 1 
-- (does not consider correctin at begin and end of year) 
function getDayAdd(tm)
  yearBeginDayOfWeek = getYearBeginDayOfWeek(tm)
  if(yearBeginDayOfWeek < 5 ) then
    -- first day is week 1
    dayAdd = (yearBeginDayOfWeek - 2)
  else 
    -- first day is week 52 or 53
    dayAdd = (yearBeginDayOfWeek - 9)
  end  
  return dayAdd
end
-- tm is date as returned from os.time()
-- return week number in year based on ISO8601 
-- (week with 1st thursday since Jan 1st (including) is considered as Week 1)
-- (if Jan 1st is Fri,Sat,Sun then it is part of week number from last year -> 52 or 53)
function getWeekNumberOfYear(tm)
  dayOfYear = os.date("%j",tm)
  dayAdd = getDayAdd(tm)
  dayOfYearCorrected = dayOfYear + dayAdd
  if(dayOfYearCorrected < 0) then
    -- week of last year - decide if 52 or 53
    lastYearBegin = os.time{year=os.date("*t",tm).year-1,month=1,day=1}
    lastYearEnd = os.time{year=os.date("*t",tm).year-1,month=12,day=31}
    dayAdd = getDayAdd(lastYearBegin)
    dayOfYear = dayOfYear + os.date("%j",lastYearEnd)
    dayOfYearCorrected = dayOfYear + dayAdd
  end  
  weekNum = math.floor((dayOfYearCorrected) / 7) + 1
  if( (dayOfYearCorrected > 0) and weekNum == 53) then
    -- check if it is not considered as part of week 1 of next year
    nextYearBegin = os.time{year=os.date("*t",tm).year+1,month=1,day=1}
    yearBeginDayOfWeek = getYearBeginDayOfWeek(nextYearBegin)
    if(yearBeginDayOfWeek < 5 ) then
      weekNum = 1
    end  
  end  
  return weekNum
end  

function url_encode(str)
  if (str) then
    str = string.gsub (str, "\n", "\r\n")
    str = string.gsub (str, "([^%w %-%_%.%~])",
        function (c) return string.format ("%%%02X", string.byte(c)) end)
    str = string.gsub (str, " ", "+")
  end
  return str	
end

----------------------------------------------------------------------


commandArray = {}



local time = string.sub(os.date("%X"), 1, 5)
local day = os.date("%A")

-- le jeudi soir à 18h30 et 20h30
if ( day == "Thursday" and (time == "18:30" or time == "20:30") ) then

	-- récupérer numéro de la semaine actuelle
	useDate = os.time()	-- os.time{year=2015,month=9,day=30} -- il est possible de préciser la date
	weekNum = getWeekNumberOfYear(useDate)

	-- semaine pair ou impair
	pair = weekNum%2 == 0

	--print(os.date("%A %d/%m/%Y",useDate)..": week number:"..tostring(weekNum))


	if pair then
		-- poubelle jaune
		msg = "n\'oublie pas de sortir la poubelle jaune"
	else
		-- poubelle grise
		msg = "n\'oublie pas de sortir la poubelle grise"
	end
	-- olivier
	commandArray[1]={['OpenURL']='http://192.168.22.70:41047/send.html?smsto=+33612345678&smsbody='..url_encode(msg)..'&smstype=sms'}
	-- delphine
	commandArray[2]={['OpenURL']='http://192.168.22.70:41047/send.html?smsto=+33687654321&smsbody='..url_encode(msg)..'&smstype=sms'}
	print(msg)
end



return commandArray 
http://easydomoticz.com/une-plateforme- ... omoticz-2/
Bonjour,

Je débute dans la programmation et je viens d'installer ce script.
Je reçois bien les notifications, mais que faut-il faire pour éviter les + entre les mots:

Voici comment je reçois le message:

n%27'oublie+pas+de+sortir+la+poubelle+grise

Autre chose, je ne reçois que les notifications par mail, mais pas sur Pushaver alors que j'ai rentré la commande suivante:

commandArray['SendNotification']='Poubelles#'..url_encode(msg)..'#0'

Y a t-il autre chose à ajouter?

Merci
denis_brasseur
Messages : 898
Inscription : 24 déc. 2018, 17:05
Localisation : (26)

Re: Sortir les poubelles

Message par denis_brasseur »

au choix

Code : Tout sélectionner

commandArray[#commandArray+1] = {['SendNotification'] = 'Poubelles#'..url_encode(msg)..'#0###pushover'}

Code : Tout sélectionner

commandArray['SendNotification']= 'Poubelles#'..url_encode(msg)..'#0###pushover'

Code : Tout sélectionner

commandArray[#commandArray+1] = {['SendNotification'] =  'Poubelles#'..url_encode(msg)}

Code : Tout sélectionner

commandArray['SendNotification']= 'Poubelles#'..url_encode(msg)
J'aime mieux commandArray[#commandArray+1] par habitude
Pi3 + DD PiDrive - RFXtrx433 - AEON Labs ZW090
Softdy
Messages : 6
Inscription : 24 févr. 2020, 12:21

Re: Sortir les poubelles

Message par Softdy »

Merci
Dernière modification par vil1driver le 22 avr. 2020, 22:16, modifié 1 fois.
Raison : Citation inutile - réponse directe
Répondre